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 4 of 4

Thread: matrices

  1. #1
    Intern Newbie
    Join Date
    Mar 2003
    Posts
    31

    matrices

    i was doing some of the nehe tutorials, and then i also found out about the gametutorials.com ones..right off the starts, in the GT.com ones, Digiben uses matrix functions (glPush and glPop)..i didn't know about them before..and i was wondering what was the advantage of using different matrices that way over just doing it the way tis done at nehe in the beginning
    thanks

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

    Re: matrices

    Once you get to the more advance stuff, nehe starts to use them also.

    The camera in openGL does not move, you move everything around it to make it look like it is moving.

    in a scene you will define camera movement before drawing with gluLookAt or just a bunch of rotate and translate commands.

    Now when we rotate/translate we are changing the matrix, but we don't want to have rotating or translating an object to effect our camera settings.


    // Scene draw
    // Set camera

    My_camera_routine();

    // Draw first object
    glPushMatrix() // We save current matrix state, which holds our camera rotations and translations

    glTranslatef // Matrix is altered
    glRotatef // Matrix is altered

    Draw_object(); // Draw object with camera and new matrix changes.
    glPopMatrix(); // We have finish drawing our object, return matrix camera settings.

    We repeat this for each object.

    Hope this helps


    Originally posted by paneb:
    i was doing some of the nehe tutorials, and then i also found out about the gametutorials.com ones..right off the starts, in the GT.com ones, Digiben uses matrix functions (glPush and glPop)..i didn't know about them before..and i was wondering what was the advantage of using different matrices that way over just doing it the way tis done at nehe in the beginning
    thanks

  3. #3
    Intern Newbie
    Join Date
    Mar 2003
    Posts
    31

    Re: matrices

    so i dont really need to use it for simple stuff such as creating a cube with textures or the like..
    anyways, i kinda get it now ..
    thanks nexusone

  4. #4
    Senior Member OpenGL Pro
    Join Date
    Oct 2000
    Location
    Fargo, ND
    Posts
    1,797

    Re: matrices

    It's also useful for doing hierarchical transformations. Usually I use a solar system example. This time I'll try to be different and use an arm example, complete with fingers.

    Code :
    glPushMatrix()
    DoUpperArmTransformations();
    DrawUpperArm();
    glPushMatrix();
    DoLowerArmTransformations();
    DrawLowerArm();
    glPushMatrix();
    DoHandTransformations();
    DrawHand();
    for(int c=0;c<5;c++)
    {
       glPushMatrix();
       DoFingerTransformations(c);
       DrawFinger(c);
       glPopMatrix();  // Pop finger transformations
    }
    glPopMatrix(); // Pop hand transformations
    glPopMatrix(); // Pop lower arm transformations
    glPopMatrix(); // Pop upper arm transformations
    With the above code, each of the sections of transformations only have to do their transformations in relation to their parent object. Because of the way I set it up, it will then also be multiplied by the parent objects transformations.

    Technically, I gues I didn't need to do the push/pop around the lower arm and hand in the above code, so maybe the solar system would have been a better example since you can have multiple planets with multiple satelites. Hopefully you get the idea, though.
    Deiussum
    Software Engineer and OpenGL enthusiast

Posting Permissions

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