You guys know the example that comes with advanced terrain?
This code uses the stuff from that, so save it in the same dir as 'Example1' before loading it again. Shows a simple little foliage optimising system, worth checking out.
` Advanced Terrain System - Example 1e - Foliage optimisation system added by Van-B
` sky textures from - SkyMatter
` heightmap created by - David Smith ( [email protected] )
` terrain base texture - generated from Advanced Terrain System Plus
` demo by - TGC
` set up display and camera
sync on
backdrop on
autocam off
set camera range 0.5, 30000
global grasscount=2000
global grassobj
dim grass_x#(grasscount)
dim grass_y#(grasscount)
dim grass_z#(grasscount)
dim grass_a#(grasscount)
dim grass_index(16,16)
dim grass_len(16,16)
dim grass_vis(500000)
` movement
g_fSpeed# = 0.05
g_fTurn# = 0.3
` set the directory to media
set dir "media"
` load base and detail texture
load image "texture2.bmp", 1
load image "detail.tga", 2
make object terrain 1 ` create the terrain object
set terrain heightmap 1, "map.bmp" ` set the heightmap
set terrain scale 1, 3, 0.6, 3 ` set the scale
set terrain split 1, 16 ` split value by 16 * 16
set terrain tiling 1, 4 ` detail map tiling
set terrain light 1, 1, -1.0, 0, 1, 1, 0.78, 0.7 ` light - xdir, ydir, zdir, red, green, blue, intensity
set terrain texture 1, 1, 2 ` base and detail texture
build terrain 1 ` finally build the terrain
` load our skybox
load object "skybox2.x", 200
set object light 200, 0
set object texture 200, 3, 1
position object 200, 1000, 2000, 4000
scale object 200, 30000, 30000, 30000
`---- Water :)
make object plain 300,10000,10000
color object 300,rgb(32,64,128)
`----
`set reflection shading on 300
position object 300,0,10,0
rotate object 300,270,0,0
` reset the directory
set dir ".."
` position the camera
position camera 385,23,100
for n=0 to grasscount
gy#=0
while gy#<11
gx#=rnd(256*300)/100.0
gz#=rnd(256*300)/100.0
gy#=get terrain ground height( 1,gx#,gz#)
endwhile
grass_x#(n)=gx#
grass_y#(n)=gy#
grass_z#(n)=gz#
grass_a#(n)=rnd(360)
next n
index=0
tlen=0
for zz=0 to 15
for xx=0 to 15
grass_index(xx,zz)=index
xa#=xx*48.0
za#=zz*48.0
xb#=xa#+48.0
zb#=za#+48.0
dec xa#,128.0
dec za#,128.0
inc xb#,128.0
inc zb#,128.0
glen=0
for n=0 to grasscount
if grass_x#(n)>=xa# and grass_x#(n)<=xb#
if grass_z#(n)>=za# and grass_z#(n)<=zb#
grass_vis(index)=n
inc index,1
inc glen,1
endif
endif
next n
if tlen<glen then tlen=glen
grass_len(xx,zz)=glen-1
text xx*.0,zz*5.0,"." : sync
next xx
next zz
grassobj=tlen-1
for n=0 to grassobj
make object plain n+2000,10,10
next n
` main program loop
do
` handle user input and show some stats
gosub userInput
gosub grass
gosub information
` get the height of the terrain at the current camera position
a# = get terrain ground height( 1, camera position x( ), camera position z( ) )
` now position the camera slightly above the terrain
position camera camera position x( ), a# + 3, camera position z()
` let the terrain handle some internal work
update terrain
` final screen update
sync
loop
userInput:
` simple mouse and keyboard movement
` move around with arrow keys
control camera using arrowkeys 0, g_fSpeed#, g_fTurn#
` store old camera angle
OldCamAngleY# = CameraAngleY#
OldCamAngleX# = CameraAngleX#
` store new camera angle
CameraAngleY# = wrapvalue ( CameraAngleY# + mousemovex ( ) * 0.4 )
CameraAngleX# = wrapvalue ( CameraAngleX# + mousemovey ( ) * 0.4 )
` rotate camera
yrotate camera curveangle ( CameraAngleY#, OldCamAngleY#, 24 )
xrotate camera curveangle ( CameraAngleX#, OldCamAngleX#, 24 )
` speed up movement
if inkey$ ( ) = "+"
if g_fSpeed# < 1000
g_fSpeed# = g_fSpeed# + 0.01
endif
endif
` slow down movement
if inkey$ ( ) = "-"
if g_fSpeed# > 0.002
g_fSpeed# = g_fSpeed# - 0.001
endif
endif
return
`-----
grass:
`Check the grass index and vis array and position grass where needed
ocx=cx
ocz=cz
cx=camera position x()/48
cz=camera position z()/48
if cx<>ocx or cz<>ocz
if cx>=0 and cz>=0 and cx<=15 and cz<=15
for n=grass_index(cx,cz) to grass_index(cx,cz)+grass_len(cx,cz)
position object gno+2000,grass_x#(grass_vis(n)),grass_y#(grass_vis(n))+0.05,grass_z#(grass_vis(n))
rotate object gno+2000,0,grass_a#(grass_vis(n)),0
inc gno,1
if gno>grassobj then gno=0
next n
endif
endif
return
information:
` show some information
` start printing at top of screen
set cursor 0, 0
` show frame rate
print "fps = " + str$ ( screen fps ( ) )
print ""
` current camera position
print ""
print "x = " + str$ ( camera position x ( ) )
print "y = " + str$ ( camera position y ( ) )
print "z = " + str$ ( camera position z ( ) )
print ""
` finally the polygon count
print "polygon count = " + str$ ( statistic ( 1 ) )
print ""
return

It's c**p being the only coder in the village.