Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm doing character control with kinect. I need to mirror the joint orientation because the character faces the player. Somehow by Googling through internet I've done it and everything works very well. But I have little idea about how the math works, here's my code:

Ogre::Quaternion JointOrientationCalculator::buildQuaternion(Ogre::Vector3 xAxis, Ogre::Vector3 yAxis, Ogre::Vector3 zAxis)
    Ogre::Matrix3 mat;    
        mat = Ogre::Matrix3(xAxis.x, yAxis.x, zAxis.x,
                            xAxis.y, yAxis.y, zAxis.y,
                            xAxis.z, yAxis.z, zAxis.z);    
        Ogre::Matrix3 flipMat(1, 0,  0,
                              0, 1,  0,
                              0, 0, -1);    
        mat = flipMat * mat * flipMat;
        mat = Ogre::Matrix3(xAxis.x, -yAxis.x, zAxis.x,
                           -xAxis.y, yAxis.y, -zAxis.y,
                           xAxis.z,  -yAxis.z, zAxis.z);

    Ogre::Quaternion q;

    return q;

When I need to mirror/flip it by axes z I calculate mat = flipMat * mat * flipMat; but I don't understand how this equation works.

share|improve this question

That matrix corresponds to the sequence of operations of (1) flipping the z-axis; (2) performing the original rotation; and (3) flipping the z-axis again. You can look at it as switching between "Kinect space" and your on-screen camera space, doing the rotation, then converting back to the original space. The resulting composite operation is the desired rotation, but in the flipped space.

Conceptually, it's similiar to what you'd do to rotate around a specified pivot point: you'd translate the pivot to the origin, then do the rotation, then undo the translation to return the pivot to its original location. In general you'd have a formula like inverse(matPivot) * matRotate * matPivot. However, in the case of your flip, flipMat is its own inverse, so the inverse() call is unnecessary. (By the way, a transform that is its own inverse is called an involution.)

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.