Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 3 of 3

Thread: independent objects

  1. #1
    Junior Member Newbie
    Join Date
    Dec 2004
    Location
    roma
    Posts
    6

    independent objects

    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?

  2. #2
    Advanced Member Frequent Contributor
    Join Date
    Jan 2003
    Location
    Virginia
    Posts
    601

    Re: independent objects

    You should use pushMatrix/popMatrix pairs instead of glLoadIdentity.

    Modified code:

    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.

  3. #3
    Junior Member Newbie
    Join Date
    Dec 2004
    Location
    roma
    Posts
    6

    Re: independent objects

    THANK YOU!!!! It works!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •