PDA

View Full Version : Applying two rotations to the same object



optimus_prime
12-04-2012, 12:56 AM
I have a simple rectangular shape in my application which I am rotating fixing one of its side, and rotating around the X axis. The rotation looks something like the following figure (grey denotes the current rotation that I am getting with this figure)

http://i.stack.imgur.com/IGWXg.jpg

I am using the following code to get this rotation


glPushMatrix();
glTranslatef(position of the axis point which has to be fixed for rotation);
glRotatef(rotationAmount, 1,0,0);
glTranslatef(-position of the axis point which has to be fixed for rotation);
Rectangle(xPosition, Position,200,100);
glPopMatrix();

However, I have to rotate this same figure with an additional rotation around y axis around one of its side (green arrow direction in the figure). How do I rotate this rectangle such that it keeps on rotating around x-axis and around y-axis simaltaneously?

I did try adding another glRotatef(rotateAroundYaxis amount,0,1,0) but the output does not actually looks like what I was expecting. The figure rotates in two quadrants instead of rotating around y-axis like a simple page turn.

While if I try these two rotations independently using only one of them in the program (not both of them together), i.e.


glRotatef(rotateAmount,1,0,0);
glRotatef(rotateYamount,0,-1,0);

I do get the required X and Y rotations independently, but when together, it combines into some weird rotation effect.

optimus_prime
12-04-2012, 01:01 AM
I have a simple rectangular shape in my application which I am rotating fixing one of its side, and rotating around the X axis. The rotation looks something like the following figure (grey denotes the current rotation that I am getting with this figure)

http://i.stack.imgur.com/IGWXg.jpg

I am using the following code to get this rotation


glPushMatrix();
glTranslatef(position of the axis point which has to be fixed for rotation);
glRotatef(rotationAmount, 1,0,0);
glTranslatef(-position of the axis point which has to be fixed for rotation);
Rectangle(xPosition, Position,200,100);
glPopMatrix();

However, I have to rotate this same figure with an additional rotation around y axis around one of its side (green arrow direction in the figure). How do I rotate this rectangle such that it keeps on rotating around x-axis and around y-axis simaltaneously?

I did try adding another glRotatef(rotateAroundYaxis amount,0,1,0) but the output does not actually looks like what I was expecting. The figure rotates in two quadrants instead of rotating around y-axis like a simple page turn.

While if I try these two rotations independently using only one of them in the program (not both of them together), i.e.


glRotatef(rotateAmount,1,0,0);
glRotatef(rotateYamount,0,-1,0);

I do get the required X and Y rotations independently, but when together, it combines into some weird rotation effect.

tonyo_au
12-04-2012, 05:17 PM
combing the 2 rotations with the 2 calls is correct even if it looks weird

newbiecow
12-23-2012, 06:46 PM
Try first call the Y rotation then call the X rotation.

newbiecow
12-23-2012, 07:04 PM
Try first call the Y rotation then call the X rotation.

newbiecow
12-23-2012, 07:17 PM
OK. Optimus Prime. It seems you can't transform right.
Any transformation order as t1,t2,...,tn. You should write your code as tn,...,t2,t1.

Remember, to transform in OpenGL world, you should turn your head down and put your feet up.


Best Regards,


newbiecow