# Box2D Forums

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

 All times are UTC - 8 hours [ DST ]

 Page 1 of 1 [ 3 posts ]
 Print view Previous topic | Next topic
Author Message
 Post subject: How to simulate liquid using the box2d?Posted: Tue May 08, 2012 11:09 pm

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

 Post subject: Re: How to simulate liquid using the box2d?Posted: Tue Nov 06, 2012 9:29 am

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

 Post subject: Re: How to simulate liquid using the box2d?Posted: Mon Dec 31, 2012 5:48 am

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

 Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending
 Page 1 of 1 [ 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 forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot post attachments in this forum

 Search for: