PDA

View Full Version : independent objects



kuh
01-14-2005, 07:05 AM
I want to move 3 objects independently. The problem is, when rotating one, the others move too.
Now I tried to solve the problem like this:

glLoadIdentity();
glTranslatef(x1, y1, z1);
/* Draw first object */
glLoadIdentity();
glTranslatef(x2, y2, z2);
/* Draw second object */
glLoadIdentity();
glTranslatef(x3, y3, z3);
/* Draw third object */

Before I had only one glLoadIdentity, now I used 3. But now the last two objects are not visible any more! What do I do wrong? :confused:

shinpaughp
01-14-2005, 10:18 AM
You should use pushMatrix/popMatrix pairs instead of glLoadIdentity.

Modified code:



glMatrixMode( GL_MODELVIEW );
glPushMatrix();
glTranslatef(x1, y1, z1);
/* Draw first object */
glPopMatrix();
glPushMatrix();
glTranslatef(x2, y2, z2);
/* Draw second object */
glPopMatrix();
glPushMatrix();
glTranslatef(x3, y3, z3);
/* Draw third object */
glPopMatrix();Always be sure to call glPushMatrix and glPopMatrix in pairs or you may overflow the matrix stack.

kuh
01-21-2005, 05:18 AM
THANK YOU!!!! It works! :D