This project was sent to me by a student in belgaum via FB. It was his end sem project.
The crux of the code is in the function fnc()...
// variable stp is initialized to 1 hence the mesh is having 300 horizontal and vertical lines
// MAX is 300
// for every intersection of x , y
// rpl and nrm are two arrays with ripple values of the mesh and the normal to the wave
void fnc()
{
int i,j;
double x,y,z,w;
w=-MAX*stp/2.0; // this works out to -150
for (i=0;i<MAX;i++) // i varies from 0 to 299
{
y=w+(double)i*stp; // this y varies from -150 to 150
for (j=0;j<MAX;j++) // j varies from 0 to 299
{
x=w+(double)j*stp; // this x varies from -150 to 150
z=2.0*sin((x*x+y*y-phase)/100.0); // this is the sin wave which gives this mesh its wavey nature
// for more refer=> Link
rpl[i][j][0]=x;
rpl[i][j][1]=y;
rpl[i][j][2]=z; // z is the height field or the height of the wave
}
}
}
Here is the snapshot.
Here is the code.
I had modified the code and took this snapshot where the mesh is being drawn using line strip.
Modification Snapshot:
The crux of the code is in the function fnc()...
// variable stp is initialized to 1 hence the mesh is having 300 horizontal and vertical lines
// MAX is 300
// for every intersection of x , y
// rpl and nrm are two arrays with ripple values of the mesh and the normal to the wave
void fnc()
{
int i,j;
double x,y,z,w;
w=-MAX*stp/2.0; // this works out to -150
for (i=0;i<MAX;i++) // i varies from 0 to 299
{
y=w+(double)i*stp; // this y varies from -150 to 150
for (j=0;j<MAX;j++) // j varies from 0 to 299
{
x=w+(double)j*stp; // this x varies from -150 to 150
z=2.0*sin((x*x+y*y-phase)/100.0); // this is the sin wave which gives this mesh its wavey nature
// for more refer=> Link
rpl[i][j][0]=x;
rpl[i][j][1]=y;
rpl[i][j][2]=z; // z is the height field or the height of the wave
}
}
}
Here is the snapshot.
Here is the code.
I had modified the code and took this snapshot where the mesh is being drawn using line strip.
Modification Snapshot:
how to add a moving boat on the surface? kindly answer
ReplyDeleteThis is a 3D project... it would be quite complex to do this... try and read through this link i am posting... 3D boat and water is way way too complex for me atleast...http://gamasutra.com/blogs/FrankKane/20140122/209052/3D_Water_Effects_Heres_Whats_Involved.php?print=1
DeleteThis comment has been removed by the author.
ReplyDeleteCan you please give the description of how the code works?
ReplyDeleteThere is absolutely no comment in the code, and that guy(veeresh) who wrote this prog is now placed in google or getgrowfit.com I'm not sure. Will try and edit this post by EOD.
Delete