Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 6 of 6

Thread: Applying two rotations to the same object

Hybrid View

  1. #1
    Newbie Newbie
    Join Date
    Dec 2012
    Posts
    3

    Applying two rotations to the same object

    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

    Code :
        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.

    Code :
        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.

  2. #2
    Newbie Newbie
    Join Date
    Dec 2012
    Posts
    3

    Question Applying two rotations to the same object

    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

    Code :
        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.

    Code :
        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.

  3. #3
    Intern Contributor
    Join Date
    Dec 2012
    Posts
    74
    Try first call the Y rotation then call the X rotation.

  4. #4
    Intern Contributor
    Join Date
    Dec 2012
    Posts
    74
    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

  5. #5
    Senior Member OpenGL Pro
    Join Date
    Jan 2012
    Location
    Australia
    Posts
    1,101
    combing the 2 rotations with the 2 calls is correct even if it looks weird

  6. #6
    Intern Contributor
    Join Date
    Dec 2012
    Posts
    74
    Try first call the Y rotation then call the X rotation.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •