TerrainShading.bb 1.5 KB

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