I notice some problem:

Solving the computation with your parameter you get this matrix:

```
400 0 (0)/(r-l) 0
0 400 (0)/(t-b) 0
0 0 (0)/(f-n) -160000
0 0 -1 0
```

… so when you multiply your camera space vertex you don’t have any Z transformation (all Z are flattened to -1) and no screen ratio preservation. :-

Both your parameter and computation are wrong.

this article explain very well the prospective matrix:

http://www.cs.kuleuven.ac.be/cwis/research/graphics/INFOTEC/viewing-in-3d/node8.html

Basically you want a matrix that take coordinates in camera space and transform them in a -1.0 < p < 1.0 cube in homogeneous coord.

The first row should take the X coord and based on your (X)FOV should scale it.

Should be something like that

```
2*near/(right-left) 0 0 0
```

the right and left value are referred to how wide is your near plane. a Near plane of 800 is HUGE.

The other number should be 0 cause I don’t wont the X to be modified by the Y o Z (or even W) coord.

You can say… wait… I want my X to become smaller when the Z became bigger to have a prospective.

No, cause the normalization pass should take care of this.

The second row is like the first, but now we are working on the Y. Nothing new…

```
0 2*near/(top-bottom) 0 0
```

Now let’s take care of the Z.

You want the z that stay on the near plane to become -1.0 and the z that stay on the far plane to become 1.0

That easy…

```
0 0 (far+near)/(far-near) -2.0 * far* near /(far-near)
```

Now if I have a vertex in (0.0, 0.0, near) it will became

0*0 + 0*0 + near *(far+near) / (far-near) + 1 * (-2.0 * far* near /(far-near))=

near * (far-near) / (far-near) = near

Wow… It don’t work, we still need to add something.

Of course!! The normalization…

After this pass the coordinates are divided by W so we need a W that is -Z.

Here it is, the last row is

```
0 0 -1 0
```

now we have a matrix like this:

```
2*near/(right-left) 0 0 0
0 2*near/(top-bottom) 0 0
0 0 (far+near)/(far-near) -2.0 * far* near /(far-near)
0 0 -1 0
```

And now my vertex in (0, 0, near, 1) will go in (0.0, 0.0, -1.0)

and my vertex in (0, 0, far, 1) will go in (0.0, 0.0, 1.0).

The computation is correct but the parameter are not very intuitive… and here it come the glutPerspective.

glutPerspective compute the right parameter based on the (Y)fov and the screen ratio.

Hope this’ll help.