Model Matrix: Transformations - A Change-of-Coordinates Perspective
The model matrix is a fundamental transformation in computer graphics that converts local object coordinates to world space. We examine the mathematical foundations of model matrices through the lens of change-of-coordinates transformations, with particular focus on rotational components. We demonstrate that rotation transformations can be conceptualized in two equivalent ways: As direct matrix operations on basis vectors, or as coordinate system changes between orthonormal bases.
Introductionโ
A model matrix describes the size, position, and orientation of an object relative to world coordinates [๐VB15, 139]. It can be understood as a change-of-coordinates matrix that transforms local coordinates relative to a local basis into world coordinates with basis .
In the following, we will elaborate on the relationship between the rotational component of the model matrix and change-of-coordinates matrices. We assume that the basis shares the same origin as . If this is not the case, an additional translation must be applied, which is omitted below for the sake of simplicity.
A model matrix can be understood as a change-of-coordinates matrix:
Since we choose the world basis as the standard basis , we can simply write the columns as the corresponding world coordinates:
This allows us to express any local vector in world coordinates:
If we want to rotate the model - and thus all coordinates expressed relative to it - we use a rotation matrix (relative to world coordinates). When multiplied by a vector , we thus obtain a rotated vector
Likewise, the rotation can be applied to the basis vectors of the model matrix, thereby rotating the entire model basis - and thus the model:
Due to linearity (acting column-wise), this results in the shorthand notation:
For the transformation of a vector into world coordinates, the following holds:
This derivation shows an important point that is commonly seen in various software libraries for matrix multiplication (e.g. glm):
- the model matrix is rotated first, and then the vector is transformed
- the vector is transformed first, and then rotated.
Due to the associativity of matrix multiplication, both approaches are equivalent and lead to the same result.
Passive Rotation and the Composition of Transformationsโ
Alternatively, the rotation can also be understood as a change of basis. If contains the orthonormal basis vectors as its columns, then the following holds:
and