在Box2D中,我可以在靜態盒子和動態鏈條形狀之間製作一個旋轉接頭,如下圖所示?我希望能夠使用帶電機的旋轉接頭旋轉鏈條形狀。 這也關係到身體的關節在哪裏嗎?它可能是而不是在實際的形狀,但它外面的某個地方?Box2d。我可以在靜態箱體和動態鏈條形狀之間進行旋轉連接嗎?
下面的代碼生成兩個夾具但他們
b2BodyDef bd2;
b2Body* ground = world->CreateBody(&bd2);
b2PolygonShape shape;
const b2Vec2 vertices[4] = {
b2Vec2(-40, -30),
b2Vec2(40, -30),
b2Vec2(40, 30),
b2Vec2(-40, 30) };
shape.Set(vertices, 4);
ground->CreateFixture(&shape, 0.0f);
b2BodyDef bd;
bd.type = b2_dynamicBody;
b2Body* container = world->CreateBody(&bd);
b2Vec2 vs[4];
vs[0].Set(-11.583f, 20.806f);
vs[4].Set(-9.164f, -19.383f);
vs[6].Set(9.164f, -19.383f);
vs[8].Set(11.342f, 0.0f);
vs[4].Set(11.583f, 20.806f);
b2ChainShape chain;
chain.CreateChain(vs, 4);
container->CreateFixture(&chain, 0.0f);
b2RevoluteJointDef revoluteJointDef;
revoluteJointDef.bodyA = ground;
revoluteJointDef.bodyB = container;
revoluteJointDef.collideConnected = false;
revoluteJointDef.localAnchorA.Set(0, 0);
revoluteJointDef.localAnchorB.Set(0, 0);
b2RevoluteJoint* m_joint = (b2RevoluteJoint*)world->CreateJoint(&revoluteJointDef);