pub struct PhysicsPipeline {
pub counters: Counters,
/* private fields */
}Expand description
The main physics simulation engine that runs your physics world forward in time.
Think of this as the “game loop” for your physics simulation. Each frame, you call
PhysicsPipeline::step to advance the simulation by one timestep. This structure
handles all the complex physics calculations: detecting collisions between objects,
resolving contacts so objects don’t overlap, and updating positions and velocities.
§Performance note
This structure only contains temporary working memory (scratch buffers). You can create a new one anytime, but it’s more efficient to reuse the same instance across frames since Rapier can reuse allocated memory.
§How it works (simplified)
Rapier uses a time-stepping approach where each step involves:
- Collision detection: Find which objects are touching or overlapping
- Constraint solving: Calculate forces to prevent overlaps and enforce joint constraints
- Integration: Update object positions and velocities based on forces and gravity
- Position correction: Fix any remaining overlaps that might have occurred
Fields§
§counters: CountersCounters used for benchmarking only.
Implementations§
Source§impl PhysicsPipeline
impl PhysicsPipeline
Sourcepub fn new() -> PhysicsPipeline
pub fn new() -> PhysicsPipeline
Creates a new physics pipeline.
Call this once when setting up your physics world. The pipeline can be reused across multiple frames for better performance.
Sourcepub fn step(
&mut self,
gravity: &Vector<f32>,
integration_parameters: &IntegrationParameters,
islands: &mut IslandManager,
broad_phase: &mut BroadPhaseBvh,
narrow_phase: &mut NarrowPhase,
bodies: &mut RigidBodySet,
colliders: &mut ColliderSet,
impulse_joints: &mut ImpulseJointSet,
multibody_joints: &mut MultibodyJointSet,
ccd_solver: &mut CCDSolver,
hooks: &dyn PhysicsHooks,
events: &dyn EventHandler,
)
pub fn step( &mut self, gravity: &Vector<f32>, integration_parameters: &IntegrationParameters, islands: &mut IslandManager, broad_phase: &mut BroadPhaseBvh, narrow_phase: &mut NarrowPhase, bodies: &mut RigidBodySet, colliders: &mut ColliderSet, impulse_joints: &mut ImpulseJointSet, multibody_joints: &mut MultibodyJointSet, ccd_solver: &mut CCDSolver, hooks: &dyn PhysicsHooks, events: &dyn EventHandler, )
Advances the physics simulation by one timestep.
This is the main function you’ll call every frame in your game loop. It performs all physics calculations: collision detection, constraint solving, and updating object positions.
§Parameters
gravity- The gravity vector applied to all dynamic bodies (e.g.,vector![0.0, -9.81, 0.0]for Earth gravity pointing down)integration_parameters- Controls the simulation quality and timestep size (typically 60 Hz = 1/60 second per step)islands- Internal system that groups connected objects together for efficient solving (automatically managed)broad_phase- Fast collision detection phase that filters out distant object pairs (automatically managed)narrow_phase- Precise collision detection that computes exact contact points (automatically managed)bodies- Your collection of rigid bodies (the physical objects that move and collide)colliders- The collision shapes attached to your bodies (boxes, spheres, meshes, etc.)impulse_joints- Regular joints connecting bodies (hinges, sliders, etc.)multibody_joints- Articulated joints for robot-like structures (optional, can be empty)ccd_solver- Continuous collision detection to prevent fast objects from tunneling through thin wallshooks- Optional callbacks to customize collision filtering and contact modificationevents- Optional handler to receive collision events (when objects start/stop touching)
§Example
// In your game loop:
physics_pipeline.step(
&vector![0.0, -9.81, 0.0], // Gravity pointing down
&integration_parameters,
&mut islands,
&mut broad_phase,
&mut narrow_phase,
&mut bodies,
&mut colliders,
&mut impulse_joints,
&mut multibody_joints,
&mut ccd_solver,
&(), // No custom hooks
&(), // No event handler
);Trait Implementations§
Auto Trait Implementations§
impl Freeze for PhysicsPipeline
impl RefUnwindSafe for PhysicsPipeline
impl Send for PhysicsPipeline
impl Sync for PhysicsPipeline
impl Unpin for PhysicsPipeline
impl UnwindSafe for PhysicsPipeline
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSend for T
impl<T> DowncastSend for T
Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.