View Full Version : Translate after rotate

10-30-2012, 10:29 AM
I am trying to translate an object in world space after rotating it at the origin. The problem is, after I rotate an object while it's at the origin, its local coordinate system rotates as well, so its axes are not parallel with the world coordinate axes anymore. So, for example, if I needed to translate an object to the point (3, 0, 5) after rotating the object around the y-axis, I would not be able to do this since the object's local coordinate system isn't the same as the world coordinate system. For example:

glRotatef(45, 0.0, 1.0, 0.0);
glTranslatef(3.0, 0.0, 5.0);
glutSolidCube(1); // This won't be at (3,0,5) like how I need it

How can I overcome this?

10-30-2012, 12:17 PM
glTranslatef(3.0, 0.0, 5.0);
glRotatef(45, 0.0, 1.0, 0.0);

Instructions are executed in reverse order.

10-30-2012, 01:09 PM
Or even better, read Ch3 of the Red Book (http://www.glprogramming.com/red/chapter03.html).
Instructions are not executed in reverse order! They are executed in the order they are issued.
If you "think in local coordinate system", commands actually move local coordinate system, and all transformations are done in local coordinate system.
If you "think in global coordinate system", object are moved in that system as the transformations are done in global system, but in the reverse order.
Of course, OpenGL Programming Guide would explain everything much better. :)

10-31-2012, 02:58 AM
Is this what you are trying to do?:


for(every object){





11-01-2012, 12:21 AM
Thanks guys, that cleared things up for me :)
And thanks for the link, I didn't even know the red book was online!

Dan Bartlett
11-01-2012, 04:58 AM
It's a very old version that's online (version 1.1). Recent editions of the red book (is it now orange?) include more of the up to date stuff, with the most recent version covering OpenGL 4.3 AFAIK.

11-01-2012, 09:50 AM
Nope! The latest is OpenGL Programming Guide: The Official Guide to Learning OpenGL, Versions 3.0 and 3.1 (7th Edition).
The greatest part of the book is about legacy OpenGL. Shaders are just mentioned and without a context (not GL context, but how to use).

Dan Bartlett
11-01-2012, 06:23 PM
Ah yeah, it says "This title has not yet been released"/"Publication Date: 7 Feb 2013" on Amazon for the 8th edition.