Skip to main content

PhysicsWorld

Struct PhysicsWorld 

Source
pub struct PhysicsWorld {
    pub gravity: [f32; 3],
    pub sleep_config: SleepConfig,
    pub dreamspace: DreamSpace,
    pub superposition: Vec<SuperpositionState>,
    /* private fields */
}
Expand description

CPU-deterministic physics simulation world.

Fields§

§gravity: [f32; 3]§sleep_config: SleepConfig§dreamspace: DreamSpace

DreamSpace incremental broadphase (alternative to SpatialHashGrid).

§superposition: Vec<SuperpositionState>

Per-body superposition state. Parallel to bodies Vec.

Implementations§

Source§

impl PhysicsWorld

Source

pub fn new() -> Self

Source

pub fn add_body(&mut self, body: RigidBody) -> BodyId

Add a rigid body. Returns its handle.

Source

pub fn remove_body(&mut self, id: BodyId) -> bool

Remove a rigid body by ID. Returns true if found.

Source

pub fn body(&self, id: BodyId) -> Option<&RigidBody>

Get body by ID.

Source

pub fn body_mut(&mut self, id: BodyId) -> Option<&mut RigidBody>

Get mutable body by ID.

Source

pub fn body_count(&self) -> usize

Number of active bodies.

Source

pub fn bodies(&self) -> &[RigidBody]

Access all bodies (read-only slice).

Source

pub fn set_broadphase_cell_size(&mut self, size: f32)

Set broadphase cell size. Optimal: ~2x the largest body radius. Smaller cells = faster query at high body counts, more memory.

Source

pub fn bodies_mut_slice(&mut self) -> &mut [RigidBody]

Mutable access to all bodies (for superposition state toggling).

Source

pub fn body_ids(&self) -> &[BodyId]

Access all body IDs.

Source

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

Step the simulation forward by dt seconds. Sequence: apply gravity → detect contacts → resolve contacts → integrate → sleep.

Source

pub fn step_dreamspace(&mut self, dt: f32)

Step using DreamSpace incremental broadphase. Same physics as step() but only re-queries cells that had boundary crossings. First call triggers a full rebuild; subsequent calls are incremental.

Source

pub fn step_superposition(&mut self, dt: f32, observer: &SuperpositionObserver)

Step with DreamSuperposition — cell-level coherence collapse + decoherence rings.

Phase 0: Cell-level coherence collapse (O(C) cells, not O(N) bodies) Phase 1: Gravity (Active + Decohering-on-tick only) Phase 2: Broadphase (DreamSpace incremental, Active + Decohering only) Phase 3: Narrowphase (filtered pairs) Phase 4: Contact wake + resolve Phase 5: Integrate (Active + Decohering-on-tick) Phase 6: DreamSpace update

Source

pub fn superposition_counts(&self) -> (u32, u32, u32, u32)

Count bodies in each superposition state: (active, decohering, superposed, dormant).

Source

pub fn raycast( &self, origin: [f32; 3], direction: [f32; 3], max_dist: f32, ) -> Option<RayHit>

Cast a ray and return the closest hit.

Source

pub fn contacts(&self) -> &[Contact]

Read-only access to contacts from the last step.

Trait Implementations§

Source§

impl Default for PhysicsWorld

Source§

fn default() -> Self

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

Auto Trait Implementations§

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, 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.