子弹转矩
我正在研究一个涉及太空船的游戏。 我们正在使用OGRE和Bullet。
例如,玩家的船应该用鼠标俯仰和偏航 - 向左移动鼠标会偏离船舶。 问题是,我无法弄清楚如何在子弹中施加扭矩。
在我们开始整合Bullet之前,我们的解决方案是像这样直接修改OGRE场景节点(使用OIS输入):
bool Game::mouseMoved(const OIS::MouseEvent &event) {
shipNode->yaw(Ogre::Degree(-event.state.X.rel));
shipNode->pitch(Ogre::Degree(event.state.Y.rel));
return true;
}
这工作得很好。
现在我们正在使用Bullet,我的计划是对刚体施加扭矩,如下所示:
bool Game::mouseMoved(const OIS::MouseEvent &event) {
//shipNode->yaw(Ogre::Degree(-event.state.X.rel));
//shipNode->pitch(Ogre::Degree(event.state.Y.rel));
shipRigidBody->applyTorqueImpulse(btVector3(-event.state.X.rel, event.state.Y.rel, 0));
return true;
}
然后,在逐步模拟之后,更新场景节点的方向,如下所示:
void Game::update(const Ogre::FrameEvent &event) {
// ... snip ...
physicsWorld->stepSimulation(event.timeSinceLastFrame, 10);
btTransform shipTransform;
shipMotionState->getWorldTransform(shipTransform);
shipNode->setPosition(shipTransform.getOrigin().x(), /* ... snip ... */);
shipNode->setOrientation(shipTransform.getRotation().getAngle(), shipTransform.getRotation().getAxis().x(), /* ... snip ... */);
}
但通过这种设置,我无法定位船。
接下来,我尝试了应用的扭矩脉冲(100, 10, 200)
每一帧不管是什么,然后打印出shipTransform.getRotation().getAngle())
总是0.此时,我变得非常困惑,因为你会认为总是施加扭矩会使身体的方位发生变化。
所以,我的问题是:我是否错过了关于btRigidBody::applyTorqueImpulse()
一些愚蠢的事情? 或者我完全吠叫错误的树?
PS: shipRigidBody
是这样构造的:
shipMotionState = new btDefaultMotionState(btTransform(btQuaternion(0, 0, 0, 1), btVector3(0, 100, 0)));
shipShape = new btBoxShape(btVector3(50, 20, 75));
shipShape->calculateLocalInertia(btScalar(1), btVector3(0, 0, 0));
shipRigidBody = new btRigidBody(btRigidBody::btRigidBodyConstructionInfo(1, shipMotionState, shipShape));
我也有代码加速船舶向前或向后的基于键盘输入,并且该代码(使用btRigidBody::applyCentralImpulse()
)工作正常。
上一篇: Torque in Bullet