in a folder named: 'textures'
images removed..
save the code at the same location as you created the 'textures' folder..
Code: Select all
;Example: Simple static Geometry 2
;This example shows how to use CreateStaticGeometry()
;If you want to add a vast number of objects to your scene,
;which are always stationary.
;Once the Static Geometry has been build, it is no longer
;possible to move or rotate the Entities.
;This example requires PB 5.20
;By DK_PETER
InitEngine3D()
InitSprite()
InitKeyboard()
InitMouse()
UseJPEGImageDecoder()
UsePNGImageDecoder()
Add3DArchive("textures",#PB_3DArchive_FileSystem)
DeclareModule _3D_Geo
Structure Geo_Data
ID.i
Mesh.i
Tex.i
Mat.i
ent.i
EndStructure
Global CamSpeed = 10
Global MouseSpeed = 10
Global DefaultCam.i
Global Win.i, Light.i
Global earth.Geo_Data
Global Geo.Geo_Data
Global cl.Geo_Data
Global deadworld.Geo_Data
Declare SetupWinScreen(Width.i, Height.i, Title.s = "")
Declare MakeStaticGeo()
Declare MakeTestTerrain()
Declare CreateClouds()
Declare CreateDeadWorld()
Declare Do_Mouse()
Declare Do_Keyboard()
EndDeclareModule
Module _3D_Geo
Procedure SetupWinScreen(Width.i, Height.i, Title.s = "") ; Setup screen, Get Dimensions, and set a default camera
Win = OpenWindow(#PB_Any, 0, 0, Width, Height, Title, #PB_Window_SystemMenu )
OpenWindowedScreen(WindowID(Win), 0, 0, Width, Height, 0, 0, 0,#PB_Screen_SmartSynchronization)
;Create camera
DefaultCam = CreateCamera(#PB_Any,0,0,100,100)
MoveCamera(DefaultCam,2000,550,2000)
CameraLookAt(DefaultCam,1000,0,1000)
CameraProjectionMode(DefaultCam, #PB_Camera_Perspective)
;Setup light
light = CreateLight(#PB_Any ,RGB(210, 200, 200), 6000, 2200, 2000,#PB_Light_Directional)
SetLightColor(light, #PB_Light_SpecularColor, RGB(220, 200, 200))
AmbientColor(RGB(250, 250, 250))
EndProcedure
Procedure MakeTestTerrain()
earth\Mesh = CreatePlane(#PB_Any,22000,22000,1,1,1,1)
earth\Tex = CreateTexture(#PB_Any,512,512)
StartDrawing(TextureOutput(earth\Tex))
Box(0,0,512,512,$444444)
For y = 0 To 512 Step 16
For x = 0 To 512 Step 16
LineXY(0,y,512,y,$999999)
LineXY(x,0,x,512,$999999)
Next x
Next y
StopDrawing()
earth\Mat = CreateMaterial(#PB_Any,TextureID(earth\Tex))
ScrollMaterial(earth\Mat,0,0.004,#PB_Material_Animated)
earth\ID = CreateEntity(#PB_Any,MeshID(earth\Mesh),MaterialID(earth\Mat))
MoveEntity(earth\ID,11000,0,11000,#PB_Absolute)
EndProcedure
Procedure MakeStaticGeo() ; Static geometry can't be moved or rotated when created.
;Let's create a large city
geo\Mesh = CreateCube(#PB_Any, 50)
geo\Tex = CreateTexture(#PB_Any, 512, 512)
StartDrawing(TextureOutput(geo\Tex))
Box(0, 0, 512, 512, $868988)
Box(0, 0, 512, 60 , $5E5F60)
For y = 64 To 512 Step 32
For x = 0 To 512 Step 32
Box(x,y,16,15,$E1BF3F)
Next x
Next y
StopDrawing()
geo\Mat = CreateMaterial(#PB_Any, TextureID(geo\Tex))
geo\ent = CreateEntity(#PB_Any, MeshID(geo\Mesh), MaterialID(geo\Mat))
;Create static geometry city...
geo\ID = CreateStaticGeometry(#PB_Any,20100,20100,20100,#True)
For z = 0 To 20000 Step 200
For x = 0 To 20000 Step 200
newsizey = Random(10,1)
entnewval = newsizey * 25
AddStaticGeometryEntity(geo\ID, EntityID(geo\ent), x, entnewval, z, 1, newsizey, 1)
Next x
Next z
BuildStaticGeometry(geo\ID)
EndProcedure
Procedure CreateClouds()
cl\mesh = CreatePlane(#PB_Any,2000, 2000, 10, 10, 2, 2)
cl\tex = LoadTexture(#PB_Any, "clouds.jpg")
cl\mat = CreateMaterial(#PB_Any, TextureID(cl\tex))
AddMaterialLayer(cl\Mat, TextureID(cl\tex), #PB_Material_Add)
MaterialBlendingMode(cl\mat,#PB_Material_Color)
RotateMaterial(cl\mat, 0.001, #PB_Material_Animated|#PB_Material_Fixed)
RotateMaterial(cl\mat, 0.004, #PB_Material_Animated|#PB_Material_Fixed,1)
SetMeshMaterial(cl\mesh, MaterialID(cl\mat))
cl\Ent = CreateEntity(#PB_Any, MeshID(cl\mesh), MaterialID(cl\mat))
MoveEntity(cl\Ent, 0, 5000, 2000)
;RotateEntity(cl\Ent,0, 0, 0) ;Clouds facing upwards
RotateEntity(cl\Ent,0,0,180) ;Clouds facing downwards
ScaleEntity(cl\Ent,100,100,100)
EndProcedure
Procedure CreateDeadWorld()
deadworld\Mesh = CreateSphere(#PB_Any, 200,40,40)
deadworld\Tex = LoadTexture(#PB_Any,"deadworld.png")
deadworld\Mat = CreateMaterial(#PB_Any, TextureID(deadworld\Tex))
deadworld\ent = CreateEntity(#PB_Any,MeshID(deadworld\Mesh), MaterialID(deadworld\Mat))
MoveEntity(deadworld\ent, 6000,5000,6000)
EndProcedure
Procedure Do_Mouse()
ExamineMouse()
MouseX = -MouseDeltaX() * MouseSpeed * 0.01
MouseY = -MouseDeltaY() * MouseSpeed * 0.01
RotateCamera(DefaultCam, MouseY, MouseX, 0, #PB_Relative)
EndProcedure
Procedure Do_Keyboard()
ExamineKeyboard()
If KeyboardPushed(#PB_Key_A)
KeyX = 0 - CamSpeed
EndIf
If KeyboardPushed(#PB_Key_D)
KeyX = CamSpeed
EndIf
If KeyboardPushed(#PB_Key_W)
KeyY = 0 - CamSpeed
EndIf
If KeyboardPushed(#PB_Key_S)
KeyY = CamSpeed
EndIf
MoveCamera(DefaultCam, KeyX, 0, KeyY)
If Not KeyboardReleased(#PB_Key_Escape)
KeyX = 0: KeyY = 0
EndIf
EndProcedure
EndModule
_3D_Geo::SetupWinScreen(1024,768)
_3D_Geo::MakeTestTerrain()
_3D_Geo::MakeStaticGeo()
_3D_Geo::CreateClouds()
_3D_Geo::CreateDeadWorld()
Repeat
ev = WindowEvent()
RotateEntity(_3D_Geo::deadworld\ent,0.1,0,0,#PB_Relative)
elaps = RenderWorld()
_3D_Geo::Do_Mouse()
_3D_Geo::Do_Keyboard()
FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape)
Peter
