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>
impl<const D: usize> PhysicsWorld<D>
Sourcepub fn move_character(
&self,
origin: [f32; D],
displacement: [f32; D],
settings: CharacterSettings,
filter: QueryFilter,
) -> Result<CharacterMotion<D>, PhysicsError>
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>
impl<const D: usize> PhysicsWorld<D>
Sourcepub fn new(gravity: [f32; D]) -> PhysicsWorld<D>
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.
pub fn with_config( config: WorldConfig<D>, ) -> Result<PhysicsWorld<D>, PhysicsError>
pub fn config(&self) -> WorldConfig<D>
pub fn len(&self) -> usize
pub fn is_empty(&self) -> bool
pub fn set_gravity(&mut self, gravity: [f32; D]) -> Result<(), PhysicsError>
pub fn insert(&mut self, desc: BodyDesc<D>) -> Result<BodyHandle, PhysicsError>
pub fn body(&self, handle: BodyHandle) -> Option<&Body<D>>
pub fn body_mut(&mut self, handle: BodyHandle) -> Option<&mut Body<D>>
pub fn bodies(&self) -> impl Iterator<Item = (BodyHandle, &Body<D>)>
Sourcepub fn remove(&mut self, handle: BodyHandle) -> Option<Body<D>>
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.
pub fn contacts(&self) -> &[Contact<D>]
Sourcepub fn events(&self) -> &[ContactEvent<D>]
pub fn events(&self) -> &[ContactEvent<D>]
Started/Stopped transitions from the last successful step. Persistent
overlaps are available through contacts, not repeated Started events.
Sourcepub fn step(&mut self, dt: f32) -> Result<StepStats, PhysicsError>
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.
Sourcepub fn raycast(
&self,
origin: [f32; D],
direction: [f32; D],
max_distance: f32,
filter: QueryFilter,
) -> Option<RayHit<D>>
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.
Sourcepub fn cast_ball(
&self,
origin: [f32; D],
radius: f32,
direction: [f32; D],
max_distance: f32,
filter: QueryFilter,
) -> Option<RayHit<D>>
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.