Struct PhysicsWorld

Source
pub struct PhysicsWorld<const D: usize> { /* private fields */ }
Expand description

Reuses bounded scratch buffers and returns an error rather than dropping overflowing collision pairs. Failed steps restore all body motion and forces. Buffers grow lazily to the configured bounds, then reuse their storage.

Implementations§

Source§

impl<const D: usize> PhysicsWorld<D>

Source

pub fn move_character( &self, origin: [f32; D], displacement: [f32; D], settings: CharacterSettings, filter: QueryFilter, ) -> Result<CharacterMotion<D>, PhysicsError>

Sweep/slide a sphere through the queried world, with low-step climbing and downward ground snap. This does not insert/move a body or apply impulses. Exclude the character’s body with the filter if it is also in this world. Slopes use collider normals; currently terrain is spheres and AABBs only. Starting penetrations are not repaired: spawn outside solid colliders.

Source§

impl<const D: usize> PhysicsWorld<D>

Source

pub fn new(gravity: [f32; D]) -> PhysicsWorld<D>

Construct a world with default finite work/memory limits. Panics for dimensions other than 2/3 or invalid gravity; use with_config for fallible construction from untrusted settings.

Source

pub fn with_config( config: WorldConfig<D>, ) -> Result<PhysicsWorld<D>, PhysicsError>

Source

pub fn config(&self) -> WorldConfig<D>

Source

pub fn len(&self) -> usize

Source

pub fn is_empty(&self) -> bool

Source

pub fn set_gravity(&mut self, gravity: [f32; D]) -> Result<(), PhysicsError>

Source

pub fn insert(&mut self, desc: BodyDesc<D>) -> Result<BodyHandle, PhysicsError>

Source

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

Source

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

Source

pub fn bodies(&self) -> impl Iterator<Item = (BodyHandle, &Body<D>)>

Source

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

Removal invalidates the handle. Its outstanding contacts generate Stopped events on the next successful step, once each, including sensor contacts.

Source

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

Source

pub fn events(&self) -> &[ContactEvent<D>]

Started/Stopped transitions from the last successful step. Persistent overlaps are available through contacts, not repeated Started events.

Source

pub fn step(&mut self, dt: f32) -> Result<StepStats, PhysicsError>

Advance exactly one timestep in (0, 0.1] seconds. Use a fixed dt, commonly 1/120, from the caller’s fixed clock. Forces last for one successful step.

Source

pub fn raycast( &self, origin: [f32; D], direction: [f32; D], max_distance: f32, filter: QueryFilter, ) -> Option<RayHit<D>>

Nearest ray hit, reflecting current body transforms immediately. Direction is normalized, so max_distance and hit distances are in world units.

Source

pub fn cast_ball( &self, origin: [f32; D], radius: f32, direction: [f32; D], max_distance: f32, filter: QueryFilter, ) -> Option<RayHit<D>>

Cast a circle/sphere continuously. point is the moving ball’s center at contact, not its surface point. Exact against boxes’ rounded Minkowski boundaries. Sensors are excluded by default; filtering is explicit.

Auto Trait Implementations§

§

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

§

impl<const D: usize> RefUnwindSafe 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> UnwindSafe 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, 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.