Results 1 to 4 of 4

Thread: Rotations

  1. #1
    Guest

    Rotations

    I'm doing some rotations that didn't seem very hard to do in my head, but implementing has been a pain in the a**. Anyway, I want my draw function to do a 2D rotation around a point on the screen. In between calls to this function the point of rotation could change, but the new rotation must take into account the old rotations. Here's some I'm some code I'm trying if it helps...

    if(firstTime){ //initailize matrix
    glLoadIdentity();
    glTranslatef(0.0, 0.0, -30.0);
    glRotatef(zAngle, 0.0, 0.0, 1.0);
    }else
    glPopMatrix();

    glTranslatef(xRotPos, RotPos, 0.0);
    drawShape(0,0,0.6f,1.2f,0.6f,1.2f,0);
    glRotatef(zChngAngle, 0.0, 0.0, 1.0);
    glTranslatef(-xRotPos, -yRotPos, 0.0);
    glPushMatrix();

  2. #2
    Junior Member Newbie
    Join Date
    Feb 2000
    Location
    Mexico
    Posts
    21

    Re: Rotations

    Hi Melissa , the first problem i saw is in th if part, you ask
    if(firstTime){
    load identity, and do trasnformations
    BUT YOU NEVER SAY ITS BEEN THE firstTime
    }

    so i think it is always the firstTime... well i'm a little tired now :0 i'll come back tomorrow, and see somo more.

  3. #3
    Guest

    Re: Rotations

    Sorry, I didn't include that part of my code and didn't notice it till later. The variable firstTime is initialized to TRUE and set to FALSE at the end of this code. It's really close to working. If zAngle is 0 degrees it works fine (zAngle is the total amount rotated, zChngAngle is constant), but if it's a different angle then the point of rotation gets translated incorrectly. If I move it straight up, it moves slightly to the left as well(due to zAngle being 30 degrees in this example). This is my only problem. Sorry I didn't mention it before but I tried to keep it short. Thanks for your help Hec.

  4. #4
    Senior Member Frequent Contributor
    Join Date
    Feb 2000
    Location
    London
    Posts
    503

    Re: Rotations

    Hi Melissa,

    The easiest way to do this is to track position (xPos, yPos)and rotation (zAngle) separately. When you move, only update the position. When you rotate, only update the rotation angle.

    Now, EVERY time you want to draw the shape,
    do the following:

    glLoadIdentity();
    glTranslatef( xPos, yPos, 0.0f );
    glRotatef( zAngle, 0.0f, 0.0f, 1.0f );

    This way the translation isn't messed up by any previous rotations. This approach is also a lot more numerically stable - if you apply repeated transformations to the same matrix, rounding errors in the float math will eventually cause it to squash or distort. By starting with a clean (identity matrix) slate each time, you don't get this problem.

Similar Threads

  1. Rotations- help?
    By cloudy in forum OpenGL: Linux
    Replies: 4
    Last Post: 08-07-2009, 10:52 PM
  2. rotations
    By michi in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 03-06-2008, 05:09 AM
  3. Rotations...
    By mkardesci in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 04-19-2003, 01:06 PM
  4. Rotations
    By jhc in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 04-03-2003, 07:15 AM
  5. Rotations again !
    By Eric in forum OpenGL: Advanced Coding
    Replies: 17
    Last Post: 03-02-2000, 12:21 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean