Skip to main content

Crate crcbl_phys

Crate crcbl_phys 

Source
Expand description

Physics: broadphase queries, forces, continuous collision detection.

This crate provides the engine’s physics pillar: collider shapes, bounding volumes, broadphase spatial queries (BVH), continuous collision detection (swept sphere and swept capsule TOI), and the capsule character controller built on them.

§Layered architecture

LayerContentsStatus
L0Queries + kinematics: ray/segment/sweep/overlap, trigger volumes, character controllerCurrent
L1Forces + ballistics + orbits: gravity, drag, thrust, integrators, Kepler propagationCurrent
CCDSwept collision: TOI, motion-inflated broadphaseCurrent
L2Contact solver: sequential impulses, warm starting, islands, sleep, sweepsRungs 1–4
L3Joints in the same solver: distance, revolute, prismatic, weld, sphericalRung 5

L1 today is the force pipeline and one integrator: GravityForce, DragForce, DampingForce and ThrustForce feed SemiImplicitEuler through ForceProvider. The integrator turns bodies as well as moving them — torque, an inertia tensor from MassProperties, the gyroscopic term by the implicit midpoint rule, and the quaternion turned to match — which is contact-solver rung 0 (docs/notes/simulation.md). This crate’s clippy.toml refuses the platform’s transcendental functions: the sine and cosine it constructs are crcbl_core::trig’s, and the three platform calls still standing — AtmosphericDrag’s exponential, the sphere of influence’s power and the Kepler solution’s Stumpff functions — each say why where they are made. SurfaceMaterial carries each body’s friction and restitution.

L2 is contact-solver rungs 1 to 3, in contact: a system made with PhysicsSystem::with_contacts collides spheres, capsules and boxes through split broadphase trees, analytic manifolds, a cached separating axis test with clipping for box pairs, and a substepped soft solver with warm starting by feature id, centroid and twist friction, speculative contacts and a restitution pass, and raises a KineticContact for each hard impact. Still bodies gather into persistent islands that sleep, costing nothing until something wakes them. Joints are rung 5: constraints in the same solver, with limits, motors and breaking, and a body can ask for more substeps for its group with PhysicsSystem::set_substeps. Convex hulls are a later rung.

Atmosphere and its quadratic AtmosphericDrag have landed, the Frames hierarchy carries sphere-of-influence crossings, and propagate is the analytic Kepler solution a coasting body is put on rails with.

L0’s kinematics side is CharacterController: a capsule that walks, slides, climbs steps and stays on its ground, moved by PhysicsWorld::sweep_capsule and dug out by PhysicsWorld::capsule_penetrations_into. It takes a world-space displacement and knows nothing about any camera, which is what lets one controller serve a first-person and a third-person game.

TriangleMesh is level geometry — floors, ramps, stairs — for static and kinematic bodies: the contact solver collides it triangle by triangle, one side of each, with Jolt’s active edges so a body slides across a seam without catching, and PhysicsWorld::add_mesh puts it in the query world, whose rays, sweeps and overlaps hit its triangles exactly.

AabbCompound is L0’s query surface for a rigid body made of several boxes: a ray cast and a closest-point query against local-space parts at a Transform, naming the part each answer came from. CompoundShape is the same kind of body to the contact solver: boxes fixed in its frame, each colliding on its own, with mass and inertia summed from the parts.

All spatial types use f64 for determinism. Downcasting to f32 happens only at the render boundary via crcbl_core::WorldPos::relative_to.

The design’s rules are in docs/notes/simulation.md, under “What the deleted 05-physics plan left behind”; what is still owed is in docs/backlog.md.

Re-exports§

