在这里,我在 Bullet 中遇到了对象旋转问题。我想要实现的是同时围绕全局 x,y,z 轴旋转对象。(这里全局意味着轴x,y,z在旋转过程中不会改变)我有下面的代码
btQuaternion m_lastRot;
btTransform tranf = _obj[idx]->mp_btRidObj->getCenterOfMassTransform();
tranf.getBasis().getRotation(m_lastRot);
btQuaternion qx(btVector3(1,0,0),angX);
btQuaternion qy(btVector3(0,1,0),angY);
btQuaternion qz(btVector3(0,0,1),angZ);
tranf.setRotation(qz * qy * qx * m_lastRot);
_obj[idx]->mp_btRidObj->setCenterOfMassTransform(tranf);
但它不像我预期的那样工作。顺便说一句,下面的代码每次围绕 x、y、z 轴之一旋转对象效果很好。
btQuaternion m_lastRot;
btTransform tranf = _obj[idx]->mp_btRidObj->getCenterOfMassTransform();
tranf.getBasis().getRotation(_obj[idx]->m_lastRot);
btQuaternion qx(btVector3(1,0,0),angX);
btQuaternion qy(btVector3(0,1,0),angY);
btQuaternion qz(btVector3(0,0,1),angZ);
if(x)
tranf.setRotation(qx * m_lastRot);
else if(y)
tranf.setRotation(qy * m_lastRot);
else if(z)
tranf.setRotation(qz * m_lastRot);
_obj[idx]->mp_btRidObj->setCenterOfMassTransform(tranf);
有没有人可以告诉我如何解决这个问题?