Rotating on each of the axies

I am having problems with rotating on each of the axies independently.

I want to attach the up and down arrow keys to rotate on one axis and the left and right arrows to another. However when I do this, I have one rotating on one axis and the other rotating clockwise/counter-clockwise in respect with the screen.

I would be happy if I could have it rotate along the x and y axis independently of each other or having the object rotate in respect with the screen in both rotating directions.

this is my code so far

rotate3f(rotatex, 1.0, 0.0, 0.0);
rotate3f(rotatey, 0.0, 1.0, 0.0);

Entire another function written in psudeo-code/C++

if (UP pressed ){rotatex+= 1;}
if (DOWN pressed ){rotatex-= 1;}
if (RIGHT pressed ){rotatey+= 1;}
if (LEFT pressed ){rotatey-= 1;}

Is there something simple that I am missing.


I don’t really understand what is your problem but using rotations as you use them is not good. In fact, when you make a glRotate(AngleX, 1.0, 0.0, 0.0) , you change the modelView matrix. So when you make the second glRotate(AngleY, 0.0, 1.0, 0.0) the axis isn’t anymore the original Y axis but the new one: the one after you make the rotation on X axis.

I hope it was your problem.

Try such thing. First, I suggest you to make MATRIX variable, which contains rotation matrix for your cursor. Then, when you need to change it, you should get all your axis rotation matrix independently, transpose them and RIGHTMULTIPLY your MATRIX by these matrices. Excuse me for no code, but I lack time for it.

i couldnt really understand your post
r u seeing ‘gimbal lock’?
have a search on the net for the term + u should find info as to what it is + hopefully info to a solution


I got it to work with polar coordinates. I used the UP and DOWN arrows to inc. and dec. the angle phi and LEFT and RIGHT to inc. and dec. the angle theta. With the angles of phi and theta, I calculated where the camera should be placed while looking at the center of the object.

Why didn’t I think of this earlier. No wonder hind site is 20/20.