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 pageshowhide
explore
- Vector Algebra6 questions
- Matrices and Transformations6 questions
- Rotations and Quaternions6 questions
- Coordinate Spaces and Projection5 questions
- Interpolation and Splines6 questions
- Geometric Queries and Intersection6 questions
- Floating-Point Robustness5 questions
- Randomness and Noise5 questions
questions
page 2 of 2How do you project a vector onto an axis and reject it from that axis, and how does a turret use both to aim?
basics
~20 sProjecting 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.
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?
basics
~20 sSimilar 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.
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?
basics
~20 sProject 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.
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?
basics
~20 sWith 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.
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?
basics
~20 sThe 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.
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?
basics
~10 sNon-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.
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?
basics
~20 sSingle-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.
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?
basics
~20 sSuspect 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.
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?
basics
~20 sA 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.
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?
basics
~20 sEvery 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.
How do you build the shortest-arc quaternion that rotates one unit direction onto another, and what breaks when the two directions are opposite?
basics
~20 sFor 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.
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?
basics
~20 sDirectly 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.
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?
basics
~20 sSeparate 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.
Should a cross-platform deterministic lockstep game simulate in fixed-point arithmetic or in tightly controlled IEEE floats, and what decides it?
basics
~20 sFixed 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.
As engine lead, which rotation representation would you standardise for authored data, runtime orientation and save files, and where should conversions between them happen?
basics
~20 sUsually 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.
showing 31–45 of 45