Arrays of vectors, transposition, multiplication rules, and the link to linear transformations.
A matrix is a rectangular array of vectors stored in row × column format. Denoted with a bold capital letter.
An r × c matrix has r rows and c columns. The element at row i, column j is written Mᵢⱼ.
A square matrix has the same number of rows and columns. Most game-math matrices are 2×2, 3×3, or 4×4.
A diagonal matrix has non-zero values only on the main diagonal (top-left to bottom-right).
The identity matrix I is a square diagonal matrix where every diagonal value is 1. Multiplying any matrix by the identity leaves it unchanged (M·I = I·M = M):
A vector can be stored as a row vector (1×n matrix) or a column vector (n×1 matrix):
M·v). DirectX and HLSL historically use row vectors (multiply on the left: v·M). Always know which convention a codebase uses.
The transpose of matrix M (written Mᵀ) is formed by swapping its rows and columns. An r×c matrix becomes a c×r matrix.
Mᵀ = M⁻¹. This is a critical optimization in shaders — transposing is free (just swap row/column access), while full matrix inversion is expensive. The normal matrix used for transforming surface normals is the inverse-transpose of the model matrix.
Multiply every element by the scalar:
The number of columns in the first matrix must equal the rows in the second. An (r×n) matrix times an (n×c) matrix produces an (r×c) result.
Example — (3×1) × (1×3) → (3×3):
AB ≠ BA in general(AB)C = A(BC) — chaining transformations is valid(kA)B = k(AB) = A(kB)(AB)ᵀ = BᵀAᵀ — note the reversed orderEvery square matrix has a unique relationship with the basis vectors of a coordinate space. A vector v multiplied by matrix M can be interpreted as expressing v in the new coordinate system defined by the rows of M:
Each row of M is a basis vector of the output space. This is why a rotation matrix's rows (or columns, depending on convention) are always the transformed X, Y, and Z axes.
Compute AB for:
Find Mᵀ for the matrix from exercise 1 (matrix A). Verify that (AB)ᵀ = BᵀAᵀ.
Verify that A · I₂ = A for matrix A above.
Why is matrix multiplication not commutative? Give a game-dev example where order matters.
What does the transpose of a rotation matrix equal, and why is this useful in shaders?