; ModifyTerrain Example ; --------------------- Graphics3D 640,480,0,2 SetBuffer BackBuffer() ; Terrain layout: 32 grid squares, scaled to 10 units per square terra_size=32 x_scale=10 y_scale=50 z_scale=10 ; Overlook the terrain from a fixed camera camera=CreateCamera() PositionEntity camera,(terra_size*x_scale)/2,120,-60 RotateEntity camera,35,0,0 light=CreateLight() RotateEntity light,45,45,0 ; Create a flat terrain to sculpt terrain=CreateTerrain(terra_size) ScaleEntity terrain,x_scale,y_scale,z_scale ; Texture the terrain grass_tex=LoadTexture("media/MossyGround.BMP") EntityTexture terrain,grass_tex ; A red marker showing which grid point we will sculpt marker=CreateSphere(8) EntityColor marker,255,60,60 EntityFX marker,1 marker_x=terra_size/2 marker_z=terra_size/2 While Not KeyDown(1) ; Cursor keys step the marker across the terrain grid If KeyHit(205) And marker_x0 Then marker_x=marker_x-1 If KeyHit(200) And marker_z0 Then marker_z=marker_z-1 ; Read the current height (0 to 1) at the marker's grid point height#=TerrainHeight(terrain,marker_x,marker_z) ; Hold Space to raise the ground, Z to lower it. ; ModifyTerrain sets the height of one grid point. If KeyDown(57) And height<1 height=height+0.005 ModifyTerrain terrain,marker_x,marker_z,height EndIf If KeyDown(44) And height>0 height=height-0.005 ModifyTerrain terrain,marker_x,marker_z,height EndIf ; Sit the marker on the sculpted ground PositionEntity marker,marker_x*x_scale,height*y_scale+2,marker_z*z_scale RenderWorld Text 0,0,"Cursor keys: move marker Hold Space: raise Hold Z: lower Esc: exit" Text 0,20,"ModifyTerrain terrain,"+marker_x+","+marker_z+","+height Flip Wend End