Skip to main content

PhysicsWorld2D

Struct PhysicsWorld2D 

Source
pub struct PhysicsWorld2D { /* private fields */ }
Expand description

Reusable O(N) spatial-hash broad-phase accelerator and 2D impulse physics solver.

Implementations§

Source§

impl PhysicsWorld2D

Broad-phase spatial hashing, narrow-phase contact resolution, and raycasting for PhysicsWorld2D.

Source

pub fn with_config(config: PhysicsConfig) -> Self

Creates a PhysicsWorld2D configured with config.

§Arguments
  • PhysicsConfig - Physics simulation parameters.
§Returns
  • Self - Configured 2D physics solver.
Source

pub fn step( &mut self, world: &mut GameWorld, dt_secs: f32, ) -> Vec<CollisionEvent>

Integrates velocities/positions, resolves spatial-hash collisions and arena bounds, and returns contact events.

§Arguments
  • &Self - Mutable physics world.
  • &mut GameWorld - Mutable ECS world containing entities and colliders.
  • f32 - Fixed physics timestep in seconds.
§Returns
  • Vec<CollisionEvent> - All solid and trigger contacts detected this step.
Source

pub fn raycast( world: &GameWorld, origin: Point, direction: Point, max_distance: f32, layer_mask: u32, ) -> Option<RaycastHit>

Casts a 2D ray from origin along normalized direction up to max_distance against colliders matching layer_mask.

§Arguments
  • &GameWorld - Game world to query.
  • Point - Ray origin in world units.
  • Point - Ray direction vector (normalized automatically).
  • f32 - Maximum ray distance.
  • u32 - Layer bitmask filter.
§Returns
  • Option<RaycastHit> - Closest ray intersection hit, if any.
Source

pub fn raycast_query( world: &GameWorld, query: &RaycastQuery2D, ) -> Option<RaycastHit>

Casts a 2D ray defined by a fluent RaycastQuery2D against world.

§Arguments
  • &GameWorld - Game world to query.
  • &RaycastQuery2D - Raycast query descriptor.
§Returns
  • Option<RaycastHit> - Closest ray intersection hit, if any.
Source§

impl PhysicsWorld2D

Source

pub fn get_config(&self) -> PhysicsConfig

Source

pub fn get_mut_config(&mut self) -> &mut PhysicsConfig

Source

pub fn set_config(&mut self, val: PhysicsConfig) -> &mut Self

Source

pub fn get_last_stats(&self) -> PhysicsStepStats

Source

pub fn get_mut_last_stats(&mut self) -> &mut PhysicsStepStats

Source

pub fn set_last_stats(&mut self, val: PhysicsStepStats) -> &mut Self

Trait Implementations§

Source§

impl Clone for PhysicsWorld2D

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for PhysicsWorld2D

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for PhysicsWorld2D

Default empty 2D physics world.

Source§

fn default() -> Self

Creates a PhysicsWorld2D using PhysicsConfig::default().

§Returns
  • Self - Ready physics world.

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.