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-startDistanceConstraint— rigid rod (exact) and soft spring (compliance)HingeConstraint— single-axis rotation with limits and motorBallSocketConstraint— 3-DOF free rotation with cone limitSliderConstraint— prismatic joint with translation limits and motorWeldConstraint— fully rigid 6-DOF lockPulleyConstraint— two bodies through a fixed pulley ratioMotorConstraint— angular velocity driveMaxDistanceConstraint— soft ropeGearConstraint— ratio-based angular coupling
Structs§
- Ball
Socket Constraint - Ball-and-socket joint: 3-DOF rotation, fixed relative position. Optionally limits the cone angle between the two body Z-axes.
- Body
Handle - Reference to a rigid body in the solver.
- Body
State - Minimal state the solver needs from a rigid body.
- Constraint
Id - Constraint
Island - A group of bodies and constraints that are connected and should be solved together.
- Constraint
Solver - Sequential-impulse + XPBD constraint solver.
- Constraint
World - Manages all bodies and constraints in one place.
- Contact
Constraint - Contact constraint: normal impulse (non-penetration) + friction impulse.
- Distance
Constraint - 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.
- Gear
Constraint - Couple the angular velocities of two bodies: omega_a + ratio * omega_b = 0.
- Hinge
Constraint - Hinge (revolute) joint: two bodies share a common anchor. Allows rotation around the Z-axis. Supports angular limits and a velocity motor.
- MaxDistance
Constraint - Soft rope: only constrains when distance exceeds max_distance.
- Motor
Constraint - 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.
- Pulley
Constraint - Pulley constraint: body_a and body_b are connected via a rope over two fixed pulley points. Maintains: len_a + ratio * len_b = constant.
- Slider
Constraint - Prismatic (slider) joint: allows translation along one axis only. Supports translation limits and a linear motor.
- Spring
Constraint - A spring-damper between two anchor points (Hooke’s law).
- Weld
Constraint - 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.