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: Preserving the order of transformations

  1. #1
    Junior Member Newbie
    Join Date
    Jun 2003
    Posts
    8

    Preserving the order of transformations

    Hi everyone

    As you know, OpenGL reserves the order of successive transformations. For example in this code:

    glMatrixMode(GL_MODELVIEW);
    t1;
    t2;
    t3;
    DrawObject();

    The t3 affects first, then t2 and finally t1.
    How should I force OpenGL to transform in the same order that I specify in code(My transformations are affected by user input and I can't predict the next transformation). I need a more direct way than using my own stack to reversre use input.

    Thanks

  2. #2
    Advanced Member Frequent Contributor
    Join Date
    Aug 2001
    Location
    Italy
    Posts
    628

    Re: Preserving the order of transformations

    The GL will always issue transforms in the order you specify them. Where's the point?

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

    Re: Preserving the order of transformations

    It's not OpenGL specifically that "reserves the order of successive transformations."

    All OpenGL does is multiply matrices and keeps the current one. The properties of matrix math is the reason that the last one is effectively done first. If you REALLY need to change the order, you can do your own matrix math and pre-multiply new transforms instead of post-multiplying them, as OpenGL does.

    For instance pseudocode for glRotate looks something like so...

    Code :
    void glRotate(float ang, float x, float y, float z)
    {
       Matrix rot = CreateRotationMatrix(ang, x, y, z);
     
       CurrentMatrix = CurrentMatrix * rot;
    }
    If you wanted to do your own matrix stuff that does things in the reverse order, your function might look similar to so...

    Code :
    void myGlRotate(float ang, float x, float y, float z)
    {
       Matrix rot = CreateRotationMatrix(ang, x, y, z);
     
       CurrentMatrix = rot * CurrentMatrix ;
       glLoadMatrix(CurrentMatrix);
    }
    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
  •