2011-01-18 5 views
1

몸과 머리가있는 캐릭터가 있습니다. 머리는 뼈로 몸에 연결되어 있고 나는 이미 뼈의 이름을 알고 있습니다. 이제 머리 방향을 찾고 싶습니다. 그게 가능하니? 나는이 시도했지만 작동하지 않는 것 : OGRE에서 오브젝트 방향 가져 오기

Entity *smith = m_sceneManager->getEntity("Smith"); 
Bone *head = smith->getSkeleton()->getBone("Bip01 Head"); 
Vector3 direction = head->_getDerivedOrientation() * Vector3::UNIT_X; 
std::cout << StringConverter::toString(direction) << std::endl; 

는 내가 단위 X 벡터 이외의 곱해야한다고 생각, 그래서 모든 조합을 시도했다. 이 경우 (즉 스미스 개체) -Vector3::UNIT_X을 사용하여 올바른 답을 얻었으므로 이것이 올바른 해결책이라고 생각했습니다. 나는 다른 엔티티들과 함께 시도했지만 정확한 답을 얻지 못했습니다.

아이디어가 있으십니까?

답변

4

올바르게 벡터로 방향을 돌려 마이너스 Z 의해 쿼터니언 곱 :

Vector3 direction = head->_getDerivedOrientation() * Vector3::NEGATIVE_UNIT_Z; 

this post on the Ogre forums.

2
// get orientation as a quaternion 
const Ogre::Quaternion quaternion = head->_getDerivedOrientation(); 

// convert orientation to a matrix 
Ogre::Matrix3 matrix3; 
quaternion.ToRotationMatrix(matrix3); 

/// get euler angles from the matrix 
Radian x; 
Radian y; 
Radian z; 
matrix3.ToEulerAnglesXYZ(x, y, z); 

// place euler angles into a vector 
Ogre::Vector3 direction(x.valueRadians(), y.valueRadians(), z.valueRadians()); 

나는 다음과 같은 것도 가능하다고 생각합니다.

// get orientation as a quaternion 
const Ogre::Quaternion q = head->_getDerivedOrientation(); 

// use pitch, yaw, and roll as values for direction vector 
const Ogre::Vector3 direction(q.getPitch(), q.getYaw(), q.getRoll());