TerrainDetail.bb 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. ; TerrainDetail Example
  2. ; ---------------------
  3. Graphics3D 640,480
  4. SetBuffer BackBuffer()
  5. camera=CreateCamera()
  6. PositionEntity camera,1,1,1
  7. light=CreateLight()
  8. RotateEntity light,90,0,0
  9. ; Load terrain
  10. terrain=LoadTerrain( "media/height_map.bmp" )
  11. ; Scale terrain
  12. ScaleEntity terrain,1,50,1
  13. ; Texture terrain
  14. grass_tex=LoadTexture( "media/mossyground.bmp" )
  15. EntityTexture terrain,grass_tex,0,1
  16. ; Set terrain detail value
  17. terra_detail=4000
  18. ; Set vertex morph value
  19. vertex_morph=True
  20. While Not KeyDown( 1 )
  21. ; Change terrain detail value depending on key pressed
  22. If KeyDown(26) Then terra_detail=terra_detail-10
  23. If KeyDown(27) Then terra_detail=terra_detail+10
  24. ; Toggle vertex morphing on/off when spacebar is pressed
  25. If KeyHit(57)=True Then vertex_morph=1-vertex_morph
  26. ; Set terrain detail, vertex morphing
  27. TerrainDetail terrain,terra_detail,vertex_morph
  28. If KeyDown( 203 )=True Then x#=x#-0.1
  29. If KeyDown( 205 )=True Then x#=x#+0.1
  30. If KeyDown( 208 )=True Then y#=y#-0.1
  31. If KeyDown( 200 )=True Then y#=y#+0.1
  32. If KeyDown( 44 )=True Then z#=z#-0.1
  33. If KeyDown( 30 )=True Then z#=z#+0.1
  34. If KeyDown( 205 )=True Then TurnEntity camera,0,-1,0
  35. If KeyDown( 203 )=True Then TurnEntity camera,0,1,0
  36. If KeyDown( 208 )=True Then MoveEntity camera,0,0,-0.1
  37. If KeyDown( 200 )=True Then MoveEntity camera,0,0,0.1
  38. x#=EntityX(camera)
  39. y#=EntityY(camera)
  40. z#=EntityZ(camera)
  41. terra_y#=TerrainY(terrain,x#,y#,z#)+5
  42. PositionEntity camera,x#,terra_y#,z#
  43. RenderWorld
  44. Text 0,0,"Use cursor keys to move about the terrain"
  45. Text 0,20,"Use [ and ] keys to change terrain detail level"
  46. Text 0,40,"Press spacebar to enable/disable vertex morphing"
  47. Text 0,60,"Terrain Detail: "+terra_detail
  48. If vertex_morph=True Then Text 0,80,"Vertex Morphing: True" Else Text 0,80,"Vertex Morphing: False"
  49. Flip
  50. Wend
  51. End