pub use atmosphere::Atmosphere;
pub use atmosphere::AtmosphericDrag;
pub use broadphase::Bvh;
pub use broadphase::BvhHit;
pub use broadphase::Ray;
pub use broadphase::Segment;
pub use character::CharacterConfig;
pub use character::CharacterController;
pub use character::GroundContact;
pub use character::GroundProbe;
pub use character::LyingMoveOutcome;
pub use character::LyingTurnOutcome;
pub use character::MoveOutcome;
pub use character::SlideContact;
pub use collider::Aabb;
pub use collider::BoxCollider;
pub use collider::Capsule;
pub use collider::LyingCapsule;
pub use collider::Sphere;
pub use components::ColliderComponent;
pub use components::RigidBody;
pub use components::Transform;
pub use compound::AabbCompound;
pub use compound::CompoundError;
pub use compound::CompoundHit;
pub use compound::CompoundPoint;
pub use compound_shape::CompoundBody;
pub use compound_shape::CompoundPart;
pub use compound_shape::CompoundShape;
pub use contact::ContactBody;
pub use contact::ContactCounters;
pub use contact::ContactReport;
pub use contact::ContactSettings;
pub use contact::KineticContact;
pub use contact::KineticSource;
pub use contact::PlaneId;
pub use contact::StageTimes;
pub use forces::DampingForce;
pub use forces::DragForce;
pub use forces::ForceProvider;
pub use forces::GravityForce;
pub use forces::PointGravity;
pub use forces::ThrustForce;
pub use frames::FrameId;
pub use frames::Frames;
pub use frames::State;
pub use frames::sphere_of_influence;
pub use impulse::ImpulseError;
pub use integrator::GYROSCOPIC_ITERATIONS;
pub use integrator::Integrator;
pub use integrator::MAX_ROTATION_LENGTH_ERROR;
pub use integrator::SemiImplicitEuler;
pub use integrator::SpinStep;
pub use integrator::cayley_rotation;
pub use integrator::gyroscopic_step;
pub use integrator::integrate_rotation;
pub use integrator::rotation_from_scaled_axis;
pub use joint::DistanceJoint;
pub use joint::Joint;
pub use joint::JointBreak;
pub use joint::JointDrift;
pub use joint::JointError;
pub use joint::JointId;
pub use joint::JointKind;
pub use joint::PrismaticJoint;
pub use joint::RevoluteJoint;
pub use joint::SphericalJoint;
pub use joint::Spring;
pub use joint::WeldJoint;
pub use mass::MassProperties;
pub use material::CombineRule;
pub use material::ContactMaterial;
pub use material::SurfaceMaterial;
pub use mesh::MeshError;
pub use mesh::MeshHit;
pub use mesh::TriangleMesh;
pub use orbit::Orbit;
pub use orbit::propagate;
pub use query::ARC_MAX_ITERATIONS;
pub use query::ARC_TIME_TOLERANCE;
pub use query::AcceleratedPath;
pub use query::ArcHit;
pub use query::OverlapHit;
pub use query::Penetration;
pub use query::ShapeHit;
pub use query::aabb_overlaps_box;
pub use query::capsule_penetration_vs_aabb;
pub use query::capsule_penetration_vs_box;
pub use query::capsule_penetration_vs_capsule;
pub use query::capsule_penetration_vs_sphere;
pub use query::ray_vs_aabb;
pub use query::ray_vs_box;
pub use query::ray_vs_capsule;
pub use query::ray_vs_sphere;
pub use query::sphere_overlap_vs_aabb;
pub use query::sphere_overlap_vs_box;
pub use query::sphere_overlap_vs_capsule;
pub use query::sphere_overlap_vs_sphere;
pub use query::sphere_overlaps_aabb;
pub use query::sphere_overlaps_box;
pub use query::sphere_overlaps_capsule;
pub use query::sphere_overlaps_sphere;
pub use query::swept_capsule_vs_aabb;
pub use query::swept_capsule_vs_box;
pub use query::swept_capsule_vs_capsule;
pub use query::swept_capsule_vs_sphere;
pub use query::swept_sphere_vs_aabb;
pub use query::swept_sphere_vs_box;
pub use query::swept_sphere_vs_capsule;
pub use query::swept_sphere_vs_sphere;
pub use system::CONTACT_NORMAL_LENGTH;
pub use system::CollisionFilter;
pub use system::ContactPairError;
pub use system::EntityOverlapQueries;
pub use system::PhysicsDebugLine;
pub use system::PhysicsSystem;
pub use wind::WindQuery;
pub use world::ALL_LAYERS;
pub use world::BroadphaseStats;
pub use world::ColliderId;
pub use world::LayerMatch;
pub use world::OverlapQueries;
pub use world::PhysicsWorld;
pub use world::QueryFilter;
pub use world::QueryScratch;

Modules§

atmosphere
An exponential atmosphere, and the quadratic drag a body moving through it feels.
broadphase
Broadphase spatial queries: bounding volume hierarchy (BVH).
character
Capsule character controller: sweep-based movement against the world.
collider
Collider shapes and bounding volumes for physics queries.
components
ECS-ready component types for physics simulation.
compound
Rigid compounds: a set of boxes fixed in one body’s local space, queried at a pose.
compound_shape
Compound collision shapes: several boxes fixed in one body’s frame that the contact pipeline collides as one rigid body.
contact
Contacts and joints: contact-solver rungs 1 to 5, recorded in docs/notes/simulation.md.
dispersion
Spread: a direction scattered within a cone about an aim, from two uniform random numbers the caller draws — a shot group, a shotgun’s pellets, a spray of sparks.
flight
Point-mass free flight with quadratic drag and gravity, in bounded segments a caller sweeps for collisions: a bullet, a thrown grenade, a shell casing.
forces
Force providers for the dynamics pipeline.
frames
A hierarchy of reference frames, and the sphere-of-influence crossings that move a body between them.
impulse
Instantaneous impulses applied at world-space points.
integrator
Numerical integrators for the physics dynamics pipeline.
joint
Joints: the rest of contact-solver rung 5 (docs/notes/simulation.md) — L3’s constraints, solved by the same Soft Step as the contacts.
mass
Mass properties from collider shapes: mass, centre of mass and the inertia tensor a RigidBody rotates with.
material
Surface materials: the friction and restitution a contact reads.
mesh
Static triangle meshes: level geometry — floors, ramps, stairs — that the contact solver and the query world both collide triangle by triangle.
orbit
Analytic two-body propagation: where a coasting body is at time t, without integrating anything to find out.
query
Shape-level intersection queries: ray-vs-shape and swept-sphere TOI.
system
ECS physics system: bridges PhysicsWorld with entity-component data.
wind
The seam physics reads moving air through.
world
Physics world: collider storage, BVH management, and query dispatch.