Working with the Projection Matrix
The objective of the projection matrix is to take objects from view space into projection space. Basically, this takes coordinates inside the camera’s viewing volume (specified by the shape and size of the frustum or rectangular prism) and puts them in normalized device coordinates (NDCs). The calculations for a perspective view’s projection matrix were explained in Chapter 4, Graphics and Game Engine Components. The OpenGL documentation also specifies how it constructs the projection matrix with a call to gluPerspective()
at registry.khronos.org/OpenGL-Refpages/gl2.1/xhtml/gluPerspective.xml where the mathematics is revealed. The projection matrix is defined as follows:
Here, the values of a, b, c, and d are calculated from the parameters passed to gluPerspective()
, which are the vertical field of view (fovy), the aspect ratio of the window, the near plane, and the far plane. These values are determined thus:
f = cotangent...