Updated Water Effect Algorithm!

4 replies [Last post]
Joined: 10/03/2012

I totally want to thank Mom4Evr for being awesome and posting a very nice algorithm and even a video on doing a World of Goo-like water effect. I have one way cool thing to add to it of great interest to like-minded individuals. When I ran the algorithm posted by Mom4Evr I found that it works great on my computer. However, it was not behaving consistently on other computers, even after utilizing the frame rate in the specified area of the algorithm as suggested. Note that utilizing the frame rate in the specified area DID help a little. However, it was not consistent enough for my requirements. For individuals who wish to render a World of Goo-like water effect on machines that could have conceivably any time step for each render, I have an updated algorithm that can be used that works VERY well:

#include <math.h>
 * Renders a neat-o World of Goo-like water effect.
 * @param timeDelta the number of microseconds that have
 * elapsed since last calling draw
void draw(const int &timeDelta)
    for (int i = 1; i < numPoints - 1; i++)
      velocities[i] += yourFavoriteValue * timeDelta * (
          (heights[i-1] + heights[i+1] + calmHeight) /
          3.0 - heights[i]) / someConstant;
      velocities[i] *= pow(yourFavoriteDampeningValue,
          yourFavoriteValue * timeDelta / someConstant);
    // and the actual height data
    for (int i = 1; i < numPoints - 1; i++)
      heights[i] += yourOtherFavoriteValue * timeDelta * velocities[i] /
    // boundary conditions
    heights[0] = heights[1];
    heights[numPoints - 1] = heights[numPoints - 2];
    // render your water using the height values!
    . . .

Thanks again and I hope everything is going well. Please feel free to question and/or insult me if I made any mistakes!

-Stephen Hoskins

Joined: 08/06/2010

This will be useful! Thanks!

Another Planet finally has an official release! Download chapters 1 through 3 here! Thank you for waiting so long while I kept starting over.

Joined: 09/01/2009

Very nice! Yeah, I wasn't even thinking about time deltas when I made that example. This is definitely a good thing to think about. And very few lines of code, too, which is sweet.

Joined: 07/05/2011

Thanks. I will try it sometime.

Joined: 10/03/2012

It's totally chock full of "pow," right? =)

(Waka waka...)