what is the shortest amount of lines to create a terrain
only 5 lines, all the other code is an accessories such as the materials, the camera is essential it is your eyes exactly watching the virtual world
here is the shortest demo, it adapted from terrain.pb from the purebasic 3D example, i have removed many lines, also removing the screenRequester , i have added a very big Sphere in the terrain center. and the camera ie our eyes is looking to it
i have also removed the ability to compile with opengl context to reduce the code size
Code: Select all
; adapted from terrain.pb from 3D examples
#CameraSpeed = 10
Define.f KeyX, KeyY, MouseX, MouseY
If InitEngine3D()
InitSprite()
InitKeyboard()
InitMouse()
OpenWindow(0, 0, 0, 1000, 600, "terrain", #PB_Window_ScreenCentered | #PB_Window_SystemMenu)
OpenWindowedScreen(WindowID(0), 0, 0, 800, 600, 0, 0, 0)
Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/Textures/", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/Textures/nvidia", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/Packs/desert.zip", #PB_3DArchive_Zip)
;- Light
;
light = CreateLight(#PB_Any ,RGB(190, 190, 190), 4000, 1200, 1000,#PB_Light_Directional)
SetLightColor(light, #PB_Light_SpecularColor, RGB(255*0.4, 255*0.4,255*0.4))
LightDirection(light ,0.55, -0.3, -0.75)
AmbientColor(RGB(255*0.2, 255*0.2,255*0.2))
;- Camera
;
CreateCamera(0, 0, 0, 100, 100)
;MoveCamera(0, 800, 400, 80, #PB_Absolute)
MoveCamera(0, 896, 502, 5500, #PB_Absolute)
CameraBackColor(0, RGB(5, 5, 10))
;CameraRenderMode(0, #PB_Camera_Wireframe)
;- Terrain definition
SetupTerrains(LightID(Light), 3000, #PB_Terrain_NormalMapping)
; initialize terrain
CreateTerrain(0, 513, 12000, 600, 1, "TerrainGroup", "dat")
; set all texture will be use when terrrain will be constructed
AddTerrainTexture(0, 0, 100, "dirt_grayrocky_diffusespecular.jpg", "dirt_grayrocky_normalheight.jpg")
; Build terrains
DefineTerrainTile(0, 0, 0, "terrain513.png", 0, 0)
BuildTerrain(0)
; SkyBox
;
SkyBox("desert07.jpg")
CreateMaterial(6, LoadTexture(1, "ValetCoeur.jpg"))
MaterialCullingMode(6, #PB_Material_NoCulling )
sphere = CreateSphere(#PB_Any, 1000)
sphere = CreateEntity(#PB_Any, MeshID(sphere), MaterialID(6), 0, 400,0 )
Repeat
Repeat
Event = WindowEvent()
If Event = #PB_Event_CloseWindow ; If the user has pressed on the close button
Quit = 1
EndIf
Until Event = 0
If ExamineKeyboard()
If KeyboardPushed(#PB_Key_Left)
KeyX = -#CameraSpeed
ElseIf KeyboardPushed(#PB_Key_Right)
KeyX = #CameraSpeed
Else
KeyX = 0
EndIf
If KeyboardPushed(#PB_Key_Up)
KeyY = -#CameraSpeed
ElseIf KeyboardPushed(#PB_Key_Down)
KeyY = #CameraSpeed
Else
KeyY = 0
EndIf
If KeyboardReleased(#PB_Key_A)
; to deremine the current coordinates of the camera
Debug CameraX(0)
Debug CameraY(0)
Debug CameraZ(0)
EndIf
EndIf
If ExamineMouse()
MouseX = -MouseDeltaX() * #CameraSpeed * 0.05
MouseY = -MouseDeltaY() * #CameraSpeed * 0.05
EndIf
MoveCamera(0, CameraX(0), TerrainHeight(0, CameraX(0), CameraZ(0)) + 60, CameraZ(0), #PB_Absolute)
MoveCamera (0, KeyX, 0, KeyY)
RotateCamera(0, MouseY, MouseX, 0, #PB_Relative)
RenderWorld()
FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1
End
EndIf
Edit: notes:
1- change number 60 in line 101 to 400 and the camera appears as if it is riding a tall Giraffe
2- remove line 101 and the camera will not be restricted to the terrain surface and we can move anywhere, this useful to go high and see the terrain from high altitude
3- DefineTerrainTile(0, tx, ty, "terrain513.png", ty % 2, tx % 2)
the "terrain513.png" is the HeightMap, position the mouse on the function DefineTerrainTile and press F1 to get all the help and info about it
4- number 600 in line 38 is the scale , make it more and we will get more bumpy terrain
6- use another HeightMap such as "Lensflare5.jpg" but change the scale from 600 to 2000 and we will get a volcano
7- you may need to change #CameraSpeed = 10 to more values to speed the camera movement