pub struct PhysicsWorld<const D: usize> {
pub bodies: Vec<RigidBody<D>>,
pub constraints: Vec<Box<dyn Constraint<D>>>,
pub gravity: SVector<f64, D>,
pub contacts: Vec<ContactManifold<D>>,
pub collision_events: Vec<CollisionEvent<D>>,
pub sensor_events: Vec<SensorEvent>,
pub solver_iterations: usize,
pub sleep_threshold: f64,
pub sleep_ticks: u32,
pub slop: f64,
pub baumgarte: f64,
pub compliance: f64,
/* private fields */
}Expand description
The physics world manages all rigid bodies and steps the simulation.
Fields§
§bodies: Vec<RigidBody<D>>§constraints: Vec<Box<dyn Constraint<D>>>§gravity: SVector<f64, D>§contacts: Vec<ContactManifold<D>>Contacts from the last step.
collision_events: Vec<CollisionEvent<D>>Collision events from the last step (for game logic callbacks).
sensor_events: Vec<SensorEvent>Sensor overlap events from the last step.
solver_iterations: usizePosition correction iterations per step.
sleep_threshold: f64Sleep velocity threshold.
sleep_ticks: u32Ticks below sleep threshold before sleeping.
slop: f64Penetration slop (small overlap allowed to prevent jitter).
baumgarte: f64Baumgarte stabilization factor (TGS Soft position-bias coefficient).
Used as bias = baumgarte * (depth - slop).max(0) / dt in TGS Soft.
Typical values: 0.1–0.4. Default: 0.2.
compliance: f64Constraint compliance (softness). 0.0 = rigid (default). Higher values
make contacts softer (spring-like). Applied as α = compliance / dt².
Implementations§
Source§impl<const D: usize> PhysicsWorld<D>
impl<const D: usize> PhysicsWorld<D>
Sourcepub fn body_count(&self) -> usize
pub fn body_count(&self) -> usize
Get the total number of bodies in the world.
Sourcepub fn total_kinetic_energy(&self) -> f64
pub fn total_kinetic_energy(&self) -> f64
Get the total kinetic energy of all dynamic bodies in the world.
Sourcepub fn sleeping_count(&self) -> usize
pub fn sleeping_count(&self) -> usize
Count how many bodies are currently sleeping.
Sourcepub fn add_sphere(
&mut self,
position: Point<D>,
radius: f64,
mass: f64,
) -> BodyHandle
pub fn add_sphere( &mut self, position: Point<D>, radius: f64, mass: f64, ) -> BodyHandle
Add a dynamic sphere body and return its handle.
Sourcepub fn add_body(&mut self, body: RigidBody<D>) -> BodyHandle
pub fn add_body(&mut self, body: RigidBody<D>) -> BodyHandle
Add a dynamic body with a custom collider.
Sourcepub fn add_bodies_deterministic(
&mut self,
bodies: Vec<(NetId, RigidBody<D>)>,
) -> Result<Vec<BodyHandle>, String>
pub fn add_bodies_deterministic( &mut self, bodies: Vec<(NetId, RigidBody<D>)>, ) -> Result<Vec<BodyHandle>, String>
Add multiple bodies with stable network IDs in deterministic order.
Bodies are sorted by NetId before insertion, ensuring the same
BodyHandle assignment regardless of the caller’s iteration order.
Returns an error if any NetId is duplicated.
Sourcepub fn handle_for_net_id(&self, net_id: NetId) -> Option<BodyHandle>
pub fn handle_for_net_id(&self, net_id: NetId) -> Option<BodyHandle>
Resolve a stable NetId to its BodyHandle.
Sourcepub fn net_id_for_handle(&self, handle: BodyHandle) -> Option<NetId>
pub fn net_id_for_handle(&self, handle: BodyHandle) -> Option<NetId>
Resolve a BodyHandle to its stable NetId.
Sourcepub fn set_net_id(&mut self, handle: BodyHandle, net_id: NetId)
pub fn set_net_id(&mut self, handle: BodyHandle, net_id: NetId)
Assign a stable network identifier to a body.
Sourcepub fn add_constraint(&mut self, constraint: Box<dyn Constraint<D>>)
pub fn add_constraint(&mut self, constraint: Box<dyn Constraint<D>>)
Add a constraint between two bodies.
Sourcepub fn body(&self, handle: BodyHandle) -> Option<&RigidBody<D>>
pub fn body(&self, handle: BodyHandle) -> Option<&RigidBody<D>>
Get a reference to a body by handle.
Sourcepub fn body_mut(&mut self, handle: BodyHandle) -> Option<&mut RigidBody<D>>
pub fn body_mut(&mut self, handle: BodyHandle) -> Option<&mut RigidBody<D>>
Get a mutable reference to a body by handle.
Sourcepub fn step_with_callback(
&mut self,
dt: f64,
callback: &mut dyn PhysicsCallback<D>,
)
pub fn step_with_callback( &mut self, dt: f64, callback: &mut dyn PhysicsCallback<D>, )
Step with consciousness-physics callback.
The callback modulates forces, impulses, and friction based on consciousness state, closing the consciousness-physics loop.
Trait Implementations§
Auto Trait Implementations§
impl<const D: usize> !RefUnwindSafe for PhysicsWorld<D>
impl<const D: usize> !UnwindSafe for PhysicsWorld<D>
impl<const D: usize> Freeze for PhysicsWorld<D>
impl<const D: usize> Send for PhysicsWorld<D>
impl<const D: usize> Sync for PhysicsWorld<D>
impl<const D: usize> Unpin for PhysicsWorld<D>
impl<const D: usize> UnsafeUnpin for PhysicsWorld<D>
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<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.