有人知道如何将2个圆形夹具添加到一个具有所需位置的b2体中吗?
我知道如何使用m_centroid
将两个多边形夹具添加到一个实体。但是我怎样才能为圆形灯具做这件事。
任何答案都将不胜感激。我想把一些对象粘在一起。我试过关节,但它们都很有弹性。我希望距离静止。
谢谢大家!
答案 0 :(得分:6)
你应该为你的身体创造两个灯具,这些灯具的形状应该是b2CircleShape
//Create a body. You'll need a b2BodyDef, but I've assumed you know how to use these since you say you've created bodies successfully before.
b2Body* body = world->CreateBody(&bodyDef);
//Create the first circle shape. It's offset from the center of the body by -2, 0.
b2CircleShape circleShape1;
circleShape1.m_radius = 0.5f;
circleShape1.m_p.Set(-2.0f, 0.0f);
b2FixtureDef circle1FixtureDef;
circle1FixtureDef.shape = &circleShape1;
circle1FixtureDef.density = 1.0f;
//Create the second circle shape. It's offset from the center of the body by 2, 0.
b2CircleShape circleShape2;
circleShape2.m_radius = 0.5f;
circleShape2.m_p.Set(2.0f, 0.0f);
b2FixtureDef circle2FixtureDef;
circle2FixtureDef.shape = &circleShape2;
circle2FixtureDef.density = 1.0f;
//Attach both of these fixtures to the body.
body->CreateFixture(&circle1FixtureDef);
body->CreateFixture(&circle2FixtureDef);