2

私は体と頭を持つキャラクターを持っています。頭は骨として体とつながっていて、骨の名前はもう知っている。今、私は頭の方向を取得したいですか?それは可能ですか?私はこれを試しましたが、うまくいかないようです:

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

2 に答える 2

5

クォータニオンに負の Z を掛けると、方向がベクトルとして正しく返されます。

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

Ogre フォーラムのこの投稿を参照してください。

于 2011-03-23T12:19:29.150 に答える
3
// 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() );
于 2011-02-07T05:58:45.507 に答える