Archived

This topic is now archived and is closed to further replies.

fallingbrickwork

Gimbal Lock, Matrices, Euler and so much more!!! Enter here 4 a whinge!!

Recommended Posts

Hi all, Am I stupid or what???? (<-I''ll let you answer this!?) I''ve just spend the last couple of days getting my head around using matrices to rotate my objects instead of using glRotatef. I''m trying to avoid the hated `Gimbal Lock` and axis flipping problems I was encountering whilst coding my `80''s Marble Madness` clone!!!! (LOL!!). Now I''ve sorted out using matrices, I''m still left with `Gimbal Lock`!!!!!!!!!!!! Why use matrices, when the results seem to be the same as glRotatef. How can I make my ball always rotate in the direction of the keypress???? irrespective of the previous rotation?? (that probably made no sense!!) I only hope you don''t say........Quaternions....<-You know!!!!! (I''ve had enough problems calculating the Z, Y, X rotation matrix!) Cheers Folks, fallingbrickwork. P.S. So was I stupid or What........

Share this post


Link to post
Share on other sites
it''s all in the order of matrix multiplications...
say you have a rotation matrix for each object

float rotationMatrix[16];

so each frame you want to rotate a certain object with the x,y,z axis always ''fixed'' to you screen

values for your rotation are xrot,yrot,zrot for this frame only

so first you make up a matrix for the rotation you want to apply

float newRotation[16];
glPushMatrix();
glLoadIdentity ();
glRotatef( xrot , 1, 0, 0);
glRotatef( yrot , 0, 1, 0);
glRotatef( zrot , 0, 0, 1);
glGetFloatv(GL_MODELVIEW_MATRIX, newRotation);
glPopMatrix ();

reset the x,y,z rotation variables for the next frame
xrot=yrot=zrot=0;

next you want to combine this rotation with the previous rotations...

glPushMatrix ();
glLoadMatrixf(newRotation);
glMultMatrixf ( rotationMatrix );
glGetFloatv(GL_MODELVIEW_MATRIX, rotationMatrix );
glPopMatrix ();


now to draw you just do...

push matrix
do translate,scale...
glMultMatrixf ( rotationMatrix );
draw the object
pop matrix


this is the way i do things and i have never had a problem with gimble lock, hope everything was clear

Share this post


Link to post
Share on other sites
repeat after me "GIMBAL LOCK IS CAUSED BY USING EULAR ANGLES TO REPRESENT ROTATIONS"
btw quaternions are not necessary

http://uk.geocities.com/sloppyturds/gotterdammerung.html

Share this post


Link to post
Share on other sites
Hi, theres a great lib that takes the pain out of using matrices and quaternions etc http://math3d.sourceforge.net

All its classes are interoperable and there are so many overloaded operators that the code you write with them is usually very clean looking.

Also, its matrix element ordering and coord system is the same as OpenGL''s.

Its not documented very well (at least not in plain english ;¬) but I found it easy to get the hang of with a bit of reference to a maths text (and I really suck at 3D maths!)

Dan

Share this post


Link to post
Share on other sites
Cheers folks!!!!!!!

Thanks for the advice Tac, I''m trying it now.......!!!!!!
I hope this sorts it out as I''m starting to lose my rag...I sat at the PC and thought....`I know, I''ll code a basic move the ball through the maze game`......I''m starting to wish I''d gone up town and bought `Medal of Honour` instead!!!(LOL!!)

By the way Zedzeek, I am repeating what you said now...believe me!!!

Cheers also `mrbastard`, I''ll check out the link!


Stay posted to find out if I fix the problem...OR....Go out and but `Medal of Honour`..............I know what I''d rather do.


Thanks again folks,


fallingbrickwork.
(remember Sammy Jankis)

Share this post


Link to post
Share on other sites