Here's the code! You'll need the enhanced version of DB! You also need a texture. It crashes my computer for some reason. It worked last time I tried it! Can't think what I've changed.
Pincho.
sync on : sync rate 0
set display mode 800,600,16
load image "moss03.bmp",1
make matrix 1,3200,3200,32,32
prepare matrix texture 1,1,1,1
set matrix texture 1,0,1
color backdrop rgb(150,150,250)
set camera range 5,10000
rem vars
explradius#=200.0
mattilex=32 : mattilez=32
tilesizex#=100.0 : tilesizez#=100.0
rem normalize matrix
normalize(1,mattilex,mattilez)
rem bombs
for a=1 to 5
make object sphere a,20
color object a,rgb(255,0,0)
position object a,rnd(3200),1000+rnd(1000),rnd(3200)
next a
rem LOOP
do
rem text
text 0,0,str$(screen fps())
rem camera control
tanglex#=wrapvalue(tanglex#+mousemovey())
tangley#=wrapvalue(tangley#+mousemovex())
xangle#=curveangle(tanglex#,camera angle x(),5)
yangle#=curveangle(tangley#,camera angle y(),5)
rotate camera xangle#,yangle#,0
if mouseclick()=1 then move camera 10
if mouseclick()=2 then move camera -10
rem bomb dropping
for a=1 to 5
position object a,object position x(a),object position y(a)-10,object position z(a)
if object position y(a)<get ground height(1,object position x(a),object position z(a))
impact(1,mattilex,mattilez,tilesizex#,tilesizez#,object position x(a),object position y(a),object position z(a),explradius#)
position object a,rnd(3200),1000+rnd(1000),rnd(3200)
endif
next a
sync
loop
rem IMPACT FUNCTION
function impact(mat,mattilex,mattilez,tilesizex#,tilesizez#,x#,y#,z#,radius#)
for x=0 to mattilex
for z=0 to mattilez
rem get positions
xpos#=(x*tilesizex#)+matrix position x(mat)
zpos#=(z*tilesizez#)+matrix position z(mat)
dist#=((x#-xpos#)*(x#-xpos#))+((z#-zpos#)*(z#-zpos#))
rem check distance
if dist#<=radius#*radius#
rem change height
height#=y#-sqrt((radius#*radius#)-dist#)
if height#<get matrix height(mat,x,z)+matrix position y(mat)
set matrix height mat,x,z,height#-matrix position y(mat)
endif
endif
next z
next x
rem normalize matrix
normalize(mat,mattilex,mattilez)
endfunction
rem normalize
function normalize(mat,mattilex,mattilez)
rem Use matrix normals to make it smooth
for z=1 to mattilez-1
for x=1 to mattilex-1
rem Get matrix heights
h8#=get matrix height(mat,x,z-1)
h4#=get matrix height(mat,x-1,z)
h#=get matrix height(mat,x,z)
h2#=get matrix height(mat,x,z)
rem Calculate projected angle X using heights
x1#=(x-1)*25.0 : y1#=h#
x2#=(x+0)*25.0 : y2#=h4#
dx#=x2#-x1#
dy#=y2#-y1#
ax#=atanfull(dx#,dy#)
ax#=wrapvalue(90-ax#)
rem Calculate projected angle Z using heights
z1#=(z-1)*25.0 : y1#=h2#
z2#=(z+0)*25.0 : y2#=h8#
dz#=z2#-z1#
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 mat,x,z,nx#,ny#,nz#
next x
next z
update matrix mat
endfunction