# Projection matrices

The projection matrix is used to project all points from the bounded volume onto a plane.

There are two types of projection: perspective and orthogonal. In perspective projection far objects look smaller, and nearby objects larger.

One way to bound volume is to use six planes:

- r - the right plane
- l - the left plane
- t - the top plane
- b - the bottom plane
- f - the far plane
- n - the near plane to which we will project

**perspective projection**
| 2*n/(r-l) 0 (r+l)/(r-l) 0 |
| 0 2*n/(t-b) (t+b)/(t-b) 0 |
| 0 0 (f+n)/(n-f) -2*f*n/(f-n)|
| 0 0 -1 0 |

**orthogonal projection**
| 2/(r-l) 0 0 (r+l)/(r-l)|
| 0 2/(t-b) 0 (t+b)/(t-b)|
| 0 0 -2*f/(f-n) (f+n)/(f-n)|
| 0 0 0 1 |

Other way to bound volume is to use near/far planes and vertical field of view:

- n - the near plane to which we will project
- f - the far plane
- ar - the ratio between the width and the height of the rectangular area which will be the target of projection
- α - vertical field of view (FOVy on image), the vertical angle of the camera through which we are looking at the world

In this case, the matrix will look like this

**perspective projection**
| 1/(ar*tan(α/2)) 0 0 0 |
| 0 1/tan(α/2) 0 0 |
| 0 0 (-n-f)/(n-f) -2*f*n/(n-f)|
| 0 0 1 0 |