Manual 04 · contact
Collision Manifolds
Broadphase to narrowphase, and the compact contact manifold — points, normal, penetration — that the solver consumes.
Contact detection runs in two passes. Broadphase cheaply rejects pairs that cannot possibly touch; narrowphase takes the survivors and produces the exact geometry of each overlap. That geometry is a manifold, and it is the only thing the solver ever sees.
Broadphase
flint sorts body bounds along an axis and sweeps, reporting overlapping intervals — sweep-and-prune. It is O(n log n) on the sort and near-linear on the sweep for the coherent, mostly-still scenes games produce. The output is a list of candidate pairs, deterministically ordered by BodyId, because a stable pair order is a prerequisite for a stable solve.
Narrowphase and the manifold
For each candidate pair, narrowphase runs the separating-axis test for polygons and analytic tests for circles and capsules. When shapes overlap it emits a Manifold:
pub struct Contact {
pub point: Vec2, // world-space contact position
pub penetration: f32, // overlap depth along the normal, >= 0
pub normal_impulse: f32, // cached for warm starting next frame
pub tangent_impulse: f32,
}
pub struct Manifold {
pub a: BodyId,
pub b: BodyId,
pub normal: Vec2, // unit vector, points from A toward B
pub contacts: [Contact; 2],
pub count: u8, // 1 for point contact, 2 for an edge
}
Two points are enough to describe any planar contact between convex shapes, so contacts is a fixed array — no allocation, no per-frame growth. A box on the ground yields count = 2; a circle on the ground yields count = 1.
Persistence
Manifolds are matched across frames by their (a, b) pair and their contact identifiers. When a contact persists, its normal_impulse and tangent_impulse carry over. That cached impulse is the seed the solver warm-starts from in the next chapter — the single most important trick for making stacks converge in a handful of iterations.