Skip to main content

RigidBody3D

Struct RigidBody3D 

Source
pub struct RigidBody3D {
    pub id: u64,
    pub position: Vector3D,
    pub velocity: Vector3D,
    pub force_accumulator: Vector3D,
    pub angular_velocity: Vector3D,
    pub torque_accumulator: Vector3D,
    pub mass: f64,
    pub inverse_mass: f64,
    pub inverse_inertia: f64,
    pub friction: f64,
    pub body_type: BodyType,
    /* private fields */
}
Expand description

A 3D rigid body participating in the physics simulation.

Fields§

§id: u64

The unique identifier of this body, typically matching a game object ID.

§position: Vector3D

The world-space position of the body’s center.

§velocity: Vector3D

The linear velocity in meters per second.

§force_accumulator: Vector3D

The accumulated force to be applied during the next physics step.

§angular_velocity: Vector3D

The angular velocity as a 3D vector (axis * speed).

§torque_accumulator: Vector3D

The accumulated torque to be applied during the next physics step.

§mass: f64

The mass of the body in kilograms. Static bodies have a mass of 0.

§inverse_mass: f64

The precomputed inverse mass (1/mass). Static bodies have 0 inverse mass.

§inverse_inertia: f64

The precomputed inverse moment of inertia (scalar, axis-aligned). Static bodies have 0 inverse inertia. Used to convert accumulated torque into angular velocity each step.

§friction: f64

The friction coefficient for surface contact.

§body_type: BodyType

How this body participates in the simulation.

Implementations§

Source§

impl RigidBody3D

Implements body creation and force management for RigidBody3D.

Source

pub fn new_dynamic(id: u64, position: Vector3D) -> RigidBody3D

Creates a new dynamic 3D rigid body with default mass and the given position.

§Arguments
  • u64 - The unique ID.
  • Vector3D - The initial position.
§Returns
  • RigidBody3D - The new body.
Source

pub fn new_static(id: u64, position: Vector3D) -> RigidBody3D

Creates a new static 3D rigid body at the given position with infinite mass.

§Arguments
  • u64 - The unique ID.
  • Vector3D - The position.
§Returns
  • RigidBody3D - The new static body.
Source

pub fn apply_force(&mut self, force: Vector3D)

Applies a force to the body’s force accumulator.

§Arguments
  • Vector3D - The force vector.
Source

pub fn apply_torque(&mut self, torque: Vector3D)

Applies a torque to the body’s torque accumulator.

§Arguments
  • Vector3D - The torque vector.
Source

pub fn apply_impulse(&mut self, impulse: Vector3D)

Applies an instantaneous impulse, directly changing velocity.

§Arguments
  • Vector3D - The impulse vector.
Source

pub fn update_mass(&mut self, mass: f64)

Sets the mass of the body, updating the inverse mass. A mass of 0 makes the body static (infinite mass).

§Arguments
  • f64 - The new mass.
Source

pub fn update_inertia(&mut self, inertia: f64)

Sets the moment of inertia of the body, updating the inverse inertia. An inertia of 0 makes the body non-rotatable (used for static bodies).

§Arguments
  • f64 - The new moment of inertia.
Source

pub fn is_dynamic(&self) -> bool

Returns true if this body is affected by forces and collisions.

§Returns
  • bool - True if this body is dynamic.
Source

pub fn update_collider(&mut self, collider: BodyCollider3D)

Attaches a 3D collider shape to this body.

§Arguments
  • BodyCollider3D - The collider to attach.
Source

pub fn bounding_box(&self) -> Option<AABB3D>

Returns the world-space 3D bounding box of the attached collider, if any.

§Returns
  • Option<AABB3D> - The bounding box, or None if no collider is attached.
Source§

impl RigidBody3D

Source

pub fn get_id(&self) -> u64

Source

pub fn get_position(&self) -> Vector3D

Source

pub fn set_position(&mut self, val: Vector3D) -> &mut Self

Source

pub fn get_velocity(&self) -> Vector3D

Source

pub fn set_velocity(&mut self, val: Vector3D) -> &mut Self

Source

pub fn get_force_accumulator(&self) -> Vector3D

Source

pub fn get_angular_velocity(&self) -> Vector3D

Source

pub fn get_torque_accumulator(&self) -> Vector3D

Source

pub fn get_mass(&self) -> f64

Source

pub fn get_inverse_mass(&self) -> f64

Source

pub fn get_inverse_inertia(&self) -> f64

Source

pub fn set_friction(&mut self, val: f64) -> &mut Self

Source

pub fn get_body_type(&self) -> BodyType

Source§

impl RigidBody3D

Source

pub fn new( id: u64, position: Vector3D, mass: f64, inverse_mass: f64, restitution: f64, friction: f64, body_type: BodyType, ) -> Self

Trait Implementations§

Source§

impl Clone for RigidBody3D

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 RigidBody3D

Source§

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

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

impl PartialEq for RigidBody3D

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for RigidBody3D

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.
Source§

impl<S, T> Upcast<T> for S
where T: UpcastFrom<S> + ?Sized, S: ?Sized,

Source§

fn upcast(&self) -> &T
where Self: ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider ref type within the Wasm bindgen generics type system. Read more
Source§

fn upcast_into(self) -> T
where Self: Sized + ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider type within the Wasm bindgen generics type system. Read more