Simple Water Simulation

Aus Earthdawn-Wiki.v2
Version vom 22. Oktober 2024, 19:37 Uhr von Root (Diskussion | Beiträge) (Die Seite wurde neu angelegt: „This is an example of an easy water-simulation. The algorithm is fast and stable and looks like water - not perfect, but it fits my needs. Just move the mouse over the applet: {Applet code='WaveApplet' archive='WaveApplet.jar'} It is just a 2D Version, but it is easy to extend it to 3D as you can see in Jopulous. ==== SourceCode==== * Java-SourceCode ==== Descriptio…“)
(Unterschied) ← Nächstältere Version | Aktuelle Version (Unterschied) | Nächstjüngere Version → (Unterschied)

This is an example of an easy water-simulation. The algorithm is fast and stable and looks like water - not perfect, but it fits my needs.

Just move the mouse over the applet:

{Applet code='WaveApplet' archive='WaveApplet.jar'}

It is just a 2D Version, but it is easy to extend it to 3D as you can see in Jopulous.

SourceCode

Description

A physical and mathematical description will follow, but the main idea is to use a height-field of seperated water columns and to calculate the pressure and the amount of water flowing between direct neighbour columns. The runtime is O(n) where n is the number of columns.

The base idea is to use Newton's second law of motion

{Math fontsize='18' F=\frac{dp}{dt}= \frac{d}{dt}(mv) =m\frac{dv}{dt}=ma }

in a combination with Bernoulli's principle

{Math fontsize='18' \frac{v^2}{2}+gy+\frac{P}{\rho}=constant }

where

v fluid velocity along the streamline
g gravitational constant
y elevation in the direction of gravity
P pressure along the streamline
{Math latex='
rho' fontsize='8'}
fluid density

The algorithm is far from beeing a realistic simulation, if you look at the following.

But with modern algorithms it is possible to get close to the original (sadly not in real time ; -) :

And here an other naive algorithms like the one I use:

TODO

  • Make it better by suppressing the unnatural high frequent waves. This could be done by adding some not-accelerated amount of the water differnece to the left and right direct neighbour columns.