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: u64The unique identifier of this body, typically matching a game object ID.
position: Vector3DThe world-space position of the body’s center.
velocity: Vector3DThe linear velocity in meters per second.
force_accumulator: Vector3DThe accumulated force to be applied during the next physics step.
angular_velocity: Vector3DThe angular velocity as a 3D vector (axis * speed).
torque_accumulator: Vector3DThe accumulated torque to be applied during the next physics step.
mass: f64The mass of the body in kilograms. Static bodies have a mass of 0.
inverse_mass: f64The precomputed inverse mass (1/mass). Static bodies have 0 inverse mass.
inverse_inertia: f64The 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: f64The friction coefficient for surface contact.
body_type: BodyTypeHow this body participates in the simulation.
Implementations§
Source§impl RigidBody3D
Implements body creation and force management for RigidBody3D.
impl RigidBody3D
Implements body creation and force management for RigidBody3D.
Sourcepub fn new_dynamic(id: u64, position: Vector3D) -> RigidBody3D
pub fn new_dynamic(id: u64, position: Vector3D) -> RigidBody3D
Sourcepub fn new_static(id: u64, position: Vector3D) -> RigidBody3D
pub fn new_static(id: u64, position: Vector3D) -> RigidBody3D
Sourcepub fn apply_force(&mut self, force: Vector3D)
pub fn apply_force(&mut self, force: Vector3D)
Sourcepub fn apply_torque(&mut self, torque: Vector3D)
pub fn apply_torque(&mut self, torque: Vector3D)
Sourcepub fn apply_impulse(&mut self, impulse: Vector3D)
pub fn apply_impulse(&mut self, impulse: Vector3D)
Applies an instantaneous impulse, directly changing velocity.
§Arguments
Vector3D- The impulse vector.
Sourcepub fn update_mass(&mut self, mass: f64)
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.
Sourcepub fn update_inertia(&mut self, inertia: f64)
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.
Sourcepub fn is_dynamic(&self) -> bool
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.
Sourcepub fn update_collider(&mut self, collider: BodyCollider3D)
pub fn update_collider(&mut self, collider: BodyCollider3D)
Sourcepub fn bounding_box(&self) -> Option<AABB3D>
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, orNoneif no collider is attached.