\n\n
glRotatef(rotateAmount,1,0,0);\nglRotatef(rotateYamount,0,-1,0);\n
\n\nI do get the required X and Y rotations independently, but when together, it combines into some weird rotation effect.
\n","author":{"@type":"Person","name":"Cipher"},"upvoteCount":1,"answerCount":2,"acceptedAnswer":null}}Reputation: 6102
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)
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?
EDIT:
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.
Upvotes: 1
Views: 460
Reputation: 64283
You need to change this :
glRotatef(rotationAmount, 1,0,0);
into this :
glRotatef(rotationAmount, 1,1,0);
Upvotes: 0
Reputation: 23560
It sounds like you just want the following. If you dont please tell and i will change it.
glPushMatrix();
glTranslatef(position of the axis point which has to be fixed for rotation);
glRotatef(rotationAmount, 1,0,0); // <- keep this but also
glRotatef(rotationAmountAroundYAxis, 0,1,0); // <- add this
glTranslatef(-position of the axis point which has to be fixed for rotation);
Rectangle(xPosition, Position,200,100);
glPopMatrix();
Upvotes: 1