pub struct PhysicsWorld {
pub gravity: Vec2,
pub damping: f32,
/* private fields */
}Expand description
Core 2D physics simulation for the arena.
Fields§
§gravity: Vec2§damping: f32Implementations§
Source§impl PhysicsWorld
impl PhysicsWorld
pub fn new() -> Self
Sourcepub fn add_object(&mut self, obj: PhysicsObject) -> ObjectId
pub fn add_object(&mut self, obj: PhysicsObject) -> ObjectId
Add a physics object, returning its unique ID.
Sourcepub fn remove_object(&mut self, id: ObjectId) -> Option<PhysicsObject>
pub fn remove_object(&mut self, id: ObjectId) -> Option<PhysicsObject>
Remove a physics object.
Sourcepub fn get_object(&self, id: ObjectId) -> Option<&PhysicsObject>
pub fn get_object(&self, id: ObjectId) -> Option<&PhysicsObject>
Get a reference to an object.
Sourcepub fn get_object_mut(&mut self, id: ObjectId) -> Option<&mut PhysicsObject>
pub fn get_object_mut(&mut self, id: ObjectId) -> Option<&mut PhysicsObject>
Get a mutable reference to an object.
Sourcepub fn object_count(&self) -> usize
pub fn object_count(&self) -> usize
Number of active objects.
Sourcepub fn object_ids(&self) -> Vec<ObjectId>
pub fn object_ids(&self) -> Vec<ObjectId>
Iterate over all object IDs.
Sourcepub fn step(&mut self, dt: f32) -> (Vec<CollisionPair>, Vec<TriggerEvent>)
pub fn step(&mut self, dt: f32) -> (Vec<CollisionPair>, Vec<TriggerEvent>)
Step the physics world forward by dt seconds.
Returns (collision_pairs, trigger_events) from this step.
Sourcepub fn raycast(&self, origin: Vec2, dir: Vec2, max_dist: f32) -> Option<RayHit>
pub fn raycast(&self, origin: Vec2, dir: Vec2, max_dist: f32) -> Option<RayHit>
Cast a ray into the world.
Sourcepub fn overlap_test(&self, shape: &CollisionShape, pos: Vec2) -> Vec<ObjectId>
pub fn overlap_test(&self, shape: &CollisionShape, pos: Vec2) -> Vec<ObjectId>
Test for all objects overlapping a given shape at a position.
Sourcepub fn apply_radial_force(&mut self, center: Vec2, radius: f32, strength: f32)
pub fn apply_radial_force(&mut self, center: Vec2, radius: f32, strength: f32)
Apply a radial force from a point (explosion, vortex).
Auto Trait Implementations§
impl Freeze for PhysicsWorld
impl RefUnwindSafe for PhysicsWorld
impl Send for PhysicsWorld
impl Sync for PhysicsWorld
impl Unpin for PhysicsWorld
impl UnsafeUnpin for PhysicsWorld
impl UnwindSafe for PhysicsWorld
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Convert
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Convert
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.