Skip to main content

Module constraints

Module constraints 

Source
Expand description

XPBD + Sequential-Impulse constraint solver for 2D/3D rigid bodies.

Implements both:

  • Sequential Impulse (SI) solver — velocity-level constraint resolution following Erin Catto / Box2D style iterative impulses.
  • Extended Position-Based Dynamics (XPBD) — position-level constraints with compliance, substep integration, and constraint islands.

§Constraint types

  • ContactConstraint — normal + friction, restitution, Baumgarte, warm-start
  • DistanceConstraint — rigid rod (exact) and soft spring (compliance)
  • HingeConstraint — single-axis rotation with limits and motor
  • BallSocketConstraint — 3-DOF free rotation with cone limit
  • SliderConstraint — prismatic joint with translation limits and motor
  • WeldConstraint — fully rigid 6-DOF lock
  • PulleyConstraint — two bodies through a fixed pulley ratio
  • MotorConstraint — angular velocity drive
  • MaxDistanceConstraint — soft rope
  • GearConstraint — ratio-based angular coupling

Structs§

BallSocketConstraint
Ball-and-socket joint: 3-DOF rotation, fixed relative position. Optionally limits the cone angle between the two body Z-axes.
BodyHandle
Reference to a rigid body in the solver.
BodyState
Minimal state the solver needs from a rigid body.
ConstraintId
ConstraintIsland
A group of bodies and constraints that are connected and should be solved together.
ConstraintSolver
Sequential-impulse + XPBD constraint solver.
ConstraintWorld
Manages all bodies and constraints in one place.
ContactConstraint
Contact constraint: normal impulse (non-penetration) + friction impulse.
DistanceConstraint
Maintain a fixed distance between two local anchor points on two bodies. With compliance = 0 this is a rigid rod; compliance > 0 gives spring behavior.
GearConstraint
Couple the angular velocities of two bodies: omega_a + ratio * omega_b = 0.
HingeConstraint
Hinge (revolute) joint: two bodies share a common anchor. Allows rotation around the Z-axis. Supports angular limits and a velocity motor.
MaxDistanceConstraint
Soft rope: only constrains when distance exceeds max_distance.
MotorConstraint
Drive a body at a target angular velocity. Acts as a torque motor.
PinConstraint
Pin a body’s local anchor to a fixed world-space point.
PulleyConstraint
Pulley constraint: body_a and body_b are connected via a rope over two fixed pulley points. Maintains: len_a + ratio * len_b = constant.
SliderConstraint
Prismatic (slider) joint: allows translation along one axis only. Supports translation limits and a linear motor.
SpringConstraint
A spring-damper between two anchor points (Hooke’s law).
WeldConstraint
Weld joint: fully rigid 6-DOF lock. Fixes both relative position and angle.

Constants§

WORLD
Sentinel for world-space anchors (infinite mass, immovable).

Traits§

Constraint
A constraint imposes a restriction on body state.

Functions§

cross2
2D cross product (scalar result): a.xb.y - a.yb.x
detect_islands
Detect constraint islands using union-find.
perp
Perpendicular of a 2D vector: (-y, x)
rotate2
Rotate a Vec2 by angle theta.