Floating your boat...

BlitzMax Forums/Brucey's Modules/Floating your boat...

Brucey(Posted 2008) [#1]
... with Box2D's new controllers :-)

Just arrived :
* 13 new Types
* 90+ new Methods,
* 1 new example (buoyancy.bmx).

Controllers apply forces to areas of your world. The new controllers include : b2BuoyancyController, b2ConstantAccelController, b2ConstantForceController, b2GravityController and b2TensorDampingController.

Merry Christmas :-)


Armitage 1982(Posted 2008) [#2]
Well !
Very interesting new controllers :)

I spend hours to reproduce a correct buoyancy surface with submerged points forces.
I'm wondering how much this one is faster than mine.
Won't be too hard to implement since my version use a sensor as water shape.

Since b2BuoyancyController is based on an infinite normal plan, I will often need to add and remove bodies to the b2Controller list.
This is not a "normal" blitzmax List ( GetBodyList:b2ControllerEdge() )
Can you tell me if I need to verify before adding if a body is already present in the list by cycling into it or is this done automatically ?
I don't know well how to cycle into all these Controllers.
Any examples on how to do this ?


slenkar(Posted 2008) [#3]
the new methods arent in the docs?

What kinds of types are there?

I recently rediscovered box2d and found it easy to use after all


Brucey(Posted 2008) [#4]
the new methods arent in the docs?

They should be in the API part of the docs... until they are documented "properly" (by Erin Catto etc), you'll have to wait for them to appear in the other section :-)

The defs are :
b2BuoyancyControllerDef
b2TensorDampingControllerDef
b2GravityControllerDef
b2ConstantForceControllerDef
b2ConstantAccelControllerDef

for these controllers :
b2BuoyancyController
b2TensorDampingController
b2GravityController
b2ConstantForceController
b2ConstantAccelController

The small example (buoyancy.bmx) should give you an idea of what the buoyancy controller is capable of.

Essentially, you can create controllers, and add bodies to them. Those will be affected accordingly by the controller.


slenkar(Posted 2008) [#5]
so if you create a boat=plane thingy you would have to take its body off of the bouyancy controller to let it take off?


Brucey(Posted 2008) [#6]
No... the buoyancy "plane" is fixed, so when your aircraft is outside of the zone, it will handle as it would normally... but once it crosses the plane, buoyancy will again have an effect.
See the example.
You can pick up and drag the shapes around.. both above and below the "water line"... they act differently depending on where they are.


Armitage 1982(Posted 2008) [#7]
Since b2BuoyancyController is based on an infinite normal plan, I will often need to add and remove bodies to the b2Controller list.
This is not a "normal" blitzmax List ( GetBodyList:b2ControllerEdge() )
Can you tell me if I need to verify before adding if a body is already present in the list by cycling into it or is this done automatically ?
I don't know well how to cycle into all these Controllers.
Any examples on how to do this ?

Stil no tiny example on how to use the internal Buoyancy Controller List ?
I'm currently using a custom blitzmax list to handle every object but this should be more handy somewhere...
No time to find the answer myself through :s


Brucey(Posted 2008) [#8]
Can you tell me if I need to verify before adding if a body is already present in the list by cycling into it or is this done automatically ?

AddBody() doesn't check if the body is already present in the controller.

You will indeed need to be careful, since it looks like RemoveBody() will stop after finding the first "matching" body and remove it - if the body exists multiple times, it will not be fully removed.

Is this a bug? Possibly.

I have the option of holding a separate list/map myself, if that will help you?


Armitage 1982(Posted 2008) [#9]
I have the option of holding a separate list/map myself, if that will help you?

That's an idea.
In the other hand maybe not everyone will use this controller the same way so it's maybe better to let things as it is ?

What I'm currently trying to guess as you probably see at box2d Forum is why the buoyancyController linked to a sensor shape drop's containing objects when sensor or object contacts points change position or disappear (due to the box2d logic). The object then act like if it wasn't underwater even if I never removing body from the list... Probably I did an error somewhere in the processing of contact Points.