PDA

View Full Version : Rotating on each of the axies

Thug
05-17-2001, 06:09 AM
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.

ChrisT
05-19-2001, 03:11 AM
Hi,

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.

Randolph
05-21-2001, 11:16 AM
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.

zed
05-21-2001, 12:19 PM
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

Thug
05-24-2001, 05:38 AM
Thanks,

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.