C++ Buoyancy

Here's the place to get help and discuss features. The focus is on the C++ version, but generic questions are welcome.
BorisTheBrave
Posts: 1911
Joined: Mon Jan 07, 2008 10:51 am
Contact:

C++ Buoyancy

Postby BorisTheBrave » Mon Oct 20, 2008 2:49 pm

I've ported over my FlashAS3 buoyancy code, which I ported from Erin's C++ code. And I will now have to report it back to Flash again. I've got to stop doing things this way...

Anyway, the attached file really has two seperate parts: firstly, the buoyancy stuff people were looking forward too, and also a b2Controller framework of dubious utility.

For those who haven't seen the Flash version, controllers were my take on how to standardize hooks to Box2D for calling code repeatedly each step. They are rather simple: you create a controller, add it to the world, and add bodies to it, and Box2D will take care of the rest. At the moment, responsibility for creating and destroying controllers is on the user; it does not use the factory pattern.

It's possible to rip out the buoyancy code if you want, just use the updated Shapes folder, and rip the relevant code out of b2BuoyancyController.cpp. But I would rather get some feedback if people think controllers are a useful tool. I hope something like this will spur contributions to Box2D, by making it a bit more "pluggable", while not being abused for non-physics features.
Attachments
box2d - controllers.zip
(276.86 KiB) Downloaded 540 times

kne
Posts: 88
Joined: Mon Feb 18, 2008 12:30 am

Re: C++ Buoyancy

Postby kne » Wed Oct 22, 2008 12:34 pm

Excellent work! I've been really looking forward to the port. I think controllers are a very useful addition to Box2D and hope others embrace them as well.

I worked on merging my favorite recent user contributions to Box2D -- Thin Line Segments (Edges) and Buoyancy, and updated both to Box2D SVN r177. I attached** the result. Note that dynamic edges have no area, so they won't respond to buoyancy. Not sure what we can/should do about that. Also added a simple combination of the DynamicEdge and Buoyancy test to make sure there were no apparent crashes (EdgesBuoyancy.h).

Whether or not it makes it into the main branch, it certainly will be included on the Python end (which I think you were expecting, seeing me post here) :)

** Can't attach more than 256k, so it's here http://pybox2d.googlecode.com/files/controllers-and-edges-r177.zip

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

Re: C++ Buoyancy

Postby BorisTheBrave » Wed Oct 22, 2008 12:49 pm

Uh, can the line segments be put on dynamic objects now? I must have missed that detail.
It's actually fairly easy for me to update the code to handle line segments (as long as they are well defined closed meshes), I can put that in if needed.

kne
Posts: 88
Joined: Mon Feb 18, 2008 12:30 am

Re: C++ Buoyancy

Postby kne » Wed Oct 22, 2008 12:58 pm

Yes, the line segments can be dynamic:
shaktool wrote:
- Edge shapes can be dynamic. However, I don't really recommend it, aside from the novelty of it. They work fine if you turn on bullet mode for them, but they don't handle deep intersections very well, and they will only collide with polygons and circles. Edge shapes will never collide with each other. If you do decide to make dynamic edge shapes, don't forget to attach another shape to the same body, or maybe try messing around with b2MassData, since edge shapes always have zero mass and ignore the density property.
(http://www.box2d.org/forum/viewtopic.php?f=3&t=1577)

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

Re: C++ Buoyancy

Postby BorisTheBrave » Wed Oct 22, 2008 4:02 pm

Ok, here is a largely untested b2EdgeShape.cpp that should do that trick. Note that a similar technique will also make SetMassFromShapes work on well defined line segments, but I haven't included it here.
The bigger work is doing segment-segment collisions before they are useful in a dynamic situation, but there are real problems with that.
Attachments
b2EdgeShape.zip
(2.02 KiB) Downloaded 199 times

kne
Posts: 88
Joined: Mon Feb 18, 2008 12:30 am

Re: C++ Buoyancy

Postby kne » Wed Oct 22, 2008 4:29 pm

Good stuff. Except it launches the big line segment in the EdgesBuoyancy test out of the world. Hmm... I'll have to look into how it's implemented a bit more later.

Oh, to get it to compile, I had to make a few changes (attached).
Attachments
b2EdgeShape.zip
(2.04 KiB) Downloaded 205 times

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

Re: C++ Buoyancy

Postby BorisTheBrave » Thu Oct 23, 2008 2:40 am

Yes, as I said, it only works for meshes where every edge is connected. Otherwise, it gives rather odd results. I suppose it would have been better to assert against that:
b2Assert(m_nextEdge && m_prevEdge);
This was only a quickie. If this body of code is put in the trunk I'll go over it more thoroughly.

(There is one circumstance that is consistent, if not useful: single edges which pass through the body origin will always have 0 submerged area).

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

Re: C++ Buoyancy

Postby BorisTheBrave » Tue Oct 28, 2008 6:53 am

So, uh, no one actually cares for controllers then?

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

Re: C++ Buoyancy

Postby mayobutter » Tue Oct 28, 2008 9:15 am

BorisTheBrave wrote:So, uh, no one actually cares for controllers then?

I was initially going to use them. But then I realized that since I would exclusively be using them with sensors, and I already had a per-shape contact list and step function mechanism in place, I pretty much had all of the functionality that I would get from controllers (I can just loop through the contact list for a sensor in its step function and apply the force). So... brilliant idea, but not needed here.

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

Re: C++ Buoyancy

Postby shaktool » Tue Oct 28, 2008 11:08 am

Relax. Build it and they will come... just not overnight. Not everybody is at a point where they need this. The biggest project I'm helping out with now would have used controllers had they existed at the time, though we have workarounds now. But my next personal project will likely employ controllers.


Return to “General Discussion”



Who is online

Users browsing this forum: No registered users and 3 guests