Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/opengl/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Opengl 子弹物理中如何旋转物体_Opengl_Graphics_Rotation_Bullet - Fatal编程技术网

Opengl 子弹物理中如何旋转物体

Opengl 子弹物理中如何旋转物体,opengl,graphics,rotation,bullet,Opengl,Graphics,Rotation,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,

这里我有一个问题,物体旋转子弹。 我要实现的是同时围绕全局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);

有人能告诉我如何解决这个问题吗?

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

我这样做:

//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”,否则旋转将是错误的。

虽然我没有尝试过你的方法,但我有一个问题,你的“myquat”似乎只是来自对象的四元数,你是否更改了“myquat”的值在你将它应用到你的对象之前?谢谢你的回答。我试图找到一个名为setOrientation的函数,但至少在刚体类中找不到。相反,我已经找到了另一种解决问题的方法。尽管如此,还是要谢谢你。请继续添加你的解决方案,作为其他人在搜索时遇到的问题的答案。对不起,我对你的项目帮助不大,祝你好运