Game Development Reference
Understanding the basics of a camera
In order to visualize objects in our scene, a camera is required. The mathematics
involved in camera control and movement can be quite confusing, so we'll explore
it more in-depth towards the end of this chapter. For now, we will simply discuss a
An essential concept in 3D rendering is the transformation matrix, and the most im-
portant of which, that are used time and time again, are the view and projection
matrices. The view matrix represents the camera's position/rotation in space, and
where it's facing, while the projection matrix represents the camera's aspect ratio
and bounds (also known as the camera's frustum ), and how the scene is stretched/
warped to give an appearance of depth (which we call perspective).
One of the most important properties of matrices is being able to combine two
matrices together, through a simple matrix multiplication, and resulting in a trans-
formation matrix that represents both. This property massively cuts down the amount
of mathematics that needs to be performed every time we render the scene.
In OpenGL, we must select the matrix we wish to modify with glMatrixMode() .
From that point onwards, or until glMatrixMode() is called again, any matrix-
modifying commands will affect the selected matrix. We will be using this command
to select the projection ( GL_PROJECTION ) and view ( GL_MODELVIEW ) matrices.
The glIdentity function sets the currently selected matrix to the identity matrix,
which is effectively the matrix equivalent of the number one. The identity matrix is
most often used to initialize a matrix to a default value before calling future functions
described in the following sections.
The glFrustum function multiplies the currently selected matrix by a projection mat-
rix defined by the parameters fed into it. This generates our perspective effect (men-
tioned previously), and when applied, creates the illusion of depth. It accepts six val-
ues describing the left, right, bottom, top, near, and far clipping planes of the cam-
era's frustum: essentially the six sides of a 3D trapezoid (or trapezoidal prism in tech-