Skip to main content

PhysicsWorld

Struct PhysicsWorld 

Source
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: usize

Position correction iterations per step.

§sleep_threshold: f64

Sleep velocity threshold.

§sleep_ticks: u32

Ticks below sleep threshold before sleeping.

§slop: f64

Penetration slop (small overlap allowed to prevent jitter).

§baumgarte: f64

Baumgarte 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: f64

Constraint 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>

Source

pub fn new(gravity: SVector<f64, D>) -> Self

Create an empty physics world.

Source

pub fn body_count(&self) -> usize

Get the total number of bodies in the world.

Source

pub fn total_kinetic_energy(&self) -> f64

Get the total kinetic energy of all dynamic bodies in the world.

Source

pub fn sleeping_count(&self) -> usize

Count how many bodies are currently sleeping.

Source

pub fn add_sphere( &mut self, position: Point<D>, radius: f64, mass: f64, ) -> BodyHandle

Add a dynamic sphere body and return its handle.

Source

pub fn add_body(&mut self, body: RigidBody<D>) -> BodyHandle

Add a dynamic body with a custom collider.

Source

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.

Source

pub fn handle_for_net_id(&self, net_id: NetId) -> Option<BodyHandle>

Resolve a stable NetId to its BodyHandle.

Source

pub fn net_id_for_handle(&self, handle: BodyHandle) -> Option<NetId>

Resolve a BodyHandle to its stable NetId.

Source

pub fn set_net_id(&mut self, handle: BodyHandle, net_id: NetId)

Assign a stable network identifier to a body.

Source

pub fn add_constraint(&mut self, constraint: Box<dyn Constraint<D>>)

Add a constraint between two bodies.

Source

pub fn body(&self, handle: BodyHandle) -> Option<&RigidBody<D>>

Get a reference to a body by handle.

Source

pub fn body_mut(&mut self, handle: BodyHandle) -> Option<&mut RigidBody<D>>

Get a mutable reference to a body by handle.

Source

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.

Source

pub fn step(&mut self, dt: f64)

Step without consciousness coupling (pure physics).

Trait Implementations§

Source§

impl<const D: usize> Default for PhysicsWorld<D>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.