0

I wanted to use quaternions to have rotations at a specific axis regardless of the position of the cube but when I rotate 90 degrees along x axis then try to rotate along y axis instead of rotating at y it rotates at z axis any idea how to solve this? my code is the following:

   quaternion permquat;
   permquat.x = 0;
   permquat.y = 0;
   permquat.z = 0;
   permquat.w = 1;
   quaternion permquat2;
   permquat2.x = 0;
   permquat2.y = 0;
   permquat2.z = 0;
   permquat2.w = 1;

   quaternion local_rotation;
   local_rotation.w  = cosf( beta/(2.0*180.0));
   local_rotation.x = 1.0 * sinf( beta/(2.0*180.0) );
   local_rotation.y = 0.0 * sinf( beta/(2.0*180.0) );
   local_rotation.z = 0.0 * sinf( beta/(2.0*180.0) );

   quaternion local_rotation2;
   local_rotation2.w  = cosf( gamma/(2.0*180.0));
   local_rotation2.x = 0.0 * sinf( gamma/(2.0*180.0));
   local_rotation2.y = 1.0 * sinf( gamma/(2.0*180.0));
   local_rotation2.z = 0.0 * sinf( gamma/(2.0*180.0));

   permquat = mult(local_rotation, permquat);
   normalize(permquat);
   permquat2 = mult(local_rotation2, permquat2);
   normalize(permquat);
   matTransl3D = matrix(permquat);
   glMultMatrixf(*matTransl3D);  

   matTransl3D = matrix(permquat2);
   glMultMatrixf(*matTransl3D);  
   glTranslatef(-9, -9, -9);   // bottom left
   drawcube();
   glPopMatrix();

Beta and Gamma are incremented by 2 for each key press.

  • Please explain why I shouldn't mark this question as a [duplicate of this question](http://stackoverflow.com/questions/9715776/using-quaternions-for-opengl-rotations) (just like your last one)? Both you and the asker of that question were asking about using quaternions for Euler angles, as if quaternions were some kind of magical salve that would fix all your orientation problems. Both of you want to use quaternions in the same way, so I don't see how an answer to that question would be any different from the answer to yours. – Nicol Bolas Dec 06 '15 at 01:16
  • so I read your answer and I kind if understand what I am doing wrong(really sorry for repeating) but what I don't understand is how can I update the orientation as the library for opengl I am using only gives me the function of glMultMatrixf and if I don't multiply the quaternions separately and use the glMultMatrix command to achieve that there is no way to use it for right multiplication. I am again sorry if I am just repeating the questions but any help would be appreciated – Mobeen Tariq Dec 06 '15 at 10:11
  • also I have been writing my code based on [this example](http://stackoverflow.com/questions/7938373/from-quaternions-to-opengl-rotations?rq=1) – Mobeen Tariq Dec 06 '15 at 10:35
  • @NicolBolas please let me know if you have any information on the query in the comments thank you – Mobeen Tariq Dec 07 '15 at 18:59

0 Answers0