Struct RigidBody

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

Rigid body state. Waking requests activation of its contact island on the next step.

Implementations§

Source§

impl RigidBody

Source

pub fn validate_definition( &self, colliders: &[Collider], ) -> Result<(), BodyValidationError>

Checks this body’s authored state against a proposed collider slice.

Checks body fields first, then the child limit and each collider in slice order, then derived mass/inertia. The first failing field is returned. Fixed/kinematic bodies permit empty or massless geometry; dynamic bodies need positive combined mass and invertible inertia. Zero-density children are valid when the combined mass is valid.

This allocation-free check does not mutate the body or colliders, inspect attached handles, or alter cached mass. See RigidBodyBuilder::try_build_with_colliders for an insertion example.

Source§

impl RigidBody

Source

pub fn translation(&self) -> Vec2

Source

pub fn rotation(&self) -> &Rotation2

Source

pub fn linvel(&self) -> Vec2

Source

pub fn angvel(&self) -> f32

Source

pub fn center_of_mass(&self) -> Vec2

Source

pub fn local_center_of_mass(&self) -> Vec2

Source

pub fn velocity_at_point(&self, p: Vec2) -> Vec2

Source

pub fn mass(&self) -> f32

Source

pub fn colliders(&self) -> &[ColliderHandle]

Source

pub fn is_ccd_enabled(&self) -> bool

Source

pub fn enable_ccd(&mut self, enabled: bool)

Source

pub fn is_sleeping(&self) -> bool

Source

pub fn wake_up(&mut self, _strong: bool)

Source

pub fn try_teleport( &mut self, pose: RigidBodyPose, options: TeleportOptions, ) -> Result<RigidBodyPose, TeleportError>

Atomically set the body-origin pose and apply independent reset policies.

Rejects non-finite translation, invalid rotation and exhausted contact revision before changing anything. Rotation uses the math crate’s checked normalization (zero and non-finite quaternions are rejected). Success always invalidates cached contact/joint impulses and wakes this body, including an identical-pose reset. Old/new solid contact and enabled-joint islands wake on the next valid world step, using existing revision flags. Sensors do not connect wake islands. No simulation tick is executed here.

Identity, children, joint anchors/configuration, mass, CCD, gravity scale and damping are retained. Preserve retains stored world-space COM and angular velocities, not origin-point velocity or angular momentum. A kinematic body’s next step still derives its velocities from any retained targets (or zero with no targets). Retained targets can move it away from the new pose on that step; clearing targets prevents this snap back. Forces/torque retained by policy apply on the next step as usual.

The returned committed pose lets hosts snap both interpolation samples. Last-step contacts/manifolds/events remain snapshots until the next valid step; their impulses cannot be reused after this revision change. This operation performs no destination search or overlap rejection and allocates no storage. Existing joints may correct the pose or break on a later step.

use ferravex_math::Vec2;
use ferravex_physics::{Rotation2, d2::{
    ColliderBuilder, PhysicsWorld, RigidBodyBuilder, RigidBodyPose,
    TeleportOptions, VelocityPolicy,
}};
let mut world = PhysicsWorld::default();
let (ball, child) = world.insert(
    RigidBodyBuilder::dynamic().linvel(Vec2::X), ColliderBuilder::ball(0.5),
);
world.bodies[ball].add_force(Vec2::Y * 20., true);
let committed = world.bodies[ball].try_teleport(
    RigidBodyPose { translation: Vec2::new(2., 3.), rotation: Rotation2::default() },
    TeleportOptions::new(VelocityPolicy::Clear),
).unwrap();
world.step(1. / 60.);
assert_eq!(world.bodies[ball].translation(), committed.translation);
assert_eq!(world.bodies[ball].linvel(), Vec2::ZERO);
assert_eq!(world.bodies[ball].colliders(), &[child]);
Source

pub fn set_translation(&mut self, p: Vec2, wake: bool)

Source

pub fn set_rotation(&mut self, q: Rotation2, wake: bool)

Source

pub fn set_linvel(&mut self, v: Vec2, wake: bool)

Source

pub fn set_angvel(&mut self, v: f32, wake: bool)

Source

pub fn set_gravity_scale(&mut self, scale: f32, wake: bool)

Source

pub fn apply_impulse(&mut self, impulse: Vec2, wake: bool)

Source

pub fn apply_impulse_at_point(&mut self, impulse: Vec2, point: Vec2, wake: bool)

Source

pub fn apply_torque_impulse(&mut self, impulse: f32, wake: bool)

Source

pub fn add_force(&mut self, force: Vec2, wake: bool)

Source

pub fn add_torque(&mut self, torque: f32, wake: bool)

Source

pub fn set_next_kinematic_translation(&mut self, p: Vec2)

Source

pub fn set_next_kinematic_rotation(&mut self, q: Rotation2)

Trait Implementations§

Source§

impl Clone for RigidBody

Source§

fn clone(&self) -> RigidBody

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for RigidBody

Source§

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

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

impl From<RigidBodyBuilder> for RigidBody

Source§

fn from(b: RigidBodyBuilder) -> RigidBody

Converts to this type from the input type.

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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.