PDA

View Full Version : Rotation

Mukund
04-02-2010, 05:51 AM
Hello everyone..I just wanted to clarify a small thing regarding rotation in OpenGL..

Now if we want to rotate an object about a fixed point,say Xf,Yf,Zf, we translate it to origin, rotate and translate it back..

But why is it that the order we give is opposite??
i mean,why do we give it as:

glTranslatef(Xf,Yf,Zf);
glRotatef();//whatever rotation is required
glTranslatef(-Xf,-Yf,-Zf);

Is this because the new point generated, a product of matrices in the reverse order??
ie

P' = p(-T)(R)(T) where(-T) is translation to origin
is this how it is done when it is given in the above mentioned order??

ZbuffeR
04-02-2010, 07:39 AM
Consider that in OpenGL you change the camera, not the object.

Mukund
04-02-2010, 07:57 AM
Now im even more confused!! can u please suggest a book which decribes these things in detail??
I started off with COMPUTER GRAPHICS by FS HILL..Now im finding hard to understand the exact concept behind the OpenGL functions..
Pls help..

strattonbrazil
04-02-2010, 08:28 AM
Now if we want to rotate an object about a fixed point,say Xf,Yf,Zf, we translate it to origin, rotate and translate it back..

If you're translating around a point, you're moving the object such that the point you're rotating around is the origin.

Say I have a sphere at (10,10,0). I want to rotate it around (0,10,0). I need to move my sphere to the system of that point, where that point is the origin.

glTranslate(0,-10,0); // A - new point of sphere becomes (10,0,0)
glRotate(degrees); // B - do your rotation
glTranslate(0,10,0); // C - move it back to the original space
drawSphere();

The points for the sphere are multiplied like this

C * B * A * points

Mukund
04-02-2010, 09:48 AM
@strattonbrazil..Thanks a lot for clarifying my doubt..Now i got the concept.. :)

Mukund
04-02-2010, 10:04 AM
One more thing, for the example yoy just gave,can this be done??

glTranslatef(-10,0,0);//Move to that point
glTranslatef(0,-10,0);//Move to origin of coordinate system
glRotate();
glTranslatef(0,10,0);//MOve back to the required point..

Can this be done??

strattonbrazil
04-02-2010, 11:29 AM
Can this be done to do what? The same thing? No. If you add on that first line, you're obviously going to get a different result.

glTranslate(10,10); // sphere will appear at (10,10) if it's object coordinates are centered at (0,0)
glTranslatef(0,-10,0); // move to coordinate space of rotation point so rotation point is at (0,0)
glRotate();
glTranslatef(0,10,0); // move back by doing a translation in the opposite direction

Mukund
04-02-2010, 07:13 PM
Yeah now i get it..Thank you.