2014-12-08 3 views
1

여기에서 Bullet의 개체 회전에 문제가 있습니다. 구현하고자하는 것은 동시에 글로벌 x, y, z 축을 중심으로 객체를 회전시키는 것입니다. (여기서는 글로벌 수단을 X 축, Y, Z가 회전하는 동안 변경되지 않는다) I 예상대로 I는Bullet Physics에서 개체를 회전하는 방법

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); 

이 문제를 해결하는 방법을 알려주는 사람이 있습니까?

+0

관련 답변 http://stackoverflow.com/questions/8196634/how-to-apply-rotation-to-a-body-in-bullet-physics-engine –

답변

0

Jbullet에서 나는 당신이 원하는 것을 수행하는 Bullet RigidBody에 구현 된 setOrientation (Quat4f r)이라는 메소드가 있습니다. 표준 Bullet lib에도 있다고 가정합니다.

+0

답장을 보내 주셔서 감사합니다. setOrientation이라는 이름을 붙 였지만 적어도 강체 클래스에서는 발견하지 못했습니다. 대신에 문제를 해결할 다른 방법을 찾았습니다. 모두 똑같습니다. –

+0

그때 검색하는 동안 upoun이 일어나는 다른 사람에 대한 질문에 anwser로 솔루션을 추가하십시오. 미안 나는 너의 프로젝트에 많은 도움과 행운이 없었다. –

0

나는 이런 식으로 작업을 수행합니다

//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'를 얻기 위해 기억해야합니다.

+0

나는 당신의 방법을 시도하지는 않았지만, 당신의 "myquat"는 단지 당신의 객체의 쿼터니언에서 온 것인가하는 질문이 있습니다, 당신이 당신의 객체에 적용하기 전에 "myquat"의 값을 변경 했습니까? –