Skip to main content
GameDev.net gamedev.net
🔒 Locked

quaternion question

Started by McZ Dec 14, 2005 at 5:52 PM 10 replies 1.2k views
Original Post
McZ
McZ
I'm trying to implement quaternions for my new 6DOF camera class.. the thing is that I get different result compared to my matrix class. quat.Rotate(90,1,0,0); gives me 1 0 0 0 0 3.42e-008 1 0 0 -1 3.42e-008 0 0 0 0 1 and mat.Rotate(90,1,0,0); gives me 1 0 0 0 0 -4.37e-008 1 0 0 -1 -4.37e-008 0 0 0 0 1 not the same matrices altough when rotate with 45 or 60 degrees they will produce the same matrices, is this correct? if so is this why the Gimbal lock problem exists?
Sneftel
Sneftel
"-4.37e-008" is equal to -0.0000000437. "3.42e-008" is equal to 0.0000000342. Both are pretty much zero. Don't sweat it.
SiCrane
SiCrane
Gimbal lock is unrelated to numerical accuracy. Gimbal lock is an artifact of storing rotation information as successive rotations around changing axes. Gimbal lock results when one of the transformed axes becomes aligned with one of the previous axes.
McZ
McZ
Quote:
Original post by Sneftel
"-4.37e-008" is equal to -0.0000000437. "3.42e-008" is equal to 0.0000000342. Both are pretty much zero. Don't sweat it.


I'm allways thinking the other way around, that the numbers are HUGE like -4.3 billions especially when I'm suppose to sleep.

how small can a number be before I can start ignore it? or a better way how can I verify that my Quaternion works correct?
SiCrane
SiCrane
The tolerance level you use usually depends on the data type you use to store your numbers. For example, if you use IEEE single precision floating point numbers you generally would allow for more variation then if you were using IEEE double precision floating point numbers. I generally use the square root of the machine epsilon of the data type for my tolerance numbers.
jflanglois
jflanglois
Quote:
Original post by SiCrane
The tolerance level you use usually depends on the data type you use to store your numbers. For example, if you use IEEE single precision floating point numbers you generally would allow for more variation then if you were using IEEE double precision floating point numbers. I generally use the square root of the machine epsilon of the data type for my tolerance numbers.


Why square root, specifically?
SiCrane
SiCrane
Because it works.
jflanglois
jflanglois
Quote:
Original post by SiCrane
Because it works.

Prophetic, that is.
JohnBolton
JohnBolton
The square root of the epsilon ensures that half the bits are significant (in the range of [-1,1]) ... or something like that.
John BoltonLocomotive Games (THQ)Current Project: Destroy All Humans (Wii). IN STORES NOW!
flip12
flip12
Hi i had lots of troubles with 6dof camera , i wrote a post about it, you might find it usefull.
http://www.gamedev.net/community/forums/topic.asp?topic_id=363738
McZ
McZ
What have I missed?

Look at this exampel source:
CMatrix4x4 m;CQuaternion q;m = CamQuat; // Overloading the = operator in matrix class for quat to matrix convert	if(key == 'w')	{		dir = m.GetColumn(0); // get first column as vector ( camera right axis )		dir.normalize();		// rotate around the right axis would be X-axis if camera looking down the Z-axis with Y-axis as up, look up		q.rotate(0.5f, dir.x, dir.y, dir.z);	}	if(key == 's') 	{		dir = m.GetColumn(0); // get first column as vector ( camera right axis )		dir.normalize();		//  look down. Rotates around the right axis would be X-axis if camera looking down the Z-axis with Y-axis as up		q.rotate(-0.5f, dir.x, dir.y, dir.z);	}	if(key == 'a')	{		// look left		q.rotate(-0.5f, 0, 1, 0);	}	if(key == 'd') 	{		// look right		q.rotate(0.5f, 0, 1, 0);	}	// post multiply with current quaternion	CamQuat = q * CamQuat;


I don't know what I'm doing wrong but the look up/down (pitch?) doesn't work... it works as long as the camera is looking down the z-axis with x-axis as right but if I look right/left using a/d and then try to look up/down it doesn't work it still rotates around the X-Axis so if the camera lookat dir is 1,0,0 or -1,0,0 it will Roll around the x-axis not looking up/down

this is how I use the CamQuat later when changing the camera
glLoadIdentity();CMatrix m;m = CamQuat;glMultMatrix( m );glTranslatef( -campos.x, -campos.y, -campos.z );



I have read this article http://www.gamedev.net/reference/articles/article1095.asp

and a few others.

EDIT: what does the aritcle writer mean with this:
Quote:

Note: Both quaternions must refer to the same coordinate axis. I made the mistake of combining two quaternions from different coordinate axes, and I had a very hard time wondering why the result quaternion fails in certain angles only.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.