b2BuoyancyController

Discuss issues specific to the Flash/AS3 port of Box2D
BorisTheBrave
Posts: 1911
Joined: Mon Jan 07, 2008 10:51 am
Contact:

b2BuoyancyController

Postby BorisTheBrave » Sun Sep 14, 2008 10:26 am

As promised from the poll I took earlier, I've implemented buoyancy. Demo, Details, Download.

b2buoyancycontroller.png
b2buoyancycontroller.png (20.41 KiB) Viewed 5100 times


It's not particle based buoyancy as promised, but I thought that most people would actually prefer the standard sort, based on cutting up shapes, even though it only works for half planes.

Big thanks to Erin Catto, as this code is somewhat "inspired" by his notes on Buoyancy.

Edit: PS I'm getting the online demos working jerkily in FF3 and IE7. Is anyone else? Anyone know what to do to fix this?

mayobutter
Posts: 915
Joined: Fri Dec 14, 2007 8:07 pm
Contact:

Re: b2BuoyancyController

Postby mayobutter » Sun Sep 14, 2008 11:21 am

Yet another awesome contribution Boris. Thanks for this. I was able to get it working with my game in a matter of minutes (just had to patch some things in b2Shape, b2World, etc.).

One question: for some reason my "floating" objects are suffering from a perpetual bounce in & out of the fluid (they never come to rest like in the demo). Any idea what could be causing this?

EDIT: Nevermind. Saw your note about the bug in GetVelocityAtPoint, patched that and it works perfect. Nice :)

shaktool
Posts: 434
Joined: Sun Jan 20, 2008 7:52 pm
Contact:

Re: b2BuoyancyController

Postby shaktool » Sun Sep 14, 2008 10:37 pm

Awesome! I'm sure I'll use this.

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.
That bug is probably my fault. ;)

Your fix, and whatever your previous bug fix was, should be committed in the Box2DAS3 SourceForge SVN repository. If you are unable to contact skatehead to get commit permission (I haven't tried in a while), show me both bugs and I'll do it.

Erin Catto
Site Admin
Posts: 2948
Joined: Thu Sep 06, 2007 12:34 am

Re: b2BuoyancyController

Postby Erin Catto » Mon Sep 15, 2008 3:22 pm

Great work!

It is not hard to extend this method for height-field water surfaces. You just need to sample the tangent plane above the shape.

BorisTheBrave
Posts: 1911
Joined: Mon Jan 07, 2008 10:51 am
Contact:

Re: b2BuoyancyController

Postby BorisTheBrave » Mon Sep 15, 2008 4:08 pm

Yes, that's true. I liked my original idea as if you sampled points you could also have fluid velocity, density etc as fields rather than constants, and it would support extra shape types if they support TestPoint. But then I came to my senses, and realized none of those are things people might commonly want to do, and they'd miss the accuracy for flat/low curvature surfaces.

BTW Erin, I'd like to double check with you that it's ok to allow floating-in-fluid bodies to go to sleep. That's not going to cause problems is it?

Erin Catto
Site Admin
Posts: 2948
Joined: Thu Sep 06, 2007 12:34 am

Re: b2BuoyancyController

Postby Erin Catto » Mon Sep 15, 2008 6:31 pm

Yeah, I think you should allow bodies to fall asleep in the fluid. This will improve performance. You will need to wake things up if the water geometry or current changes.

freshcut
Posts: 42
Joined: Fri Feb 01, 2008 8:41 am

Re: b2BuoyancyController

Postby freshcut » Tue Sep 16, 2008 9:51 am

sometimes i think your psychic boris. First with your concaveArc and now this, bang on time for when I need it :)
awesome and very easy to implement! thanks very much for this great addition

I was wondering though, can the functionality of this be extended to allow for isolated pools of water in blocked shapes? instead of a plane that covers the whole world?

mayobutter
Posts: 915
Joined: Fri Dec 14, 2007 8:07 pm
Contact:

Re: b2BuoyancyController

Postby mayobutter » Tue Sep 16, 2008 10:19 am

freshcut wrote:I was wondering though, can the functionality of this be extended to allow for isolated pools of water in blocked shapes? instead of a plane that covers the whole world?

I was actually just thinking about this. It seems like you could just add and remove bodies from the controller as needed. You could use a sensor that wraps the buoyant region to determine what bodies to add / remove.

BorisTheBrave
Posts: 1911
Joined: Mon Jan 07, 2008 10:51 am
Contact:

Re: b2BuoyancyController

Postby BorisTheBrave » Tue Sep 16, 2008 10:29 am

This should be done by having a sensor for your pool, and add and remove bodies from the controller as they come in contact with the sensor. Sorry to force this burden on the user, but
a) I think it would be confusing to represent the fluid with a shape, when the actual calculations always use a half plane. This way forces the user to realize that, and design his levels so that pools are enclosed.
b) Box2D doesn't really have enough of a framework for me to be able to listen to sensor collisions from the controller, without interfering with user written stuff or patching the engine itself.

Ah, mayobutter beat me to it.

ewjordan
Posts: 803
Joined: Sun Sep 23, 2007 2:35 pm

Re: b2BuoyancyController

Postby ewjordan » Tue Sep 16, 2008 12:36 pm

Looks awesome! This will be a great addition to the engine.

Couple of questions:

1) Are you already porting this to C++, or does someone still need to step in on that?
2) Are you planning on adding the height field support that Erin mentioned? If so, I'll offer to set up something based on that so that we could get waves, as well (a 1D volume-corrected damped wave equation should do nicely if I can figure out a plausible way of fudging the velocity field and the reaction on the water).

Also, the SPH code from viewtopic.php?f=3&t=1210 might be useful to use for surface effects if we end up getting the wave-equation water working well enough...I'm probably going to port that code from D to either C++ or Java soon, so we'll see how it goes, I haven't taken a close look yet.

Erin wrote:
It is not hard to extend this method for height-field water surfaces. You just need to sample the tangent plane above the shape.

I'm not sure I follow what you mean by "sample" here - are you saying to clip the objects against the height-field tangent instead of the actual vertical, or to actually sample several points?


Return to “Flash”



Who is online

Users browsing this forum: No registered users and 1 guest