2011-01-18 3 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ベクトル以外を掛けなければならないと思ったので、私はすべての組み合わせを試してみました。この場合(Smithエンティティ)、-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()); 
関連する問題