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: