Change of Coordinates and Applications to View Matrices
This article introduces the mathematical derivation of the lookAt view matrix commonly used in computer graphics APIs like OpenGL.
As part of the graphics pipeline, the purpose of this matrix is to perform the view transformation, converting global world coordinates into a coordinate system defined by position and direction of an observer.
The derivation is built from from fundamental linear algebra principles, beginning with the interpretation of the matrix-vector product as projections onto an orthonormal basis. This leads to formal treatment of coordinate system changes using change-of-coordinates matrices. By applying these concepts, we construct a final matrix, revealing the precise geometric meaning of both its rotational as well as translational components.
Introduction
This article introduces the derivation of the lookAt matrix in OpenGL, which is a -transformation matrix of the form
Here, denotes a change-of-coordinates matrix. While is often referred to as a translation vector - that is, a displacement vector - we will later see in the view matrix that this displacement also involves rotation.
The purpose of the lookAt-matrix is to transform coordinates from world space to camera space, effectively re-expressing world coordinates relative to the camera's point of view:
We begin by examining the structure of matrix-vector products, where the matrix rows are interpreted as the vectors of an orthonormal basis1 in .
Next, we introduce the concept of coordinate vectors and explain how change-of-coordinates matrices are used to map vectors from one coordinate system into another coordinate system .
Building on these concepts, we conclude by deriving the explicit form of the lookAt matrix to map coordinates between and .
To complement the theoretical derivation, we provide an interactive application as a hands-on experience, enabling readers to visualize the effects of these transformations in real-time.
Projections and Matrix-Vector Products
Let be the orthonormal vectors of the standard basis in
Let be an arbitrary vector in .
We can write as the matrix-vector product , where is a matrix whose rows represent the vectors . Since , it immediately follows that .
The resulting components represent the scalar projections of onto the axes of the standard basis.
Since is a normalized vector, multiplying with yields the parallel component of the orthogonal projection of onto .
These projections can then be used to reconstruct as a linear combination of the basis vectors , e.g. for :