Box2D v2 format

16 views
Skip to first unread message

Rod

unread,
Sep 21, 2009, 11:23:17 AM9/21/09
to Mekanimo
Great work on this editor!
I am wondering about updates to the system.createBox2DCpp(..) method.
In particular to handle the new b2FixtureDef in Box2D v2.x. I know the
createBox2DCpp feature is experimental, but it is great for moving
models to other Box2D platforms. :-)

Thanks again,
Rod

Fahri

unread,
Sep 21, 2009, 11:54:07 AM9/21/09
to Mekanimo
Hi Rod,

I have been working with version 2.01 for a while and am not aware of
the b2FixtureDef in the API. I remember seeing something like this in
the box2D forums but could not find anything in the documentation.
Can you post a link to the documentation so that I can see how it
works. If it isn't too complicated, I may be able to add this
functionality to the createBox2DCpp function in the next release
(coming soon).

Fahri

Rod

unread,
Sep 21, 2009, 12:14:28 PM9/21/09
to Mekanimo
Fahri,

Thanks for the quick reply:
Here are a couple links discussing it:
(HelloWorld for Box2D re-written to use it):
http://code.google.com/p/box2d/source/browse/trunk/Box2D/Examples/HelloWorld/HelloWorld.cpp

Another example: (in Objective-C)
http://www.cocos2d-iphone.org/forum/topic/1288

Basically shapes just hold geometry data, Fixtures hold some of the
physics info (friction, mass,etc), fixtures contain a shape, and then
bodies have fixtures attached to them (b2Body->CreateFixture())

Check the API.chm file in the Box2D SVN, it has the updated classes
(b2PolygonShape for example), unfortunately they have not updated the
manual yet and I don't think b2Fixture is in there yet. The test cases
have been moved over to the new format and that is the best source of
this info (and the forums).
Here is quick and dirty example:

b2PolygonShape partition0;
b2Vec2 p0vertices[6];

p0vertices[0] = b2Vec2(-3.606342f, 0.639774f);
p0vertices[1] = b2Vec2(-3.737414f, 0.394014f);
p0vertices[2] = b2Vec2(-3.671878f, -0.146658f);
p0vertices[3] = b2Vec2(-2.967366f, -1.703138f);
p0vertices[4] = b2Vec2(-1.214278f, -1.703138f);
p0vertices[5] = b2Vec2(-1.214278f, -1.309922f);
partition0.Set(p0vertices, 6);

b2FixtureDef truckFixtureDef0;
truckFixtureDef0.shape = &partition0;
truckFixtureDef0.density = 10.0f;

b2BodyDef bodyDef;
b2Body* carBody = world->CreateBody(&bodyDef);

carBody->CreateFixture(&truckFixtureDef0);

-------------
Check out the b2Fixture.h file in the SVN (under the dynamics folder):
/// A fixture definition is used to create a fixture. This class
defines an
/// abstract fixture definition. You can reuse fixture definitions
safely.
struct b2FixtureDef
{
/// The constructor sets the default fixture definition values.
b2FixtureDef()
{
shape = NULL;
userData = NULL;
friction = 0.2f;
restitution = 0.0f;
density = 0.0f;
filter.categoryBits = 0x0001;
filter.maskBits = 0xFFFF;
filter.groupIndex = 0;
isSensor = false;
}


Does that make sense?
Rod

Fahri

unread,
Sep 21, 2009, 12:42:17 PM9/21/09
to Mekanimo
Thanks for the links. I will take a look at it and see if I can add
this in the new release. The new function may look like something
like this:

def createBox2DCpp(self, filePath, version=2.01):

if the version is 2.02 then it would include fixtures.



On Sep 21, 12:14 pm, Rod <rod.stro...@gmail.com> wrote:
> Fahri,
>
> Thanks for the quick reply:
> Here are a couple links discussing it:
> (HelloWorld for Box2D re-written to use it):http://code.google.com/p/box2d/source/browse/trunk/Box2D/Examples/Hel...
>
> Another example: (in Objective-C)http://www.cocos2d-iphone.org/forum/topic/1288
Reply all
Reply to author
Forward
0 new messages