View Full Version : Rotation point?!
M109uk
24-08-2004, 05:26 AM
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 :)
Paulius
24-08-2004, 10:32 AM
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;
M109uk
24-08-2004, 03:22 PM
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:
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);
Im guessing im doing something wrong here?
M109uk
24-08-2004, 03:29 PM
Ok no worries, i have solved my problem (by mistake).
I just simply used:
glTranslatef(0.5, 0.5, 0);
glRotatef(Rotation*ElapsedTime);
glTranslatef(-0.5, 0.5, 0);
and it works great.
Thanx again for you help :D
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.