PDA

View Full Version : The logic of the order in using glTranslate and glRotate ?



~cyan
05-15-2001, 12:57 AM
How should I think when I'm using glTranslate and glRotate to acomplish what I want:
- rotate by the axe of the object
- rotate by the axe of the space
- rotate by the axe of the object in other point that the center of the space.

I have succeded to realize those things but I didn't catch the logic OpenGL uses.

Teofuzz
05-15-2001, 01:19 AM
Ahemm...
I think in this way (don't know if it's right, however...)
*When an object is drawn, it is affected only by the previous gltranslate glrotate.
*I assume the object is drawn in the origin, and I'm moving
- rotate by the axe of the object
>>> glrotate with angle alpha
- rotate by the axe of the space
>>> glrotate with angle -alpha

Example 1: you orbit around a point
glRotatef(angle,0.0,1.0,0.0);
glTranslatef(0.0,0.0,-5.0);
// I rotate and then translate 5 units backwards, always facing the origin

Example 2: a point orbits around you
glTranslatef(0.0,0.0,-5.0);
glRotatef(angle,0.0,1.0,0.0);
// I translate backwards 5 units (this means that every time I'm in the same point) and then I rotate on myself... or the point rotates around me!

Hope this helps (and hope this is right!)
tFz

[This message has been edited by Teofuzz (edited 05-15-2001).]

ffish
05-15-2001, 02:23 AM
I was in a discussion about this the other day: http://www.opengl.org/discussion_boards/ubb/Forum2/HTML/003759.html

Hope that helps.