This shows how to make auto positioning grass with few objects!
When grass is behind camera or not on camera view it moves it front of camera.. This gives little fps boost this is easy (if advanced terrain or something else) or hard (if .x terrain or .dbo terrain) to convert to diffrent type of world/terrain
Increase or decrease GRASS Value in top of code to set amount of max grass to render
Increase or decrease the grass height and width values in top of code to set grass height and width..
Have fun!
autocam off
sync on
renderGrass=50
GRASS=50
Max_Grass_Height=50
Max_Grass_Width=50
set image colorkey 0,0,0
create bitmap 1,256,256
for x=1 to GRASS
ink rgb(0,255,0),rgb(0,255,0)
lock pixels
line rnd(256),256,rnd(256),0
unlock pixels
get image x,0,0,bitmap width(),bitmap height()
next x
delete bitmap 1
set current bitmap 0
for x=1 to GRASS
make object plain x,rnd(Max_Grass_Width),rnd(Max_Grass_Height)
position object x,rnd(255),0,rnd(255)
texture object x,x
set object transparency x,5
next x
ink rgb(rnd(255),rnd(255),rnd(255)),rgb(rnd(255),rnd(255),rnd(255))
create bitmap 1,512,512
lock pixels
for x=1 to 512
typ=rnd(3)+1
if typ=1 then dot rnd(512),rnd(512)
if typ=2 then line rnd(512),rnd(512),rnd(512),rnd(512)
if typ=3 then box rnd(512),rnd(512),rnd(512),rnd(512)
if typ=4 then circle rnd(512),rnd(512),rnd(20)
next x
repeat
inc mattexture
until image exist(mattexture)=0
get image mattexture,0,0,512,512
unlock pixels
delete bitmap 1
set current bitmap 0
make matrix 1,2000,2000,24,24
PREPARE MATRIX TEXTURE 1, mattexture, 1, 1
randomize matrix 1,rnd(20)
ink rgb(255,255,255),rgb(255,255,255)
do
control camera using arrowkeys 0,1,1
position camera camera position x(),get ground height(1,camera position x(),camera position z())+10,camera position z()
for x=1 to GRASS
if renderGrass<=x and object visible(x) then hide object x
if renderGrass>=x and object visible(x) = 0 then show object x
if object in screen(x)=0
if camBearing(x)<180
rotate object x,camera angle x(),camera angle y(),camera angle z()
pos=rnd(3)
if pos=0 then position object x,camera position x()+rnd(255),0,camera position z()+rnd(255)
if pos=1 then position object x,camera position x()-rnd(255),0,camera position z()-rnd(255)
if pos=2 then position object x,camera position x()-rnd(255),0,camera position z()+rnd(255)
if pos=3 then position object x,camera position x()+rnd(255),0,camera position z()-rnd(255)
position object x,object position x(x),get ground height(1,object position x(x),object position z(x)),object position z(x)
move object x,rnd(300)
point object x,camera position x(),0,camera position z()
else
rotate object x,camera angle x(),camera angle y(),camera angle z()
if pos=0 then position object x,camera position x()+rnd(255),0,camera position z()+rnd(255)
if pos=1 then position object x,camera position x()-rnd(255),0,camera position z()-rnd(255)
if pos=2 then position object x,camera position x()-rnd(255),0,camera position z()+rnd(255)
if pos=3 then position object x,camera position x()+rnd(255),0,camera position z()-rnd(255)
position object x,object position x(x),get ground height(1,object position x(x),object position z(x)),object position z(x)
move object x,rnd(500)
point object x,camera position x(),0,camera position z()
endIf
endif
next x
Text 0,0,"Press [i] to increase number of rendered grass!"
Text 0,20,"Press [d] to decrease number of rendered grass!"
text 0,40,"FPS:"+str$(screen fps())
text 0,60,"Rendered Grass:"+str$(renderGrass)
text 0,80,"Max Grass to render:"+str$(GRASS)
if keystate(23) and renderGrass<GRASS then inc renderGrass,1
if keystate(32) and renderGrass>0 then dec renderGrass,1
update matrix 1
fastsync
loop
function camBearing(object)
rem taken from DBPro Programmers Resource (http://www.liquid-hosting.com/banshee)
bearing#=wrapvalue(atanfull(object position x(object)-camera position x(),object position z(object)-camera position z())-camera angle y())
endfunction bearing#

