Core Concepts of Box2D
mainBox2D is a 2D rigid body simulation library written in portable C17. It uses several fundamental objects to simulate physics:
- Rigid Body (Body): A chunk of matter with constant internal distances. It has 3 degrees of freedom (two translation, one rotation).
- Shape: Binds collision geometry to a body and defines material properties like
density,friction, andrestitution. Shapes are used by the broad-phase collision system. - Constraint: A physical connection that removes degrees of freedom from bodies.
- Contact Constraint: Automatically created by Box2D to prevent penetration and simulate friction/restitution.
- Joint Constraint: Used to hold bodies together (e.g.,
revolute,prismatic,distance). Joints can includelimits,motors, andsprings.
- World: A collection of bodies, shapes, joints, and contacts. Multiple independent worlds can exist simultaneously.
- Solver: A high-performance sequential solver that advances time and resolves constraints in $O(N)$ time, where $N$ is the number of constraints.
- Continuous Collision: Algorithms (Time of Impact interpolation and speculative collision) used to prevent 'tunneling' (objects passing through each other during discrete time steps).