TerrainHeight.bb 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. ; TerrainHeight Example
  2. ; ---------------------
  3. Graphics3D 640,480
  4. SetBuffer BackBuffer()
  5. terra_size=32 ; initial size of terrain, and no. of grids segments, along each side
  6. x_scale=10 ; x scale of terrain
  7. y_scale=50 ; y scale of terrain
  8. z_scale=10 ; z scale of terrain
  9. marker_x=terra_size/2 ; initial x position of marker
  10. marker_z=terra_size/2 ; initial z position of marker
  11. camera=CreateCamera()
  12. PositionEntity camera,(terra_size*x_scale)/2,50,0 ; position wherever; just try and get good view of terrain!
  13. RotateEntity camera,30,0,0 ; again, try and get good view of terrain
  14. light=CreateLight()
  15. RotateEntity light,90,0,0
  16. ; Create terrain
  17. terra=CreateTerrain(terra_size)
  18. ScaleEntity terra,x_scale,y_scale,z_scale
  19. ; Texture terrain
  20. grass_tex=LoadTexture("media/mossyground.bmp")
  21. EntityTexture terra,grass_tex
  22. ; Create marker
  23. marker=CreateSphere()
  24. ScaleEntity marker,1,1,1
  25. EntityColor marker,255,0,0
  26. While Not KeyDown(1)
  27. ; Change marker position values depending on cursor key pressed
  28. If KeyHit(205)=True Then marker_x=marker_x+1
  29. If KeyHit(203)=True Then marker_x=marker_x-1
  30. If KeyHit(208)=True Then marker_z=marker_z-1
  31. If KeyHit(200)=True Then marker_z=marker_z+1
  32. ; Get terrain height at marker position
  33. marker_y#=TerrainHeight(terra,marker_x,marker_z)
  34. ; If A pressed then increase marker_y value and modify terrain
  35. If KeyDown(30)=True
  36. If marker_y#<1 Then marker_y#=marker_y#+0.005
  37. ModifyTerrain terra,marker_x,marker_z,marker_y#
  38. EndIf
  39. ; If Z pressed then decrease marker_y value and modify terrain
  40. If KeyDown(44)=True
  41. If marker_y#>0 Then marker_y#=marker_y#-0.005
  42. ModifyTerrain terra,marker_x,marker_z,marker_y#
  43. EndIf
  44. ; Position marker, taking into account x, y and z scales of terrain
  45. PositionEntity marker,marker_x*x_scale,marker_y#*y_scale,marker_z*z_scale
  46. RenderWorld
  47. Text 0,0,"Use cursor keys to move marker over the terrain"
  48. Text 0,20,"Press A or Z to alter height of terrain at marker's position"
  49. Text 0,40,"Terrain Height: "+marker_y#
  50. Flip
  51. Wend
  52. End