# Thread: Simple projection matrix question

1. ## 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);

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. 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.

3. Originally Posted by BB_John
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. Thanks both of you. Now using gl_frustum but still have some wierd results. May post these here...

5. 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
•