LoadTerrain.htm 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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>LoadTerrain ( file$[,parent] )</h1>
  8. <h1>Parameters</h1>
  9. <table>
  10. <tr>
  11. <td>
  12. file$ - filename of image file to be used as height map <br />
  13. parent (optional) - parent entity of terrain
  14. </td>
  15. </tr>
  16. </table>
  17. <h1>Description</h1>
  18. <table>
  19. <tr>
  20. <td>
  21. Loads a terrain from an image file and returns the terrain's handle. <br />
  22. <br />
  23. The image's red channel is used to determine heights. Terrain is initially the same width and depth as the image, and 1 unit high. <br />
  24. <br />
  25. Tips on generating nice terrain: <br />
  26. <br />
  27. * Smooth or blur the height map <br />
  28. * Reduce the y scale of the terrain <br />
  29. * Increase the x/z scale of the terrain <br />
  30. * Reduce the camera range <br />
  31. <br />
  32. When texturing an entity, a texture with a scale of 1,1,1 (default) will be the same size as one of the terrain's grid squares. A texture that is scaled to the same size as the size of the bitmap used to load it or the no. of grid square used to create it, will be the same size as the terrain. <br />
  33. <br />
  34. The optional parent parameter allows you to specify a parent entity for the terrain so that when the parent is moved the child terrain will move with it. However, this relationship is one way; applying movement commands to the child will not affect the parent. <br />
  35. <br />
  36. Specifying a parent entity will still result in the terrain being created at position 0,0,0 rather than at the parent entity's position. <br />
  37. <br />
  38. A heightmaps dimensions (width and height) must be the same and must be a power of 2, e.g. 32, 64, 128, 256, 512, 1024. <br />
  39. <br />
  40. See also: CreateTerrain.
  41. </td>
  42. </tr>
  43. </table>
  44. <h1><a href=../3d_examples/LoadTerrain.bb>Example</a></h1>
  45. <table>
  46. <tr>
  47. <td>
  48. LoadTerrain Example <br />
  49. ------------------- <br />
  50. <br />
  51. Graphics3D 640,480 <br />
  52. SetBuffer BackBuffer() <br />
  53. <br />
  54. camera=CreateCamera() <br />
  55. PositionEntity camera,1,1,1 <br />
  56. <br />
  57. light=CreateLight() <br />
  58. RotateEntity light,90,0,0 <br />
  59. <br />
  60. ; Load terrain <br />
  61. terrain=LoadTerrain( "media/height_map.bmp" ) <br />
  62. <br />
  63. ; Set terrain detail, enable vertex morphing <br />
  64. TerrainDetail terrain,4000,True <br />
  65. <br />
  66. ; Scale terrain <br />
  67. ScaleEntity terrain,1,50,1 <br />
  68. <br />
  69. ; Texture terrain <br />
  70. grass_tex=LoadTexture( "media/mossyground.bmp" ) <br />
  71. EntityTexture terrain,grass_tex,0,1 <br />
  72. <br />
  73. While Not KeyDown( 1 ) <br />
  74. <br />
  75. If KeyDown( 205 )=True Then TurnEntity camera,0,-1,0 <br />
  76. If KeyDown( 203 )=True Then TurnEntity camera,0,1,0 <br />
  77. If KeyDown( 208 )=True Then MoveEntity camera,0,0,-0.1 <br />
  78. If KeyDown( 200 )=True Then MoveEntity camera,0,0,0.1 <br />
  79. <br />
  80. x#=EntityX(camera) <br />
  81. y#=EntityY(camera) <br />
  82. z#=EntityZ(camera) <br />
  83. <br />
  84. terra_y#=TerrainY(terrain,x#,y#,z#)+5 <br />
  85. <br />
  86. PositionEntity camera,x#,terra_y#,z# <br />
  87. <br />
  88. RenderWorld <br />
  89. <br />
  90. Text 0,0,"Use cursor keys to move about the terrain" <br />
  91. <br />
  92. Flip <br />
  93. <br />
  94. Wend <br />
  95. <br />
  96. End
  97. </td>
  98. </tr>
  99. </table>
  100. <br>
  101. <a target=_top href=../index.htm>Index</a><br>
  102. <br>
  103. Click <a href=http://www.blitzbasic.co.nz/b3ddocs/command.php?name=LoadTerrain&ref=comments target=_blank>here</a> to view the latest version of this page online</body>
  104. </html>