A dynamic 3d wave generator for making things like moving water.
<edit> revised version 6/12/04, now uses a matrix.
`3dwave by Ric
ink rgb(0,0,0),0
box 0,0,10,10
ink rgb(0,0,255),0
box 0,0,8,8
get image 1,0,0,10,10
`size of wave area
rows=50
columns=50
`dipper1 x,z coordinates:
a=20
b=10
`dipper2 x,z coordinates:
c=30
d=10
elasticity#=0.03
damping#=0.94
r#=10 `cam distance
CamSpeed#=2
sync on
sync rate 30
autocam off
color backdrop 0
hide mouse
ink rgb(120,120,255),0
set text font "arial"
set text size 15
position camera rows/3,20,-10
point camera rows/2,0,columns/2
num=rows*columns
dim obnum(rows+1,columns+1)
dim v#(rows,columns)
make matrix 1,rows,columns,rows,columns
prepare matrix texture 1,1,1,1
for x=1 to rows
for z=1 to columns
obnum(x,z)=ob
ob=ob+1
next z
next x
dim fixed(rows*columns)
fixed(obnum(a,b))=1
fixed(obnum(c,d))=0
do
if keystate(30)=1 then y#=y#+1
if keystate(44)=1 then y#=y#-1
if inkey$()="=" then fixed(obnum(c,d))=1
if inkey$()="-" then fixed(obnum(c,d))=0
if fixed(obnum(a,b))=1
set matrix height 1,a,b,y#
endif
if fixed(obnum(c,d))=1
set matrix height 1,c,d,y#
endif
gosub wave
3D_Move_Cam(CamSpeed#)
update matrix 1
sync
loop
FUNCTION 3D_Move_Cam(CamSpeed#)
IF CamSpeed# = 0 THEN EXITFUNCTION
cam_x# = CAMERA ANGLE X() + MOUSEMOVEY() * .2
cam_y# = CAMERA ANGLE Y() + MOUSEMOVEX() * .2
cam_z# = CAMERA ANGLE Z() + MOUSEMOVEZ() * .2
IF upkey() = 1
polarity=1
MOVE CAMERA CamSpeed#
XROTATE CAMERA cam_x#
ENDIF
IF downkey() = 1
polarity=-1
MOVE CAMERA -CamSpeed#
XROTATE CAMERA cam_x#
ENDIF
IF leftkey() = 1
ROTATE CAMERA 0, cam_y#-90, 0
MOVE CAMERA CamSpeed#
ROTATE CAMERA cam_x#, cam_y#, 0
ENDIF
IF rightkey() = 1
ROTATE CAMERA 0, cam_y#+90, 0
MOVE CAMERA CamSpeed#
ROTATE CAMERA cam_x#, cam_y#, 0
ENDIF
ROTATE CAMERA cam_x#, cam_y#, cam_z#
ENDFUNCTION
wave:
for x=1+1 to rows-1
for z=1+1 to columns-1
`check x+1 height
if x<rows
distxp1#=get matrix height(1,x+1,z)-get matrix height (1,x,z)
endif
`check x-1 height
if x>1
distxm1#=get matrix height(1,x-1,z)-get matrix height (1,x,z)
endif
`check z+1 height
if z<columns
distzp1#=get matrix height(1,x,z+1)-get matrix height (1,x,z)
endif
`check z-1 height
if z>1
distzm1#=get matrix height(1,x,z-1)-get matrix height (1,x,z)
endif
`calculate vector some of heights adjacent to object
`and make this proportional to the objects acceleration
vectorsum#=distxp1#+distxm1#+distzp1#+distzm1#
a#=vectorsum#*elasticity#
`increase object's velocity by it's acceleration amount
v#(obnum(x,z))=v#(obnum(x,z))+a#
if fixed(obnum(x,z))=0
`reposition object
set matrix height 1,x,z,get matrix height(1,x,z)+v#(obnum(x,z))
v#(obnum(x,z))=v#(obnum(x,z))*damping#
endif
next z
next x
text 0,20,"Move camera with mouse and arrow keys"
text 0,40,"Move dipper up and down with 'a' and 'z'"
text 0,60,"Add/remove 2nd dipper with '+' and '-'"
return
p.s. feeling seasick yet? :-