Quaternion rotations and gimble lock

Hi, I’ve been trying to implement a camera class for a couple of weeks now ive finally got something thats mostly working using quaternions for rotation and vectors for movement, but I think im suffering from gimble lock. The more i turn to the side the less height i can acheive turning upwards. Im fairly certain the vector section is correct and is mostly independant from the rotation.

Heres my code for the rotation


public void updateCamera()
{
	Quat4f rotation = new Quat4f();
		
	AxisAngle4f axisAngleX = new AxisAngle4f(cameraX.x, cameraX.y, cameraX.z, (float)Math.toRadians(angleX));
	AxisAngle4f axisAngleY = new AxisAngle4f(cameraY.x, cameraY.y, cameraY.z, (float)Math.toRadians(angleY));
		
	Quat4f quatXRotation = new Quat4f();
	Quat4f quatYRotation = new Quat4f();
		
	quatXRotation.set(axisAngleX);
	quatYRotation.set(axisAngleY);
		
	rotation.mul(quatYRotation, quatXRotation);
	rotation.normalize();
	
	Matrix4f newViewMatrix = new Matrix4f();
	newViewMatrix.set(rotation);
	newViewMatrix.transpose();
		
	float[] rotationMatrixArray = new float[]
	{
	newViewMatrix.m00, newViewMatrix.m01, newViewMatrix.m02, 0,
	newViewMatrix.m10, newViewMatrix.m11, newViewMatrix.m12, 0,
	newViewMatrix.m20, newViewMatrix.m21, newViewMatrix.m22, 0,
	 0, 0, 0, 1
	};

		gl.glLoadIdentity();
		glu.gluPerspective(60.0, 800/600, 2.0, 500.0f);
		
		gl.glTranslatef(cameraPosition.x, cameraPosition.y, cameraPosition.z);
		gl.glMultMatrixf(rotationMatrixArray);
	}

Am i doing something completely wrong? Or do i need to approach this from a different angle.

You would probably be better served by asking this question in one of the OpenGL forums here.

AIUI the whoel point of Quaternions is that they don’t suffer from gimble lock.

As this is a heavy 3D math question I would defintiely ask it in one of the 3D forums (JOGL or Java3D)

hey arthor,

what are the values for the vectors cameraX and cameraY? Simply, the axes <1,0,0>, <0,1,0>?
and do you change angleX/angleY on key strokes?

further, what is ment by ‘The more i turn to the side the less height i can acheive turning upwards’?
Rotating around the y-axis, right?

Jeff is right if the Quaternion is used to represent an orientation. On the surface, it appears that the quaternions may be used to represent axis rotations. I included an overview of Java 3D quanternions in this article that might prove useful (http://jdj.sys-con.com/read/99792.htm). The quaternions are covered in the section entitled ‘Slicker than Euler’ on page 3.

Mike

Thanks for the interest, as sugessted ive posted again in one of the 3d forums, JOGL to be specific, hopefully that is a better place for the question. Ive also answered some of the questions asked in the new post

http://www.java-gaming.org/forums/index.php?topic=12801.0