Search code examples
3dquaternionsdirectionogre

Getting Object Direction in OGRE


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?


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.