A game moves thousands of corners every frame, all with matrices. Watch a cube turn, move away and land on a screen.
How games move 3-D objects
Turn, move, project: three 4 × 4 matrices, one product.
A wireframe cube with corners (±1, ±1, ±1), the eye at the origin, a screen 1 unit in front of it.
Describe this picture
Two panels (stacked on a phone). On the left, a 3-D view with the eye at the origin, a screen 1 unit in front of it, and a wireframe cube with corners at . On the right, two grids of cells: the matrix being applied now, and the product of all the steps so far. In three stages: the cube turns about the vertical axis by 53.13° under ; it moves 4 units away under a move matrix with 4 in its last column; and it is projected onto the screen, every corner sliding along its ray to the eye, while , whose last row copies into the last entry, joins the product. At the end a flat panel shows the drawing on the screen, a perspective drawing with its nearer edges larger. Readouts give the step, the distance, and the drawn sizes of the nearest and farthest corners. One control after the clip: a slider for the move distance from 2 to 10; the farther the cube, the smaller its drawing.
A move is not linear, in the plane
On A gallery of linear maps, sliding the plane by failed the test of linearity, because it moves the origin and every matrix keeps the origin in place. But games and drawing programs move objects all the time, and they want to do everything with matrices, because matrices chain by multiplication.
The trick is one extra coordinate. Write the point as , its homogeneous coordinates. Now a move by is a matrix:
One dimension up, the move is a shear of space, and shears are linear. The plane just slides along inside it. Turns and scalings go in the top left corner, with a 1 in the bottom right: the turn by from A gallery of linear maps becomes , still written .
Chaining steps
Every step is now a matrix, so a chain of steps is one product, applied right to left as in Matrix multiplication. A turn about a point other than the origin takes three steps: move to the origin, turn, move back.
For a quarter turn about :
It sends to , and it leaves where it is, as a turn about that point must.
Order matters
A quarter turn about (2, 1), against a move by (2, 1) and then a quarter turn.
The same house twice, with the corner (3, 1) marked.
Describe this picture
Two panels with the same small house, its corner marked with a dot (stacked on a phone). On the left the house turns a quarter turn about the point , which is marked; the corner traces a dashed arc and lands at . Then, on the right, the house is first moved by , so the corner goes to , and then turned a quarter turn about the origin; the corner traces a long arc and lands at . A faint copy of the starting house stays in each panel. The two houses end in different places, and the end points are labelled. The clip runs for about 12 s. There is no control.
The order matters, as it did for the turn and the shear: “move, then turn” is not “turn, then move”.
Perspective
In 3-D a point is and every step is . A camera at the origin looking along the axis draws a point at on a screen at distance 1: things twice as far look half as big. Division is not a matrix, but it can be left to the end. Use
which sends to : it copies the depth into the last entry. Then divide by that last entry. Graphics cards work this way: multiply, then divide once per corner.
A vector whose last entry is 0 is a direction, not a place. Moves don’t change it: . That is right, since moving an object doesn’t change which way it points.
Worked example
1. Turn about a point. With a quarter turn, : ; then gives above. Check: .
2. The other order. Move by , then turn about the origin: , which sends to .
3. The cube, unturned. Moved 4 units away, its front face has corners and its back face . On the screen they land at and : two nested squares, the front one larger in the ratio .
4. The cube, turned. The turn by 53.13° (0.9273 rad, the 3-4-5 angle) followed by the move is one matrix:
The corner goes to and appears on the screen at . The corner goes to and appears at .
Try these before you read the answers.
- Is “turn, then move” the same as “move, then turn”? No.
- Where does land on the screen at distance 1? .
- Move the cube twice as far away. How big is its drawing? About half as big.
In signal processing · the bilinear transform
IIR design by the bilinear transform, in the signal processing course, maps to , up to a constant factor. That is a homogeneous-coordinate trick in one complex dimension: the matrix acts on , then divide the first entry by the second. For it gives , and . Composing two such maps multiplies their matrices.
Where you’ll meet this
Every graphics card. A card draws a triangle by multiplying its corners by three matrices: the model’s place in the world, the camera’s view, and the perspective. A game multiplies the three once per object per frame, and then each corner costs one product.
Robot arms. Each joint of an arm turns and offsets the next link, one matrix per joint. The hand’s position is the product of the chain.
Augmented reality. To draw a virtual object on a live camera view, a phone estimates the camera’s matrix from the picture, many times a second.
Reference card
| Quantity | Formula | Notes |
|---|---|---|
| Homogeneous point | one extra coordinate | |
| Move | , in the last column | a shear one dimension up |
| Turn | in the top-left corner | 1 in the bottom right |
| Chain | product of the steps, right to left | order matters |
| Turn about a point | move there, turn, move back | |
| Perspective | , then divide | screen point |
| Direction | last entry 0 | moves leave it unchanged |