2
\$\begingroup\$

I want to make a simulation of water drops producing waves, in OpenGL with C++. I calculated the height for each point of my plane grid in the 'Vertex Shader' with this formula:

Wi(x, y, t) = Ai * sin(Do • (x, y) * wi + t * Pi)

The problem is that I don't know how to generate the waves so they gradually advance.


This is what my waves look like:

My waves.

I want to have one circle at the beginning instead of all of them. The first circle should get bigger, like in the photo.


How do I do this?

\$\endgroup\$
7
  • \$\begingroup\$ Where did you get that formula from? \$\endgroup\$ – Bálint Jan 1 '17 at 22:20
  • \$\begingroup\$ http.developer.nvidia.com/GPUGems/gpugems_ch01.html \$\endgroup\$ – domino dominica Jan 1 '17 at 22:23
  • \$\begingroup\$ This article is about endlessly generating waves, not about actually computing realistic physic based ones. \$\endgroup\$ – Bálint Jan 1 '17 at 22:34
  • 1
    \$\begingroup\$ It looks to me like you have the advancing term in there already: + t*phi is a phase adjustment, which shifts the waves over time (t) at a speed given by the phi coefficient. \$\endgroup\$ – DMGregory Jan 1 '17 at 22:36
  • \$\begingroup\$ @dominodominica What are x, y and t? \$\endgroup\$ – user253751 Jan 4 '17 at 2:50
1
\$\begingroup\$

Wave function

See that t there towards the end?

That represents time. Replace it with the system clock time in milliseconds, adjust Phi as necessary (so that the waves move at the desired rate: larger phi value means they'll move more quickly, smaller phi and they've move more slowly, negative and they're converge rather than diverge), and you're done.

\$\endgroup\$
2
  • 1
    \$\begingroup\$ Is that a 麒麟 in your profile pic? \$\endgroup\$ – Engineer Apr 21 '17 at 18:17
  • 1
    \$\begingroup\$ @ArcaneEngineer It's a dragon. \$\endgroup\$ – Draco18s no longer trusts SE Apr 21 '17 at 18:18
0
\$\begingroup\$

You probably want to do something like a physics simulation of the water surface. If you break the surface up into smaller polygons and connect neighboring polys by virtual springs, you can move one in the center and that movement should propagate over time. Here is an interesting example with links to papers on how it works.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.