#### Archived

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

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

This topic is 5990 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## 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 on other sites
unless you use quanternions dont rotate on more than 2 axi at a time. simple as that.

##### 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();
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 ();
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 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 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 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 on other sites
Hi yet again.....

I''ve tried your example Tac and I can see how it would work. The only problem is....My object now seems to be corrupted!!!

Got any ideas??!?

fallingbrickwork
(remember Sammy Jankis)

1. 1
2. 2
Rutin
21
3. 3
JoeJ
18
4. 4
5. 5

• 14
• 40
• 23
• 13
• 13
• ### Forum Statistics

• Total Topics
631722
• Total Posts
3001892
×