How to simulate liquid using the box2d?

Hi guys,
Are there someone to simulate liquid using the box2d.
I've looked at the following web site
http://www.patrickmatte.com/index.php/2009/06/16/simulating-liquid-with-a-physics-engine-in-actionscript-3/
but I still don't understand author's code.
Someone can explain. It is best to give a sample code.
It`s looks like stimulation of "Newton's law of universal gravitation" . If that so then consider following code:

Code: Select all

for ( int i = 0; i < numBodies; i++ ) {

    b2Body* bi = bodies[i];
    b2Vec2 pi = bi->GetWorldCenter();
    float mi = bi->GetMass();

    for ( int k = i; k < numBodies; k++ ) {

        b2Body* bk = bodies[k];
        b2Vec2 pk = bk->GetWorldCenter();
        float mk = bk->GetMass();

        b2Vec2 delta = pk - pi;
        float r = delta.Length();
        float force = G * mi * mk / (r*r);

        delta.Normalize();
        bi->ApplyForce(  force * delta, pi );
        bk->ApplyForce( -force * delta, pk );
    }
}


Thanks.
Jack
Software engineer at commercial refrigeration installation
I really depends on what you are looking for. The link you gave is not real liquid, but a trick to make a few balls look like liquid. If you are looking for real fluids, then you need something a lot more advanced, and there are a few (4 if I remember correctly) implementations of fluids of varying degrees of complexity here on the forums.

Original thread: https://box2d.org/forum/viewtopic.php?t=8471