b2BuoyancyController

Mon, 09/15/2008 - 00:00 — Boris
Box2DBox2DFlashFlash

Following the poll, buoyancy seemed to be the popular choice for Box2D feature. I decided against the fancy and probably unreliable technique I was going to use, and have produced a "controller" based on good old, geometry, cribbing a fair amount of Erin Catto's notes on the subject. Demo

To use, you need to patch Box2DAS3, and also use the separate package. Box2D seems to take the view that force effects like buoyancy aren't a real part of the engine, so I've separated it.

This was the second time I've found a bug in Box2DAS3, just a trivial inlining of a funciton done wrong. But I guess it shows no one was actually using these features (GetVelocityAtPoint in this case), until I came along. Hopefully this contributed code makes everything easier to use.

Usage

b2Controller
This is the base class for controllers that provide forces to bodies. At the moment, only one is implemented.

b2BuoyancyController
This controller provides the forces for the buoyancy and drag of a fluid filling a half plane.
Create a new b2BuoyancyController, and add bodies to it with AddBody. Set normal and offset to specify the surface of the fluid, and fill in the various other parameters with it's physical behaviour. As usual, code has commenting for the details.

Then call b2BuoyancyController::Step once per world step, passing the timestep.

Note: You should add and remove bodies from the controller as appropriate; for large worlds it would not be efficient to add every body to the contoller. However, do not use a sensor to detect the very wide surface, this can hurt performance. Instead, you should use several smaller sensors, or b2World::Query

Bugs

I've fudged some of the drag calculations, but there's honestly no good way to do it.

Coming Features

I'll port this to C++. And I might add some more controllers to the same framework. And I suppose the buoyancy controller deserves it's own mini-broadphase.

Download

AttachmentSize
Box2DAS3 v2.0.1 - Buoyancy.zip387.54 KB

waves in the water

Hello,

The buoyancy controller is awesome. My question is how difficult would it be to have water that is changing shape to do things like waves?

Re: waves in the water

Of moderate difficulty. and unfortunately, with little relation to the techniques used here. For small waves, consider a graphical wave with no underlying physics. For large waves, you could try locally approximating as a plane. Otherwise, you'll have to start reading up on particle physics, or other ways of doing water...

Re: waves in the water

Any chance of seeing Waves Update from you?

Waves

No, I don't think so. It's not got so much to do with what I've done here, and there are several ways of doing it. I'm trying to stick with things more globally applicable.

Reply to comment | www.boristhebrave.com

We're a group of volunteers and starting a new scheme in our community.
Your web site offered us with valuable information to work on.
You have done a formidable job and our whole community will be grateful to you.

Also visit my website - anxiety medication

This is the first time I am

This is the first time I am reading about the buoyancy project. It is a brilliant decision that you have taken to produce a controller. I got a lot of information from the demo. I am glad that you shared the links for that. Thanks a lot for sharing. Keep posting.
-----------------------------
finally asleep anti-snoring mouthpiece

Reply to comment | www.boristhebrave.com

In history, galvanized iron and lead were commonly used for making pipe and tube.
It is always important to remember to not try to do it yourself especially if you're not a licensed
plumber registered in Tampa. Plumbing is 1 vocation location that
provides quite a few possibilities for all those looking for a monetarily, challenging, and
rewarding job.

The popular elect for Box2D

The popular elect for Box2D detail. I positive into the ornate yet presumably untrustworthy manner I was going to handle, plus hold produced a controller based on saintly ancient, geometry, cribbing a beautiful measure of Erin Catto's remarks on the expose furthermore also function the alienate box.
business grant writing

Post new comment

The content of this field is kept private and will not be shown publicly.
CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.