1
無論我嘗試什麼,我都無法在Box2d中獲得電機接頭旋轉(具體而言,我使用的是liquidfun,它是Box2d的超集) 您可以看到下面的代碼沒有任何原因生產..
1.A圓形靜態的「支點」
2.A動態的「木板」,這是由旋轉關節電機Box2D:旋轉電機接頭不工作
我得到的兩具屍體,但「板」旋轉不旋轉。
b2BodyDef bd2;
bd2.type = b2_staticBody;
bd2.position.Set(0, 0);
b2Body* pivot = world->CreateBody(&bd2);
{
b2CircleShape circleShape;
circleShape.m_radius = 0.5f;
b2FixtureDef myFixtureDef;
myFixtureDef.shape = &circleShape;
pivot->CreateFixture(&myFixtureDef);
}
b2BodyDef bd3;
bd3.type = b2_dynamicBody;
bd3.position.Set(0, 0);
bd3.angle = 1.0f;
b2Body* plank = world->CreateBody(&bd3);
{
b2PolygonShape boxShape;
boxShape.SetAsBox(2, 0.5f);
b2FixtureDef myFixtureDef2;
myFixtureDef2.shape = &boxShape;
plank->CreateFixture(&myFixtureDef2);
}
{
b2RevoluteJointDef revoluteJointDef;
revoluteJointDef.bodyA = pivot;
revoluteJointDef.bodyB = plank;
revoluteJointDef.collideConnected = false;
revoluteJointDef.localAnchorA.Set(0, 0);
revoluteJointDef.localAnchorB.Set(0, 0);
revoluteJointDef.enableMotor = true;
revoluteJointDef.maxMotorTorque = 100000.0f;
revoluteJointDef.motorSpeed = 2.0f;
b2RevoluteJoint* m_joint = (b2RevoluteJoint*)world->CreateJoint(&revoluteJointDef);
}
這是範圍問題嗎?或者是世界上持久的? – mlatu
另外,http://box2d.org/manual.pdf第8.4章說使用類似b2RevoluteJointDef :: Initialize(myBodyA,myBodyB,myBodyA-> GetWorldCenter());試過嗎? – mlatu
@mlatu當「木板」停留在原地時,這個聯合是堅持不懈的。它不會在重力下落入無限的空間。我嘗試使用b2MotorJoint b2MotorJoint * m_joint初始化; \t b2MotorJointDef mjd; \t mjd.Initialize(pivot,plank); \t mjd.maxForce = 10000.0f; \t mjd.maxTorque = 10000.0f; \t m_joint =(b2MotorJoint *)world-> CreateJoint(&mjd); –