ModifyTerrain.htm 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <html>
  2. <head>
  3. <title>Blitz3D Docs</title>
  4. <link rel=stylesheet href=../css/commands.css type=text/css>
  5. </head>
  6. <body>
  7. <h1>ModifyTerrain terrain,grid_x,grid_z,height#[,realtime]</h1>
  8. <h1>Parameters</h1>
  9. <table>
  10. <tr>
  11. <td>
  12. terrain - terrain handle <br />
  13. grid_x - grid x coordinate of terrain <br />
  14. grid_y - grid y coordinate of terrain <br />
  15. height# - height of point on terrain. Should be in the range 0-1. <br />
  16. realtime (optional) - True to modify terrain immediately. False to modify terrain when RenderWorld in next called. Defaults to False.
  17. </td>
  18. </tr>
  19. </table>
  20. <h1>Description</h1>
  21. <table>
  22. <tr>
  23. <td>
  24. Sets the height of a point on a terrain.
  25. </td>
  26. </tr>
  27. </table>
  28. <h1><a href=../3d_examples/ModifyTerrain.bb>Example</a></h1>
  29. <table>
  30. <tr>
  31. <td>
  32. ; ModifyTerrain Example <br />
  33. ; --------------------- <br />
  34. <br />
  35. Graphics3D 640,480 <br />
  36. SetBuffer BackBuffer() <br />
  37. <br />
  38. terra_size=32 ; initial size of terrain, and no. of grids segments, along each side <br />
  39. x_scale=10 ; x scale of terrain <br />
  40. y_scale=50 ; y scale of terrain <br />
  41. z_scale=10 ; z scale of terrain <br />
  42. marker_x=terra_size/2 ; initial x position of marker <br />
  43. marker_z=terra_size/2 ; initial z position of marker <br />
  44. <br />
  45. camera=CreateCamera() <br />
  46. PositionEntity camera,(terra_size*x_scale)/2,50,0 ; position wherever; just try and get good view of terrain! <br />
  47. RotateEntity camera,30,0,0 ; again, try and get good view of terrain <br />
  48. <br />
  49. light=CreateLight() <br />
  50. RotateEntity light,90,0,0 <br />
  51. <br />
  52. ; Create terrain <br />
  53. terra=CreateTerrain(terra_size) <br />
  54. ScaleEntity terra,x_scale,y_scale,z_scale <br />
  55. <br />
  56. ; Texture terrain <br />
  57. grass_tex=LoadTexture("media/mossyground.bmp") <br />
  58. EntityTexture terra,grass_tex <br />
  59. <br />
  60. ; Create marker <br />
  61. marker=CreateSphere() <br />
  62. ScaleEntity marker,1,1,1 <br />
  63. EntityColor marker,255,0,0 <br />
  64. <br />
  65. While Not KeyDown(1) <br />
  66. <br />
  67. ; Change marker position values depending on cursor key pressed <br />
  68. If KeyHit(205)=True Then marker_x=marker_x+1 <br />
  69. If KeyHit(203)=True Then marker_x=marker_x-1 <br />
  70. If KeyHit(208)=True Then marker_z=marker_z-1 <br />
  71. If KeyHit(200)=True Then marker_z=marker_z+1 <br />
  72. <br />
  73. ; Get terrain height at marker position <br />
  74. marker_y#=TerrainHeight(terra,marker_x,marker_z) <br />
  75. <br />
  76. ; If A pressed then increase marker_y value and modify terrain <br />
  77. If KeyDown(30)=True <br />
  78. If marker_y#<1 Then marker_y#=marker_y#+0.005 <br />
  79. ModifyTerrain terra,marker_x,marker_z,marker_y# <br />
  80. EndIf <br />
  81. <br />
  82. ; If Z pressed then decrease marker_y value and modify terrain <br />
  83. If KeyDown(44)=True <br />
  84. If marker_y#>0 Then marker_y#=marker_y#-0.005 <br />
  85. ModifyTerrain terra,marker_x,marker_z,marker_y# <br />
  86. EndIf <br />
  87. <br />
  88. ; Position marker, taking into account x, y and z scales of terrain <br />
  89. PositionEntity marker,marker_x*x_scale,marker_y#*y_scale,marker_z*z_scale <br />
  90. <br />
  91. RenderWorld <br />
  92. <br />
  93. Text 0,0,"Use cursor keys to move marker over the terrain" <br />
  94. Text 0,20,"Press A or Z to alter height of terrain at marker's position" <br />
  95. Text 0,40,"Terrain Height: "+marker_y# <br />
  96. <br />
  97. Flip <br />
  98. <br />
  99. Wend <br />
  100. <br />
  101. End
  102. </td>
  103. </tr>
  104. </table>
  105. <br>
  106. <a target=_top href=../index.htm>Index</a><br>
  107. <br>
  108. Click <a href=http://www.blitzbasic.co.nz/b3ddocs/command.php?name=ModifyTerrain&ref=comments target=_blank>here</a> to view the latest version of this page online</body>
  109. </html>