Results 1 to 4 of 4

Thread: Push Pop matrix VS Load identity??

  1. #1
    Member Contributor
    Join Date
    Aug 2002
    Posts
    95

    Push Pop matrix VS Load identity??

    I am a bit new, and a bit confussed. I am making a scene. In the scene I want a room, with about 10 independently moving objects.

    I understand if the user moves around the scene I simply load the identity matrix Rotate or translate(in the negative direction), then draw my room. Now I want to draw the objects, after they have moved.

    Should I Push the current matrix, move object one, pop the matrix, push the matrix, move object two, pop the matrix, and so on??

    Is this how its done??

  2. #2
    Junior Member Newbie
    Join Date
    Apr 2002
    Posts
    26

    Re: Push Pop matrix VS Load identity??

    Simple answer: Yes

  3. #3
    Senior Member OpenGL Guru
    Join Date
    Jun 2000
    Location
    Gastonia, NC, USA
    Posts
    2,068

    Re: Push Pop matrix VS Load identity??

    You have to remember anything in the current matrix is affected by any changes to it. example would be glrotate and gltranslate.

    What happens is when you push the matrix, every thing that has been done before the push matrix is saved in a stack. Look at it like a save command, you have saved and closed the last items you worked on.

    Now anything you do after the push matrix will not change the past saved matrix.
    now you can translate and rotate a new object without it effecting the past matrix.

    Then after you have complete changes to that object you pop the matrix back, which combines the past matrix with the current matrix.


    example:

    display()
    {

    glLoadIdenty(); // Lets start a new
    glMatrixMode(GL_MODELVIEW);

    glRotate(); //Rotate world
    glTranslate() //Translater world

    glPushMatrix()// Save past matrix to stack

    Draw_cube(); Draw a cube some where

    glPopMatrix(); Now add it to our past matrix.


    with out using the glPush/pop we get a rotation of the whole world each time we call the glrotate command, but by using the glPush/pop we select what objects we want to rotate and translate.

    example without using glpush/pop

    glRotate(15,1,0,0);
    drawcube(); drawn rotated 15 degrees

    glRotate(15,1,0,0);
    drawcube(); but this cube will be drawn with a rotation of 15 + 15 = 30 degrees

    Hope this helps...


    Originally posted by LostInTheWoods:
    I am a bit new, and a bit confussed. I am making a scene. In the scene I want a room, with about 10 independently moving objects.

    I understand if the user moves around the scene I simply load the identity matrix Rotate or translate(in the negative direction), then draw my room. Now I want to draw the objects, after they have moved.

    Should I Push the current matrix, move object one, pop the matrix, push the matrix, move object two, pop the matrix, and so on??

    Is this how its done??

  4. #4
    Senior Member Regular Contributor
    Join Date
    Nov 2000
    Location
    Huntsville, AL. USA
    Posts
    302

    Re: Push Pop matrix VS Load identity??

    Correct on all accounts ... If you didnt push and pop for every object, each successive object's position and rotation would have to be relative to the previous object.
    Obsessive - A word used by the lazy to describe the motivated.

Similar Threads

  1. loading the identity matrix after glPopMatrix
    By SaeedGH in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 09-13-2016, 05:27 AM
  2. avoid loosing Stacked Transformations on Load identity matrix
    By Phil15 in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 08-22-2015, 07:54 AM
  3. Very odd results when drawing with an identity matrix
    By chbaker0 in forum OpenGL: Basic Coding
    Replies: 8
    Last Post: 12-23-2013, 08:53 AM
  4. Load identity write it out does not work properly
    By lolzoromg in forum OpenGL: Basic Coding
    Replies: 6
    Last Post: 03-15-2012, 05:55 PM
  5. load identity after gluLookAt?
    By arthas in forum OpenGL: Basic Coding
    Replies: 10
    Last Post: 03-31-2010, 07:03 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean