• ### Announcements

#### Archived

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

# Matrix Rotation & glRotatef

## Recommended Posts

Hi all, Can anyone help me sort out this problem.......? I''m having trouble getting around the problem of Gimbal Lock. I''m currently coding a very simple top down roll the ball around the maze type game..remember the 80''s classic Marble Madness. I only need to rotate around the X & Y axis''s. I was originally using glRotatef but run into troubles regarding axis flipping and the ball rotating in the opposite direction. I was told to construct my own rotation Matrix and this should fix the prob. It hasn''t!!! I get exactly the same results. Should a rotation matrix behave in the same way a glRotate??? if so, why go to the trouble of using them???? Can I fix this problem without using Quaternions????? as I dont need to rotate in all three axis. Basically, I always want the ball to rotate in the direction of the keypress. Cheers, fallingbrickwork.

##### Share on other sites
Rotation in 2 axis should not produce gimbal lock with glRotatef as far as I know.

Anyway, the matrix-way to fix gimbal lock is keeping a matrix in memory and updating it every frame. First construct the matrix for the initial orientation. Then each frame, construct a new matrix for the CHANGE in orientation that frame. Then multiply these matrices together and store the result in the matrix that is kept between frames. This matrix can then be glLoadMatrix''ed.

Also you could just have OpenGL keep the matrix, and then use glMultMatrix each frame. But I prefer to keep the entire matrix in memory. (It allows you to do things that would otherwise require a glGetFloatv(GL_MODELVIEW_MATRIX, ...))

##### Share on other sites
You don''t need quaternions, you can use either quaternions or matrices.

First you need to rotate about the instantanious (i.e. current) axis of rotation, which for rolling in 2D is always perpendicular to the direction of motion. A recent thread disccussed this.

Second you need to use this to update the rotation. E.g. each time the ball rolls and moves a bit further work out the matrix/quaternion and multiply that by the total rotation to get the new rotation. Use this to draw it and store it until next time/frame.

• ### Forum Statistics

• Total Topics
627708
• Total Posts
2978730

• 21
• 14
• 12
• 22
• 35