dxLoadTerrain%(file$,parent%)

Parameters

file$ - filename of image file to be used as height map
parent (optional) - parent entity of terrain

Description

Loads a terrain from an image file and returns the terrain's handle.

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.

Tips on generating nice terrain:

* Smooth or blur the height map
* Reduce the y scale of the terrain
* Increase the x/z scale of the terrain
* Reduce the camera range

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.

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.

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.

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.

See also: dxCreateTerrain.

Example

dxLoadTerrain Example
-------------------

dxGraphics3D 640,480
dxSetBuffer dxBackBuffer()

camera=dxCreateCamera()
dxPositionEntity camera,1,1,1

light=dxCreateLight()
dxRotateEntity light,90,0,0

; Load terrain
terrain=dxLoadTerrain( "media/height_map.bmp" )

; Set terrain detail, enable vertex morphing
TerrainDetail terrain,4000,True

; Scale terrain
dxScaleEntity terrain,1,50,1

; Texture terrain
grass_tex=dxLoadTexture( "media/mossyground.bmp" )
dxEntityTexture terrain,grass_tex,0,1

While Not dxKeyDown( 1 )

If dxKeyDown( 205 )=True Then dxTurnEntity camera,0,-1,0
If dxKeyDown( 203 )=True Then dxTurnEntity camera,0,1,0
If dxKeyDown( 208 )=True Then dxMoveEntity camera,0,0,-0.1
If dxKeyDown( 200 )=True Then dxMoveEntity camera,0,0,0.1

x#=dxEntityX(camera)
y#=dxEntityY(camera)
z#=dxEntityZ(camera)

terra_y#=TerrainY(terrain,x#,y#,z#)+5

dxPositionEntity camera,x#,terra_y#,z#

dxRenderWorld

dxText 0,0,"Use cursor keys to move about the terrain"

dxFlip

Wend

End

Index