Enjoy
sync on : sync rate 60
set display mode 1024,768,32 : hide mouse
autocam off : set camera range 1,0x7fffffff
backdrop on : color backdrop 0
`Make a simple sphere
make object sphere 1,100
`World
fog on : fog color rgb(128,128,128) : fog distance 5000
dim matheight#(50,50)
make matrix 1,10000,10000,50,50
create bitmap 1,256,256 : set current bitmap 1
ink rgb(0,128,0),0 : box 0,0,256,256
for d=1 to 1000
ink rgb(0,rnd(128),rnd(32)),0
dot rnd(256),rnd(256)
next d
blur bitmap 1,4
get image 1,0,0,256,256
set current bitmap 0 : delete bitmap 1
prepare matrix texture 1,1,1,1
randomize matrix 1,128
for x=0 to 50 : for y=0 to 50
matheight#(x,y)=get ground height(1,x,y)
next y : next x
normal(1,50,50)
update matrix 1
`Set up reflection
dim refimg(6) as integer
for r=1 to 6
refimg(r)=1+r
make camera r : set camera range r,1,5000
set camera to image r,refimg(r),256,256
color backdrop r,0
next r
set cube mapping on 1,refimg(2),refimg(4),refimg(5),refimg(6),refimg(1),refimg(3)
`Main Loop
do
`Controls
move object 1,(upkey()-downkey())*10
yrotate object 1,wrapvalue(object angle y(1)-((leftkey()-rightkey())*3))
position object 1,object position x(1),get ground height(1,object position x(1),object position z(1))+50,object position z(1)
`Camera
set camera to follow object position x(1),object position y(1),object position z(1),object angle y(1),600,200,20,0
`Reflection
reflection(1)
sync
loop
`Reflection function
function reflection(obj)
x#=object position x(obj)
y#=object position y(obj)
z#=object position z(obj)
rad#=object size(obj)/2
position camera 1,x#,y#,z#+rad#
position camera 2,x#+rad#,y#,z# : yrotate camera 2,90
position camera 3,x#,y#,z#-rad# : yrotate camera 3,180
position camera 4,x#-rad#,y#,z# : yrotate camera 4,270
position camera 5,x#,y#+rad#,z# : xrotate camera 5,270
position camera 6,x#,y#-rad#,z# : xrotate camera 6,90
endfunction
`Normal Function (Yarble)
function normal(MatNum,MapSizeX,MapSizeZ)
for x=1 to MapSizeX-1
for z=1 to MapSizeZ-1
rem create regular normals for Terrain array
rem Vertices on the matrix
rem x-1,z-1 x,z-1
rem x-1,z x,z
rem Get stored heights
h8#=MatHeight#(x,z-1)
h4#=MatHeight#(x-1,z)
h1#=MatHeight#(x,z)
rem Calculate projected angle X using heights
y1#=h1#
y2#=h4#
rem X distance is a function of stepX#
dx#=stepX#/10
rem Y distance is the difference in height
dy#=y2#-y1#
ax#=atanfull(dx#,dy#)
ax#=wrapvalue(90-ax#)
rem Calculate projected angle Z using heights
y1#=h1#
y2#=h8#
rem Z distance is a function of stepZ#
dz#=stepZ#/10
rem Y distance is the difference in height
dy#=y2#-y1#
az#=atanfull(dz#,dy#)
az#=wrapvalue(90-az#)
rem Make normal from projected angle
nx# = Sin(ax#)
ny# = Cos(ax#)
nz# = Sin(az#)
rem Setting matrix normal for smoothness
Set Matrix Normal MatNum,x,z,nx#,ny#,nz#
Next x
Next z
EndFunction