Maths · function

frustumFromViewProjection

Pull the six planes out of a view-projection matrix.

Explained in Coordinates and units.

function frustumFromViewProjection<T extends FrustumPlanes>(m: ReadonlyMat4 | Float64Array, out: T): T
import { frustumFromViewProjection } from '@driftengine/core';

Parameters

ParameterTypeDescription
mReadonlyMat4 | Float64Array
outT

In depth

This is Gribb and Hartmann, and it is worth naming because it looks like a trick. A view-projection takes a world point to clip space, where being inside the frustum is -w <= x <= w and the same for y and z. Writing x >= -w as x + w >= 0 and substituting the matrix rows gives a plane equation in world coordinates directly — so the left plane is row 4 plus row 1, the right is row 4 minus row 1, and so on. No inversion, no corner extraction.

Normalising is not tidiness. Straight out of the matrix a plane's normal has an arbitrary length, so n · p + d is a distance in some unscaled clip unit. Dividing through by the normal's length makes it a distance in world units, which is the only form a radius in metres can be compared against. Skipping it produces a test that is nearly right, and wrong by a factor that changes with the field of view.

gl-matrix stores column-major, so m[column * 4 + row].