createTerrain()
Purpose
Create a 3D terrain
Description
Create a 3D terrain by setting the height and colour of points on a grid
Syntax
handle = createTerrain( gridsize, filter )
Arguments
handle identifer of the created terrain
gridsize size of the grid (length of one side)
filter Smoothing filter (0 = no filter)
Example
gsize = 64
landscape = createTerrain( gsize, 1 )
height = 0
colour = white
for x = 0 to gsize loop
for y = 0 to gsize loop
d = distance ( { x, y }, { gsize / 2, gsize / 2 } )
if d > 24 then // sea level
height = 0
colour = blue
else
if d > 18 then // beach
height = 1
colour = yellow
else // hills
height = rnd( 2 ) + 1
colour = green
endIf
endIf
setTerrainPoint( landscape, x, y, height, colour )
repeat
repeat
setCamera( { gsize / 2, 50, gsize / 2 }, { gsize / 2, 0, gsize / 2 - 1 } )
setAmbientLight( { 0.5, 0.5, 0.5 } )
island = placeObject( landscape, { gsize / 2, 0, gsize / 2 }, { 1, 1, 1 } )
loop
c = controls( 0 ) // rotate using joysticks
rotateObject( island, { 1, 0, 0 }, c.ly )
rotateObject( island, { 0, 0, 1 }, c.lx )
rotateObject( island, { 0, 1, 0 }, c.rx )
drawobjects()
update()
repeat
Associated Commands