PDA

View Full Version : Simple projection matrix question

BB_John
12-22-2012, 06: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);

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?

tonyo_au
12-22-2012, 07:12 PM
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.

Dark Photon
12-22-2012, 07:50 PM
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
(http://www.songho.ca/opengl/gl_projectionmatrix.html)
Or yeah, just use glFrustum or gluPerspective.

BB_John
12-24-2012, 07:18 AM
Thanks both of you. Now using gl_frustum but still have some wierd results. May post these here...

Dark Photon
12-27-2012, 05:37 PM
Sure thing.