Creating complex shapes with box2d
I am trying to create a body in box2d which looks like this:
http://www.tobyjones.com/3d/3d_rec.jpg
I was going to create a horizontal rectangle and add vertical rectangles to each e开发者_如何学Cnd of the horiztontal rectangle.
I want to create this as a single body and so I was under the impression I should create 3 shapes and attach these to the body using a fixture, however I cant see how I'm surposed to position the shapes relative to the body.
So my question is, how do i position each shape within the body using fixtures?
I believe you also need to use the CreateShape() method for each shape you add:
bodyDef = new b2BodyDef();
body = world.CreateBody(bodyDef);
boxDef = new b2PolygonShape();
boxDef.SetAsBox(5,1);
body.CreateShape(boxDef);
boxDef.SetAsBox( 1, 5, b2Vec2( -5,5), 0 );
body.CreateShape(boxDef);
boxDef.SetAsBox( 1, 5, b2Vec2( 5,-5), 0 );
body.CreateShape(boxDef);
//middle shape
polygonShape.SetAsBox( 5, 1 );
//left end shape
polygonShape.SetAsBox( 1, 5, b2Vec2(-5,-5), 0 );
//right end shape
polygonShape.SetAsBox( 1, 5, b2Vec2( 5,-5), 0 );
精彩评论