Translate after rotate

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?

Try:
glTranslatef(3.0, 0.0, 5.0);
glRotatef(45, 0.0, 1.0, 0.0);

Instructions are executed in reverse order.

Or even better, read Ch3 of the Red Book.
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. :slight_smile:

Is this what you are trying to do?:

pushMatrix()
loadIdentity()

for(every object){

pushMatrix()
translate()
rotate()

drawObject()

popMatrix()
}

popMatrix()

Thanks guys, that cleared things up for me :slight_smile:
And thanks for the link, I didn’t even know the red book was online!

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.

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).

Ah yeah, it says “This title has not yet been released”/“Publication Date: 7 Feb 2013” on Amazon for the 8th edition.