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.