我有一个身体和头部的角色。头部作为骨骼连接到身体,我已经知道骨骼的名称。现在我想得到头部的方向?那可能吗?我试过这个,但它似乎不起作用:
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
得到了正确的答案,所以我认为这是正确的解决方案。我试过其他实体,但我没有得到正确答案。
有什么想法吗?
答案 0 :(得分:4)
将四元数乘以负Z应该正确地将方向作为向量返回:
Vector3 direction = head->_getDerivedOrientation() * Vector3::NEGATIVE_UNIT_Z;
答案 1 :(得分: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() );