3D Math for Games

Games use math to display graphics. Games are computational media and I will be exploring how video game engines build the graphics through computations. In Game Engine Architecture by Jason Gregory, Chapter 5 starts to break this all down. Specifically, in sections 5.1 and 5.2, Gregory talks about points, vectors, and different coordinate systems, which are key to building and understanding 3D worlds.

What are Points & Vectors?

The majority of 3D games are made up of 3-dimensional objects. These objects are built from points and 3D vectors. Gregory describes them like this:

“A point is a location in n-dimensional space.
In most games, we deal with 2D or 3D space, so a point might look like (x, y) or (x, y, z).”

“A vector is a quantity that has both a magnitude and a direction in n-dimensional space.” (Gregory)

P1 is a point. P1-P2 is a vector.

To use points and vectors, we need a frame of reference. That’s where coordinate systems come in.

The most common one is the Cartesian coordinate system. This is the most common 3D coordinate system that uses X, Y, and Z axes. Although depending on the situation, cylindrical and spherical coordinate systems might be used.

Cylindrical coordinate system

Spherical Coordinate System

For example, Gregory describes using cylindrical coordinates in a game called Crank the Weasel. In one scene, the character collects loot that floats inward in a spiral. Instead of using regular (x, y, z) math, he used angular and radial values:

“I simply gave the loot a constant angular speed in θ, a small constant linear speed inward along its radial axis r… This extremely simple animation looked great, and it was much easier to model using cylindrical coordinates.” (Gregory)

Crank the Weasel

Working with Vectors

With vectors, you can scale, add, subtract and multiply.One simple example Gregory gives is multiplying a vector by a scalar (just a number). If a vector is like an arrow, multiplying it by 2 makes the arrow twice as long.

“Multiplication of a vector by a scalar s is accomplished by multiplying the individual components of a by s:
sa = (s·aₓ, s·aᵧ, s·a𝓏).”

You can also break vectors into pieces using unit vectors (called i, j, and k). These are the basic directions in the x, y, and z axes. So a vector like (5, 3, -2) becomes:

5i + 3j − 2k

This form is super helpful in physics, motion, and animation because it tells you exactly how much movement is happening in each direction.

andrei.obreja2007@gmail.com

Seattle, Washington