Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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;
zAdjustVec.normalise();

Quaternion targetWorldOrientation;

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

Vector3 yVec = zAdjustVec.crossProduct(xVec);
yVec.normalise();

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:

https://www.youtube.com/watch?v=6bdFhW_vtUs

Any ideas on how to fix this ?

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

OGRE3D: http://ogre3d.org/forums/viewtopic.php?f=2&t=78213
GD.Net: http://www.gamedev.net/topic/644417-vectorquaternion-help-pitch-bone-to-direction-vector/

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
add comment

Your Answer

 
discard

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

Browse other questions tagged or ask your own question.