2

希望する位置で 1 つの b2body に 2 つの円フィクスチャを追加する方法を知っている人はいますか? を使用して 2 つのポリゴン フィクスチャを 1 つのボディに追加する方法を知っていますm_centroid。しかし、サークルフィクスチャに対してはどうすればよいですか。

どんな答えでも大歓迎です。物をくっつけたい。ジョイントを試してみましたが、すべて伸縮性があります。距離スタティックが欲しい。

みんな、ありがとう!

4

1 に答える 1

6

体に 2 つのフィクスチャを作成し、これらのフィクスチャの形状を次のようにする必要があります。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);
于 2011-11-04T09:44:17.803 に答える