here ya go uni...
i already got it done in DBPro... moving the code over to c++ and integrating it into the current class is gonna be fun (read un as sarcasm)...
anyways... this is what it looks like...
and here's the dbPro code for the demo...
set display mode 1024,768,32
sync on
sync rate 60
hide mouse
set camera range 0,1,15000
set camera FOV 80
color backdrop 0
set ambient light 90
make light 1
color light 1, rgb(255,255,255)
`load wave texture
load image "waves.jpg", 1
`create wave mesh constant and variable
#constant WAVEHEIGHT 1
#constant SIZE_W 16
#constant SIZE_D 16
#constant SCALEW 10
#constant SCALED 10
#constant USCALE 0.25
#constant VSCALE 0.25
WaveOffset# = 0.0
`make reflection camera
make camera 1
set camera range 1,1,15000
set camera FOV 1,80
color backdrop 1,0
set camera to image 1,5,512,512
load effect "water2.fx",1,0
set effect constant float 1,"u",1
set effect constant float 1,"v",1
make object cube 4,55
position object 4, 0, 10, 0
`make a test plane
make object plain 7,1500,1500
xrotate object 7,270
texture object 7,0,5
texture object 7,1,1
set object effect 7,1
hide object 7
`make a skybox
load object "skybox2.x",8
set object light 8,0
set object texture 8,3,1
scale object 8,20000,20000,20000
`create waves arrays
dim HEIGHTMAP#(SIZE_W,SIZE_D)
dim NORMALS#(SIZE_W,SIZE_D,3)
`setup mesh memblock
if memblock exist(1) then delete memblock 1
make memblock 1, 12 + (32 * 3 * 2 * SIZE_W * SIZE_D)
write memblock dword 1, 0, 274 : `FVF FORMAT
write memblock dword 1, 4, 32 : `SIZE PER VERT
write memblock dword 1, 8, SIZE_W * SIZE_D * 2 * 3 : `VERT NO
`these vetors are used for normal calculation
null = make vector3(1)
null = make vector3(2)
null = make vector3(3)
null = make vector3(4)
null = make vector3(5)
null = make vector3(6)
null = make vector3(7)
null = make vector3(8)
null = make vector3(9)
`setup camera and lighting
autocam off
CamAngle# = 45
CAMDISTX# = SCALEW * SIZE_W
CAMDISTY# = 30.0
CAMDISTZ# = SCALED * SIZE_D
position camera CAMDISTX# * sin(CamAngle#), CAMDISTY#, CAMDISTZ# * cos(CamAngle#)
point camera 0, 0, 0
set point light 0, SCALEW * SIZE_W / 2, CAMDISTY , SCALED * SIZE_D / 2
`setup Framerate based variables
frameTime# = 1.0
startTime = timer()
do
text 10, 10, "FPS: " + str$(screen fps())
`calculate frametime
frameTime# = (0.8 * frameTime#) + ((timer() - startTime) * 0.2)
startTime = timer()
`rotate the camera around the waves
if leftkey() then inc CamAngle#, frameTime# * 0.1 : position camera CAMDISTX# * sin(CamAngle#), CAMDISTY#, CAMDISTZ# * cos(CamAngle#): point camera 0, 0, 0
if rightkey() then dec CamAngle#, frameTime# * 0.1 : position camera CAMDISTX# * sin(CamAngle#), CAMDISTY#, CAMDISTZ# * cos(CamAngle#): point camera 0, 0, 0
`increment the offset and recreate the mesh
inc WaveOffset#, frameTime# * 0.1
gosub CREATE_WAVES
position camera 1 ,camera position x(),camera position y(),camera position z()
rotate camera 1, camera angle x(), camera angle y(), camera angle z()
ro#=wrapvalue(ro#+0.05)
position object 7,500+sin(ro#)*100.0,0,500+cos(ro#)*100.0
position object 3,0+sin(ro#)*100.0,0,0+cos(ro#)*100.0
position object 4,0+sin(ro#)*100.0,0,0+cos(ro#)*100.0
sync
loop
CREATE_WAVES:
`create wave heightmap
NumberOfWavesX = 4
NumberOfWavesZ = 4
for i = 0 to SIZE_D
for j = 0 to SIZE_W
i# = i
j# = j
HEIGHTMAP#(j, i) = (cos((NumberOfWavesZ * 360.0 * j# / SIZE_W) + WaveOffset#) + sin((NumberOfWavesX * 360.0 * i# / SIZE_D) + WaveOffset#)) * WAVEHEIGHT
next j
next i
`calculate normals by effectively averagign out the front, left, back and right vertices from the current point.
for i = 1 to SIZE_W-1
for j = 1 to SIZE_D-1
set vector3 1, SCALEW, HEIGHTMAP#(i,j) - HEIGHTMAP#(i+1,j ), 0
set vector3 2, 0, HEIGHTMAP#(i,j) - HEIGHTMAP#(i ,j-1), -SCALED
set vector3 3, -SCALEW, HEIGHTMAP#(i,j) - HEIGHTMAP#(i-1,j ), 0
set vector3 4, 0, HEIGHTMAP#(i,j) - HEIGHTMAP#(i ,j+1), SCALED
cross product vector3 5, 1, 2
cross product vector3 6, 2, 3
cross product vector3 7, 3, 4
cross product vector3 8, 4, 1
set vector3 9, 0, 0, 0
add vector3 9, 9, 5
add vector3 9, 9, 6
add vector3 9, 9, 7
add vector3 9, 9, 8
NORMALS#(i,j,0) = x vector3(9)
NORMALS#(i,j,1) = y vector3(9)
NORMALS#(i,j,2) = z vector3(9)
next j
next i
`create mesh. Each poly has 2 triangles.
poly = 0
for i = 0 to SIZE_W-1
for j = 0 to SIZE_D-1
` ** POLY 1 **
x = i : z = j : y# = HEIGHTMAP#(x,z) : n = 12 + (poly * 192) : u# = x * USCALE : v# = z * VSCALE : gosub CREATE_MESH_ENTRY
x = i : z = j+1 : y# = HEIGHTMAP#(x,z) : n = 12 + (poly * 192) + 32 : u# = x * USCALE : v# = z * VSCALE : gosub CREATE_MESH_ENTRY
x = i+1 : z = j : y# = HEIGHTMAP#(x,z) : n = 12 + (poly * 192) + 64 : u# = x * USCALE : v# = z * VSCALE : gosub CREATE_MESH_ENTRY
` ** POLY 2 **
x = i+1 : z = j : y# = HEIGHTMAP#(x,z) : n = 12 + (poly * 192) + 96 : u# = x * USCALE : v# = z * VSCALE : gosub CREATE_MESH_ENTRY
x = i : z = j+1 : y# = HEIGHTMAP#(x,z) : n = 12 + (poly * 192) + 128 : u# = x * USCALE : v# = z * VSCALE : gosub CREATE_MESH_ENTRY
x = i+1 : z = j+1 : y# = HEIGHTMAP#(x,z) : n = 12 + (poly * 192) + 160 : u# = x * USCALE : v# = z * VSCALE : gosub CREATE_MESH_ENTRY
inc poly
next j
next i
`update the mesh
change mesh from memblock 1, 1
`recreate the object by deleting it and making a new one.. Kinda slow here I think but dont know any other way!!
if object exist(3) = 1 then delete object 3
make object 3, 1, 1
position object 3, 0, -10, 0
texture object 3,0,5
texture object 3,1,1
`set effect constant float 1,"u",2400
`set effect constant float 1,"v",2000
set object effect 3,1
`hide object 3
return
CREATE_MESH_ENTRY:
`This simply writes an entry into the memblock. Vetex x,y,z,nx,ny,nz,u,v
write memblock float 1, n + 0, (x - (SIZE_W/2)) * SCALEW `X
write memblock float 1, n + 4, y# `Y
write memblock float 1, n + 8, (z - (SIZE_D/2)) * SCALED `Z
write memblock float 1, n + 12, NORMALS#(x,z,0) `NX
write memblock float 1, n + 16, NORMALS#(x,z,1) `NY
write memblock float 1, n + 20, NORMALS#(x,z,2) `NZ
write memblock float 1, n + 24, u# `X
write memblock float 1, n + 28, v# `Y
return
sorry... the logic is not segmented for easy porting... basically, i'm using memblocks to warp the mesh... i hope you can make heads or tails of it...
--Mike