pub struct RigidBody {Show 21 fields
pub id: BodyId,
pub position: Vec2,
pub velocity: Vec2,
pub acceleration: Vec2,
pub mass: f32,
pub inv_mass: f32,
pub restitution: f32,
pub friction: f32,
pub damping: f32,
pub angle: f32,
pub angular_vel: f32,
pub angular_damp: f32,
pub inertia: f32,
pub inv_inertia: f32,
pub force_accum: Vec2,
pub torque_accum: f32,
pub is_sleeping: bool,
pub collider: Collider,
pub tag: u32,
pub layer: u8,
pub mask: u8,
}Expand description
A simulated rigid body (treated as a point mass for simplicity).
Fields§
§id: BodyId§position: Vec2§velocity: Vec2§acceleration: Vec2§mass: f32§inv_mass: f32§restitution: f32§friction: f32§damping: f32§angle: f32§angular_vel: f32§angular_damp: f32§inertia: f32§inv_inertia: f32§force_accum: Vec2§torque_accum: f32§is_sleeping: bool§collider: Collider§tag: u32User-provided tag for identification.
layer: u8§mask: u8Implementations§
Source§impl RigidBody
impl RigidBody
Sourcepub fn dynamic(position: Vec2, mass: f32, collider: Collider) -> Self
pub fn dynamic(position: Vec2, mass: f32, collider: Collider) -> Self
Create a new dynamic body.
Sourcepub fn static_body(position: Vec2, collider: Collider) -> Self
pub fn static_body(position: Vec2, collider: Collider) -> Self
Create a static body (unmovable).
Sourcepub fn apply_force(&mut self, force: Vec2)
pub fn apply_force(&mut self, force: Vec2)
Apply a force at the body’s center of mass.
Sourcepub fn apply_force_at_point(&mut self, force: Vec2, point: Vec2)
pub fn apply_force_at_point(&mut self, force: Vec2, point: Vec2)
Apply a force at a world-space point (generates torque if off-center).
Sourcepub fn apply_impulse(&mut self, impulse: Vec2)
pub fn apply_impulse(&mut self, impulse: Vec2)
Apply an impulse (instantaneous velocity change).
Sourcepub fn clear_forces(&mut self)
pub fn clear_forces(&mut self)
Clear accumulated forces.
Sourcepub fn kinetic_energy(&self) -> f32
pub fn kinetic_energy(&self) -> f32
Kinetic energy.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for RigidBody
impl RefUnwindSafe for RigidBody
impl Send for RigidBody
impl Sync for RigidBody
impl Unpin for RigidBody
impl UnsafeUnpin for RigidBody
impl UnwindSafe for RigidBody
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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.