View Full Version : Rotating Cubes

11-15-2016, 05:42 AM

I am new to opengl and I am trying to draw rotating cubes that move in circular path using glTranslatef, and glRotatef.
I can't seem to get to it o work..the cubes only rotate in their position and I can't get them to move. What is the procedure that I have to follow in order to make that happen? thank you

11-15-2016, 10:04 AM
This will be easier if you post the code that isn't working.

11-15-2016, 11:41 AM
//this is the cube that should be fixed in the center
glRotatef(angle++, 0, 1, 0);

//this cube should move in circular path around the first one
glRotatef(angle++, 1, 0, 0);
glTranslatef(0, 3, 0);
glRotatef(angle++, 1, 0, 0);

the second one just moves half a circle

11-15-2016, 12:19 PM

The above call does nothing.

Bear in mind that all matrix operations except glLoadIdentity() and glLoadMatrix() are cumulative, i.e. they compose a specified transformation with the current transformation. A call to glTranslate() with zero offsets composes an identity matrix, i.e. it leaves the current transformation unchanged.

In any case, to make an object "orbit" a point, the sequence is: rotate, translate, then draw. If you're going to be drawing anything else which isn't orbiting along with that object, you'd want the rotation and translation between glPushMatrix() and glPopMatrix().