Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

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've kinda solved this myself by adapting the Camera::setDirection code from OGRE to work for my need:

Now I have the following code:

Vector3 boneDir = getBoneWorldOrientation(mEntity, mHips) * Vector3::UNIT_Z; //mDirection;
Vector3 dir = mCameraTrans->_getDerivedDirection();

Vector3 zAdjustVec = dir;

Quaternion targetWorldOrientation;

Vector3 xVec = Vector3::UNIT_Y.crossProduct(zAdjustVec);

Vector3 yVec = zAdjustVec.crossProduct(xVec);

targetWorldOrientation.FromAxes(xVec, yVec, zAdjustVec);

mTransform is basically the SceneNode of the character, I'm multiplying the target orientation with it's inverse orientation to get it to parent/character-space.
mHips->_setDerivedOrientation(mTransform->_getDerivedOrientation().Inverse() * targetWorldOrientation); The above code was taken from OgreCamera.cpp, the setDirection function, the part with the fixed yaw axis. Now, that works... Sorta, I now get this problem at near-90 degree pitch, the orientation kind of flips to the other side, I've made another video to showcase this:

Any ideas on how to fix this ?

I've asked on both the OGRE3D and forums, I'll link to there just in case.


share|improve this question
In your coordinate system, which direction is down toward the floor? It is clear your cross product is flipping as you pass by that direction (probably negative UNITY), but just to be clear. The solution probably involves eschewing those absolute unit vectors and maintaining your own reference directions relative to the camera. – Seth Battin Jun 19 '13 at 0:07
OR! clamp your pitch to +- < 90 degrees. If you don't pass that axis, no problem occurs, right? – Seth Battin Jun 19 '13 at 0:14
Yes, pretty much. Thanks a lot for the reply I'm not too good with Vector/Quaternion math. And yes, -UNIT_Y is the downward direction. I think I'll go with the second option, as I don't need more pitch then that. :) – Ilija Boshkov Jun 19 '13 at 14:31
You are welcome. Be sure to come back and post your final solution as an answer. – Seth Battin Jun 19 '13 at 15:12

Your Answer


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

Browse other questions tagged or ask your own question.