Skip to main content

Do you have a water simulation?

My suggestions are

  • fake it with springs. Each vertex on the water surface is coupled together into a spring mesh. Pull one down and they all start oscillating. You could constrain x,z motion and only allow y (or up/down motion)

  • fake it by summing sinewaves of different amplitudes and frequencies. Some thing like this:

     rez = 32;
     for(i=-rez; i<rez; i++)
        for(j=-rez; j<rez; j++)
        {
           yofs = 0;
           yofs += 1.0 * sin( t + j*0.5 + i*0.125);
           yofs += 2.0 * sin( t + (rez-j)*0.125 + i*0.25 );
           yofs += 2.0 * sin( t + (j)*0.125 + (rez-i)*0.125 );
           yofs += 0.5 * sin( t + (rez+j)*0.125 + (rez+i)*0.125 );
           glVertex(i/rez, yofs, j/rez);
        }
    
  • simulate the 2D wave equation, this can be very fast on the GPU. See this page for a java applet and some pseudo code. Also check this version, the same but even simpler. A processing sketch with code.

From the wave equation sim you can get the direction (dx,dz) of the wave is traveling in

dx = h[x-1][z] - h[x+1][z] 
dz = h[x][z-1]- h[x][x+1] 

where h a 2D array with the height of the wave at [x][z]

You could add this to the boats position to make it travel with the wave... I've tried, but the movement becomes jerky, so I smoothed it out with a simple 3x3 box filter (smoothing the differences/velocities dx dz)