Results 1 to 4 of 4

Thread: Rotation point?!

  1. #1

    Rotation point?!

    Hi all,

    Is there any way of setting an axis point for rotation?

    Im currently using glRotate(angle, 0,0,1); but this will rotate the texture by its lower left cornour, but i want it to be rotated by maybe the center of the texture or maybe the top right cornour!
    Is this possible?

    Thanx for any help
    M109uk
    <br />--------------------------------------------------------
    <br />www.pulse-soft.oneuk.com

  2. #2

    Rotation point?!

    If you want to mess with the texture matrix then you have to multiply it with a translation matrix (to bring it's center point to 0,0), then by rotation matrix and another translation matrix to get it back in position, but if you're transforming not a lot of points it will be faster to just rotate texture coordinates by hand.
    X:= X ?¢_" CenterX;
    Y:= Y ?¢_" CenterY;
    NewX:= X * Cos(Angle) ?¢_" Y * Sin(Angle) + CenterX;
    NewY:= Y * Cos(Angle) + X * Sin(Angle) + CenterY;

  3. #3

    Rotation point?!

    Thanx,

    I think i understand what you mean, i have to translate to the center of the texture, rotate it then translate it back to original?

    I have tried the following just to get it working:
    [pascal]
    glPushMatrix;
    glMatrixMode(GL_TEXTURE);
    glLoadIdentity;

    .... Other code ....

    Center[0] := Width of face div 2
    Center[1] := Height of face div 2

    X := 0-Center[0]; // Gives me the lower left cornour
    // X := 1-Center[0]; // Gives me the upper right cornour
    Y := 0-Center[1]; // Gives me the lower left cornour
    // Y := 1-Center[1]; // Gives me the upper right cornour

    X := X*Cos(Angle)-Y*Sin(Angle)+Center[0];
    Y := Y*Cos(Angle)-X*Sin(Angle)+Center[1];

    Angle := Rotation*ElapsedTime;

    glTranslatef(X, Y, 0);
    glRotatef(Angle, 0, 0, 1);
    glTranslatef(-X, -Y, 0);

    glMatrixMode(GL_MODELVIEW);
    [/pascal]

    Im guessing im doing something wrong here?
    M109uk
    <br />--------------------------------------------------------
    <br />www.pulse-soft.oneuk.com

  4. #4

    Rotation point?!

    Ok no worries, i have solved my problem (by mistake).

    I just simply used:
    [pascal]
    glTranslatef(0.5, 0.5, 0);
    glRotatef(Rotation*ElapsedTime);
    glTranslatef(-0.5, 0.5, 0);
    [/pascal]

    and it works great.

    Thanx again for you help
    M109uk
    <br />--------------------------------------------------------
    <br />www.pulse-soft.oneuk.com

Bookmarks

Posting Permissions

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