I'm trying to convert two axis rotations into Quaternion rotations. When I constrain the rotations to one axis i can get it to work properly, but it requires I multiply it by a second quaternion of 90degres to get it to work. Note, this code doesn't compile, I will have the whichever two I'm not using commented out when running.

if(cameraXRotate > 180) { mult = -1; } /* rotation around the x axis*/ Quaternion cameraX = new Quaternion(mult * cameraXRotate * (float)(Math.PI / 180.0), new XYZ(1,0,0)); Quaternion camera = new Quaternion(90 * (float) (Math.PI / 180.0), new XYZ(0, 1, 0)); /* Rotation around the y axis*/ Quaternion cameraY = new Quaternion(-cameraYRotate * (float) (Math.PI / 180.0), new XYZ(0, 1, 0)); Quaternion camera = new Quaternion(90 * (float) (Math.PI / 180.0), new XYZ(1, 0, 0)); /* rotation around the z axis*/ Quaternion cameraZ = new Quaternion(cameraZRotate * (float)(Math.PI / 180.0), new XYZ(0,0,1)); Quaternion camera = new Quaternion(90 * (float) (Math.PI / 180.0), new XYZ(1, 0, 0));

Now, firstly, I'm not sure why I have to multiply by 90 to get all these to work, and I'm not sure why I have to reverse the rotation on the X axis if it's greater than 180. All I know, is that these seem to work properly on single axis rotation.

This is the standard rotation code in openGL for the cameraX and Y, the negative cameraX is deliberate-

glRotatef(-cameraXRotate, 1, 0, 0); glRotatef(cameraYRotate, 0, 1, 0);

Now, when I try to multiple the two rotations together, I get weird angles. This is my rotation code:

/* x axis rotation */ Quaternion cameraX = new Quaternion(mult * cameraXRotate * (float)(Math.PI / 180.0), new XYZ(1,0,0)).mul(new Quaternion(90 * (float)(Math.PI / 180.0), new XYZ(1,0,0))); /* y axis rotation */ Quaternion cameraY = new Quaternion(cameraYRotate * (float) (Math.PI / 180.0), new XYZ(0, 1, 0)).mul(new Quaternion(90 * (float)(Math.PI / 180.0), new XYZ(1,0,0))); Quaternion result = Quaternion.IDENTITY.mul(cameraX.mul(cameraY));

Any ideas? I'm really stuck on this one

Thanks!