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

Thread: Projection matrix

  1. #1
    Guest

    Projection matrix

    I tried something funny.. I took the definition of the orthographic projection(from the red book) and loaded up a calculated matrix as the projection matrix.

    Though it didn't give the same result as using built in methods.. i had to multiply a translation to the calculated orthographic projection matrix because the coords 0,0 was lower right coordinates... yepp RIGHT =D

    Now i wonder if someone tried this out, is there some matematical stuff going on that isn't specified in the docs. Seems a bit odd that i had multiply by a translation matrix to get the same results as the built in glOrtho.

  2. #2
    Member Regular Contributor
    Join Date
    Oct 2001
    Location
    Princeton, NJ
    Posts
    386

    Re: Projection matrix

    could be because opengl orders the matrices differently than normal math, try using the transpose of your original matrix

  3. #3
    Advanced Member Frequent Contributor
    Join Date
    Oct 2001
    Posts
    596

    Re: Projection matrix

    Well, transltion is like moving the camera nearer.. to simulate Zoom , just narrow the FOV, that is exactly what realworld cameras does.

  4. #4
    Guest

    Re: Projection matrix

    well the matrix is the way opengl wants it, it column ordered in a array(0-3 first column etc..)

    The code currently looks like(matrix are a GLfloat matrix[16]

    void M4x4::LoadOrtho(float Left, float Right, float Bottom, float Top, float Near, float Far)
    {
    matrix[0] = 2.0f / (Right - Left);
    matrix[1] = 0.0f ;
    matrix[2] = 0.0f ;
    matrix[3] = 0.0f ;

    matrix[4] = 0.0f ;
    matrix[5] = 2.0f / ( Top-Bottom ) ;
    matrix[6] = 0.0f ;
    matrix[7] = 0.0f ;

    matrix[8] = 0.0f ;
    matrix[9] = 0.0f ;
    matrix[10] = -2.0f / (Far - Near);
    matrix[11] = 0.0f ;

    matrix[12] = (Right + Left) / (Right - Left) ;
    matrix[13] = (Top + Bottom) / (Top - Bottom) ;
    matrix[14] = (Far + Near) / (Far - Near) ;
    matrix[15] = 1.0f ;
    M4x4 tmp;
    tmp.LoadTranslation(Left-Right,Top-Bottom,0);
    *this = (*this)*tmp;
    }

    you also see the LoadTranslation method(pasted below), which is
    the current test work around to transpose the scene origin just tested at my perticular case.

    Now the entire scene is reseted and world,texture and projection matrix is set to identity before i do any operations.

    glMatrixMode(GL_PROJECTION);


    M4x4 projection
    projection.LoadOrtho(0,287,255,0,-1,1);
    glLoadMatrixf(projection.matrix);

    Now the above code vill produce the same

    result as: gluOrtho2D(0,287,255,0);

    But only if i keep the translation matrix in the LoadOrtho method(otherwise the scene will have 0,0 in lower right).

    I can't see anything differing from the redbooks definition of the orthomatrix, soo I believe it should yield the same result without the translation but it doesn't.

    ---

    void M4x4::LoadTranslation(float Tx, float Ty, float Tz)
    {
    LoadIdentity();
    matrix[12] = Tx;
    matrix[13] = Ty;
    matrix[14] = Tz;
    }

  5. #5
    Junior Member Regular Contributor
    Join Date
    Dec 2001
    Location
    Belmont, CA, USA
    Posts
    216

    Re: Projection matrix

    Originally posted by Some Bozo:

    matrix[12] = (Right + Left) / (Right - Left) ;
    matrix[13] = (Top + Bottom) / (Top - Bottom) ;
    matrix[14] = (Far + Near) / (Far - Near) ;
    It's hard to read in the book -- look closely, these terms should be negated.

  6. #6
    Guest

    Re: Projection matrix

    Yep, that did indeed work =) thanks!

    no matter what zoom level i used in the pdf file i couldn't find the sign though, but it now i know, thanks again =D

Posting Permissions

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