A problem of rotation with quaternion.

Immoho

17-12-2007 10:30:38

Seriously,I think it's a mathematical problem.
I wanna rotate my collision boxes with the quaternion.Here the code.

//along the Y
Quaternion q1 = torsoTrans->getOrientation();
Quaternion q2( Radian( ms.X.rel ),Ogre::Vector3::UNIT_Y );
Quaternion q3 = q1 * q2;
torsoTrans->setOrientation( q3);
//along the X
Quaternion q4 = torsoTrans->getOrientation();
Quaternion q5( Radian( ms.Y.rel ),Ogre::Vector3::UNIT_X );
Quaternion q6 = q4 * q5;
torsoTrans->setOrientation( q6);

They work fine when I just use one of them.
But when I change the x,y coordinates at the same time.It has a wrong rotation.
Because when rotate along the X,or the Y.It's local coordinate system has changed which is the parameter of the second rotation.
The second rotation has a wrong normal :(
And the funtion,setOrientation() is the only one which can change direciton of torsoTrans!
Somebody Help.Thanks.

rewb0rn

18-12-2007 08:46:20

Yes this is a common issue in 3d programming. Unfortunately I dont have this case in my application so I can not present you an out of the box solution for OgreOde. But you might want to have a look at the Ogre source code. Ogre::SceneNode provides a method where you can choose which coordinate system you want to use: local, parent or world:

Node->pitch(Ogre::Radian(-Val), Ogre::Node::TS_LOCAL);
Maybe you find something in that piece of code.