I display caracters in Opengl, i have them rotate around axis with quaternions, what i want to achieve is make them rotate around their own axis but when using quaternions, if i rotate an object according to one axe, the others don't take in consideration this rotation will rotate around a fix world axe. Given a Quaternion Qaccumulative (former rotations) and 3 angles AngleX, AngleY and AngleZ. First i thought Euler's rotation was the thing to try and i tried several techniques :
Quaternion rot1;
Quaternion rot2;
Quaternion rot3;
Vector3 axis ;
float angle;
QAccumulative.getAxisAngle(&axis, &angle);
// first try : around fix axes
cout << "axis : " << axis << endl;
rot1.FromAxis(Vector3(1.0,0.0,0.0),angleX);
rot2.FromAxis(Vector3(0.0,1.0,0.0),angleY);
rot3.FromAxis(Vector3(0.0,0.0,1.0),angleZ);
QAccumulative = QAccumulative * rot1;
QAccumulative = QAccumulative * rot2;
QAccumulative = QAccumulative * rot3;
/*
// second try, around current modified axes
rot1.FromAxis(Vector3(axis.x,0.0,0.0),angleX);
rot2.FromAxis(Vector3(0.0,axis.y,0.0),angleY);
rot3.FromAxis(Vector3(0.0,0.0,axis.z),angleZ);
QAccumulative = QAccumulative * rot1;
QAccumulative = QAccumulative * rot2;
QAccumulative = QAccumulative * rot3;
*/
/*
// third try with Euler rotation
Quaternion rotation;
rotation.FromEuler(10*angleX,10*angleY,10*angleZ);
QAccumulative = QAccumulative * rotation;
*/
QAccumulative.normalise();
None of them have worked so far...i don't think my implementations of rotations are the problems but if someone does i will post the code. Isn't Euler what i thought it was ? What can of rotation should i use to achieve my goal ?
EDIT : i have tried this, suggested by a post :
rotate(float angleX,float angleY,float angleZ) {
Vector3 axis = Vector3(angleX,angleY,angleZ);
Vector3 worldAxis = QAccumulative * axis;
Quaternion worldRotation( worldAxis.x,worldAxis.y,worldAxis.z, 10 );
QAccumulative = worldRotation * QAccumulative;
QAccumulative.normalise();
The character still rotates around fix axis.
EDIT : I applied the pseudo code given by a post and it worked :
rotate(float angleX,float angleY,float angleZ) {
Vector3 axis = Vector3(angleX,angleY,angleZ);
Vector3 worldAxis = QAccumulative * axis;
Quaternion worldRotationx( 1.0,0,0, angleZ );
Quaternion worldRotationy( 0,1.0,0, angleX);
Quaternion worldRotationz( 0,0,1.0, -angleY );
QAccumulative = worldRotationx * worldRotationy * worldRotationz * QAccumulative;
QAccumulative.normalise();