GraphicsBlast

Projection Matrices

This section is a work-in-progress. I will update it at some point!

A projection matrix is designed to perform a transformation such that any points within the camera's 3D view frustum are moved into the OpenGL render box of -1 to +1 in each axis. Any points outside the view frustum will be outside of the render box, and therefore not be visible.

As the camera's frustum gets wider as it gets further away, performing this transformation will necessarily make you experience parallax correctly, as things further away will occupy a smaller portion of the frustums size at that depth.

As the projection matrix performs a fixed transformation, most matrix libraries will offer a function to compute the matrix for us. There are a few parameters that we may wish to change though. Normally, the provided function will ask us for the aspect ratio of final rendered image, the field of view, and the clipping planes. The function will then plug these values in and generate our projection matrix for us.

The field of view refers to the angle that our frustum occupies. So if we are viewing the world through the scope of a rifle, a small angle will occupy the whole screen. Setting this too high will give us a fish-eye type effect.

The clipping planes are important because OpenGL will only render things between -1 and +1 in the z axis. Things too close or too far will not make the final image. The projection matrix allows us to map real distances to these OpenGL distances.

Common values for this are a minimum of 0.1 and a maximum of 100. In this scenario, things between these will lie in our box and be rendered. Anything closer than 0.1 in our world will not be - this shouldn't be zero due to how it's calculated, there must be some minimum distance. Meanwhile, anything in our world further than 100 will not be rendered.

While it might seem like an easy solution to set the far distance to perhaps 100 million so we can have very far render distances, in practice this is problematic. The buffer has a fixed precision. If you set the far clipping plane to be too big, the lack of precision will cause issues. If two objects are 0.1 distance apart, the lack of precision will mean OpenGL won't care about the order of which object to draw when the difference is so small compared to the total range. This is a computer issue, rather than an OpenGL issue. The solution is to fake it - a solution which you will see applied in the tutorials.