1

在这里,我在 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);

有没有人可以告诉我如何解决这个问题?

4

2 回答 2

1

我这样做:

//this is my bullet object currently reading data from:
bulletobject->getMotionState()->getWorldTransform(trans);
btQuaternion rot = trans.getRotation();
myquat.w = rot.w();
myquat.x = rot.x();
myquat.y = rot.z();
myquat.z = rot.y();
//I then apply the quat to my object that I want to move in my graphics application.

如果你这样做,你也必须记住得到'w',否则旋转将是错误的。

于 2014-12-09T05:58:27.900 回答
0

在 Jbullet 中,我相信在 Bullet RigidBody 中实现了一个名为 setOrientation(Quat4f r) 的方法,它可以满足您的需求。我认为它也在标准的 Bullet 库中。

于 2014-12-08T20:20:02.240 回答