Question

I have a character with a body and head. The head is connected to the body as a bone and I already know the name of the bone. Now I want to get the direction of the head? Is that possible? I tried this but it doesn't seem to work:

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;

I thought I should multiply by other than the unit x vector, so I tried all the combinations. In this case (i.e. Smith entity), I got the correct answer using -Vector3::UNIT_X, so I thought this is the correct solution. I tried with other entities, but I failed to get the correct answer.

Any idea?

Was it helpful?

Solution

Multiplying a quaternion by negative Z should correctly return the direction as a vector:

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

See this post on the Ogre forums.

OTHER TIPS

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

I suspect the following will also work.

// 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() );
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top