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

Thread: Simple projection matrix question

Hybrid View

  1. #1
    Junior Member Newbie
    Join Date
    Dec 2012
    Posts
    7

    Simple projection matrix question

    Hello forum again,

    Following the homogeneous co-ordinate system, I wanted to add a simple perspective projection matrix to my OpenGL code.

    Wikipedia states that the "simplest" or "normal" perspective projection matrix is:

    Code :
    1 0 0 0
    0 1 0 0
    0 0 1 0
    0 0 1 0

    In a 4-co-ordinate system (x, y, z and w) this sets w = z so that the actual plotted points are x/z, y/z, etc.

    I'm finding that I have to use the following for anything to be drawn on the screen:

    Code :
    float m[16] = {1,0,0,0, 0,1,0,0, 0,0,1,1, 0,0,0,1};
    glMatrixMode(GL_PROJECTION);
    glLoadMatrixf(m);

    I get that the matrix might need to be a row/column transposed version (can anyone verify this?) but it doesn't explain the bottom-right corner coefficient needing to be a "1".

    Or maybe it's because this sets up w = w + z, so that dividing I get x = x / (w + z), y = y / (w + z), z = z / (w + z), i.e. rather than x = x / w, y = y / w and z = z / w where in the last case, w = z so z = z / z = 1 and therefore the depth information disappears.

    Anyone got a typical projection matrix they use or a link to a decent projection matrix tutorial. Is my understanding correct?

  2. #2
    Senior Member OpenGL Pro
    Join Date
    Jan 2012
    Location
    Australia
    Posts
    1,101
    Have a look at th glu library - it is easier than working out these matrices for yourself.

    Generally OpenGL examples are column-major matrices but it does not have to be - it all depends on what you want to do.
    Last edited by tonyo_au; 12-22-2012 at 08:24 PM.

  3. #3
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Location
    Druidia
    Posts
    3,124
    Quote Originally Posted by BB_John View Post
    Anyone got a typical projection matrix they use or a link to a decent projection matrix tutorial. Is my understanding correct?
    See the perspective matrix in the back of the Red Book, or those listed here:

    * http://www.songho.ca/opengl/gl_transform.html
    * http://www.songho.ca/opengl/gl_projectionmatrix.html

    Or yeah, just use glFrustum or gluPerspective.

  4. #4
    Junior Member Newbie
    Join Date
    Dec 2012
    Posts
    7
    Thanks both of you. Now using gl_frustum but still have some wierd results. May post these here...

  5. #5
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Location
    Druidia
    Posts
    3,124
    Sure thing.

Posting Permissions

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