Training Computer Graphics & Gaming 3D Worlds — Matrices Behind Every Pixel
1 / 1

3D Worlds — Matrices Behind Every Pixel

20 min Computer Graphics & Gaming

3D Computer Graphics

Every 3D video game, Pixar movie, and architectural visualization is powered by linear algebra. When you move through a game world, your GPU is multiplying millions of matrices per second.

Matrices Move the World

Every object in a 3D scene is made of triangles, and every triangle is made of three points (vertices). To move, rotate, or scale an object, you multiply each vertex by a transformation matrix.

3D Transformation Matrices

Translation (move):

$$T = \begin{pmatrix} 1 & 0 & 0 & t_x \\ 0 & 1 & 0 & t_y \\ 0 & 0 & 1 & t_z \\ 0 & 0 & 0 & 1 \end{pmatrix}$$

Rotation around Z-axis (uses trig!):

$$R_z = \begin{pmatrix} \cos\theta & -\sin\theta & 0 & 0 \\ \sin\theta & \cos\theta & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 1 \end{pmatrix}$$

Scaling:

$$S = \begin{pmatrix} s_x & 0 & 0 & 0 \\ 0 & s_y & 0 & 0 \\ 0 & 0 & s_z & 0 \\ 0 & 0 & 0 & 1 \end{pmatrix}$$

Notice: rotation uses sine and cosine — the same trig functions from your math class. Every time a character turns in a game, $\sin\theta$ and $\cos\theta$ are calculated.

Example

Rotate the point $(3, 4, 0)$ by $90°$ around the Z-axis.

$\cos 90° = 0$, $\sin 90° = 1$:

$$\begin{pmatrix} 0 & -1 & 0 \\ 1 & 0 & 0 \\ 0 & 0 & 1 \end{pmatrix} \begin{pmatrix} 3 \\ 4 \\ 0 \end{pmatrix} = \begin{pmatrix} 0(3) + (-1)(4) \\ 1(3) + 0(4) \\ 0 \end{pmatrix} = \begin{pmatrix} -4 \\ 3 \\ 0 \end{pmatrix}$$

The point moved from $(3, 4)$ to $(-4, 3)$ — a perfect 90° rotation. Matrix multiplication and trig made it happen.

Lighting — The Dot Product

How bright a surface appears depends on the angle between the surface and the light source. This is calculated with the dot product:

$$\text{brightness} = \max(0,\; \mathbf{n} \cdot \mathbf{l}) = \max(0,\; n_x l_x + n_y l_y + n_z l_z)$$

where $\mathbf{n}$ is the surface normal and $\mathbf{l}$ is the light direction. This is multiplication and addition — applied billions of times per second.

The Numbers

What HappensMath UsedTimes Per Frame
Transform verticesMatrix × vector~10 million
Calculate lightingDot products~50 million
Texture mappingInterpolation (linear algebra)~2 billion
Perspective projectionMatrix division~10 million

At 60 frames per second, your GPU does this 60 times every second.

Key Insight

Every frame of every game is millions of matrix multiplications, dot products, and trig evaluations. When you learn linear algebra and trigonometry, you're learning the language of computer graphics.

Interactive Explorer: 2D Rotation
Original Point: (3, 4)
Rotated Point: (-4, 3)
cos θ = 0.000 sin θ = 1.000