1

我已经创建了一个带有复合体作为底盘的子弹车,复合体由两个车身组成,一个底盘和一个炮塔。

我可以像这样获得炮塔变换和opengl矩阵:

// get chassis and turret transforms
btTransform chassisTransform = m_vehicle->getChassisWorldTransform();
btTransform turretTransform = compound->getChildTransform(1);
// multiply transforms to get updated turret transform
turretTransform *= chassisTransform;

// get turret matrix
btScalar turretMatrix[16];
turretTransform.getOpenGLMatrix(turretMatrix);

turretTransform 是 btCollisionShape 对象 (turretShape) 的变换。

我现在正试图围绕它的 Y 轴旋转这个炮塔。

我试过这个:

turretTransform.setRotation(btQuaternion(btVector3(0, 1, 0), angle));

其中角度是一个浮点数,但没有任何反应。

我肯定遗漏了一些东西,但不完全理解这些轮换是如何工作的。

4

1 回答 1

1

我不得不改变汽车炮塔设置并为炮塔创建一个单独的刚体。所以现在我有 2 个不同的刚体,汽车和炮塔。

在经历了 ConstraintDemo 之后,我得出了这个结论:

// create constraint
btVector3 axisA(0.f, 1.f, 0.f);
btVector3 axisB(0.f, 0.f, 0.f);
btVector3 pivotA(0.f, 1.f, 0.f);
btVector3 pivotB(0.f, 0.f, 0.f);
hinge = new btHingeConstraint(*m_carChassis, *turretBody, pivotA, pivotB, axisA, axisB);

// add constraint to world
bt_dynamicsWorld->addConstraint(hinge, true);

我现在可以使用hinge->enableAngularMotor(true, 0, 1);来停止炮塔旋转 abd hinge->enableAngularMotor(true, angle, 1);(浮动角),以便在需要时旋转它。

于 2013-11-24T17:27:10.790 回答