skip to content

Game Mathematics

Vectors, matrices, quaternions, projection, splines, intersection tests, float traps and noise. Interviewers use it to find who can derive a transform rather than only call an engine function.

on this pageshow

explore

questions

page 2 of 2

How do you project a vector onto an axis and reject it from that axis, and how does a turret use both to aim?

level: middleimportance: should knowfreq 55%

basics

~20 s

Projecting v onto unit axis a gives dot(v, a)*a; rejecting gives the perpendicular rest, v - dot(v, a)*a. A turret rejects the up part of its target offset to aim its base, and pitches its barrel from the two parts' lengths.

open as a page

How do you derive a perspective projection matrix from vertical field of view, aspect ratio and near and far planes, and how does orthographic differ?

level: seniorimportance: should knowfreq 40%

basics

~20 s

Similar triangles give x / -z, scaled by 1 / tan(fovY / 2) over aspect; the matrix stores -z in w so the perspective divide does it, and two constants map near and far to the NDC depth limits. Orthographic keeps w at 1.

open as a page

How do you find the closest point on a triangle to a given point, and why is projecting onto its plane and clamping barycentric coordinates wrong?

level: seniorimportance: should knowfreq 35%

basics

~20 s

Project the point onto the triangle's plane; if its barycentrics are all non-negative, that is the answer. Otherwise the closest point lies on an edge or vertex: test Voronoi regions or take the nearest clamped edge point. Clamping barycentrics picks a wrong point.

open as a page

Why can a slab-method ray-versus-AABB test hit or miss crates inconsistently when a y-up top-down shooter fires bullet rays whose y component is exactly zero, and how do you fix it?

level: seniorimportance: should knowfreq 40%

basics

~20 s

With d.y = 0, the slab terms (bmin.y - o.y) / d.y become infinities, which work, until o.y lies exactly on a box face: 0 * infinity is NaN, and how min, max and comparisons treat NaN decides hit or miss. Handle parallel axes explicitly.

open as a page

A cinematic camera following a spline through waypoints by advancing t at a constant rate speeds up and slows down; why, and how do you make it move at constant speed?

level: seniorimportance: should knowfreq 40%

basics

~20 s

The parameter t is not distance: the curve's speed |P'(t)| varies within a segment, and equal t per segment gives long segments more distance per second. Build an arc-length table, then map distance travelled back to t each frame.

open as a page

A statue scaled non-uniformly has lighting normals tilted the wrong way; why does transforming normals by the model matrix fail, and what fixes it?

level: seniorimportance: should knowfreq 56%

basics

~10 s

Non-uniform scale stretches the surface so a normal pushed through the model matrix is no longer perpendicular to it. Transform normals with the inverse-transpose of the model matrix's upper-left 3x3 block, then renormalise.

open as a page

In an open-world game, why does the player's character model visibly shake 20 kilometres from the world origin, and how does origin rebasing fix it?

level: seniorimportance: should knowfreq 46%

basics

~20 s

Single-precision positions near 20,000 m snap to a grid about 2 mm wide, so vertices, bones and contacts jump between grid points. Origin rebasing periodically shifts the whole world so the player stays near zero, where the grid is fine.

open as a page

Which floating-point sources of non-determinism would you suspect when a lockstep strategy game's two clients drift apart after ten minutes despite identical inputs?

level: seniorimportance: should knowfreq 36%

basics

~20 s

Suspect anything that changes a last bit: a different operation order, fused multiply-add on one build, fast-math compiler flags, differing sin and cos implementations, and a changed rounding or denormal mode. Per-tick state hashes locate the first divergent tick.

open as a page

Players of a roguelike share a run seed, yet the same seed gives different loot on some machines; how do you find and fix the divergence?

level: seniorimportance: should knowfreq 36%

basics

~20 s

A seed replays only when every gameplay draw happens in the same order with the same algorithm. Log draws on both machines and diff for the first mismatch, then give gameplay its own codebase-owned generator streams that cosmetic, frame-rate or thread-order draws never touch.

open as a page

A turret slerps toward its target and sometimes swings almost 360 degrees the long way round; how do quaternion double cover and a dot-product check explain and fix it?

level: seniorimportance: should knowfreq 58%

basics

~20 s

Every rotation has two unit quaternions, q and -q. When the turret's current and target quaternions have a negative dot product, slerp takes the arc of more than 180 degrees; negating the target first restores the short turn.

open as a page

How do you build the shortest-arc quaternion that rotates one unit direction onto another, and what breaks when the two directions are opposite?

level: seniorimportance: should knowfreq 42%

basics

~20 s

For unit directions a and b, normalising the quaternion (1 + dot(a, b), cross(a, b)) gives the shortest-arc rotation; when a and b are opposite both parts vanish, so pick any axis perpendicular to a and rotate 180 degrees.

open as a page

A sentry turret vanishes from the screen whenever the player jumps onto its top; how can normalizing a vector cause that, and how do you guard against it?

level: seniorimportance: should knowfreq 50%

basics

~20 s

Directly above the turret, the horizontal aim offset is zero, and normalizing it divides 0 by 0, giving NaN components that poison the turret's orientation and transform, so it typically disappears. Guard with a squared-length check and a fallback direction.

open as a page

Your engine's math library, asset exporters and shaders keep disagreeing about matrices; what matrix-convention standard would you set for the team, and how would you enforce it?

level: principalimportance: should knowfreq 30%

basics

~20 s

Separate two choices — which side the vector multiplies on, and how the 16 floats sit in memory — pick one of each, document them, and enforce them with types, named accessors, boundary conversions and golden tests.

open as a page

Should a cross-platform deterministic lockstep game simulate in fixed-point arithmetic or in tightly controlled IEEE floats, and what decides it?

level: principalimportance: should knowfreq 30%

basics

~20 s

Fixed point makes cross-platform determinism a property of integer arithmetic, at the cost of range limits, overflow care and hand-written math; controlled floats keep speed and familiar tooling but need strict flags, own transcendentals and cross-platform tests. The platform spread usually decides.

open as a page

As engine lead, which rotation representation would you standardise for authored data, runtime orientation and save files, and where should conversions between them happen?

level: principalimportance: should knowfreq 30%

basics

~20 s

Usually unit quaternions for runtime orientation and saves, Euler angles with a documented order only where people author or clamp angles, and matrices derived on demand; conversions happen once, at named boundaries, never as a per-frame round trip.

open as a page

showing 31–45 of 45