BB_John

12-22-2012, 07:41 AM

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:

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:

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?

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:

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:

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?