PDA

View Full Version : Rotating Cubes



loreen
11-15-2016, 05:42 AM
Hello,

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

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

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

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

the second one just moves half a circle

GClements
11-15-2016, 12:19 PM
glTranslatef(0,0,0);


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