Box2D Forums

It is currently Mon May 20, 2013 11:21 am

All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Tue May 08, 2012 11:09 pm 
Offline

Joined: Sun Apr 15, 2012 8:39 pm
Posts: 9
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.


Top
 Profile  
 
PostPosted: Tue Nov 06, 2012 9:29 am 
Offline

Joined: Tue Nov 06, 2012 9:21 am
Posts: 2
Location: Clifton,New Jersey
It`s looks like stimulation of "Newton's law of universal gravitation" . If that so then consider following code:
Code:
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


Top
 Profile  
 
PostPosted: Mon Dec 31, 2012 5:48 am 
Offline

Joined: Mon Jun 15, 2009 4:34 pm
Posts: 69
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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 8 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group