Struct RigidBodyBuilder

Source
pub struct RigidBodyBuilder { /* private fields */ }

Implementations§

Source§

impl RigidBodyBuilder

Source

pub fn try_translation( self, p: Vec3, ) -> Result<RigidBodyBuilder, BodyValidationError>

Checked translation in world units. Rejects non-finite components.

Source

pub fn try_rotation( self, r: Vec3, ) -> Result<RigidBodyBuilder, BodyValidationError>

Checked rotation in radians (a scaled axis in 3D). Rejects non-finite input or an unrepresentable quaternion conversion.

Source

pub fn try_linvel( self, v: Vec3, ) -> Result<RigidBodyBuilder, BodyValidationError>

Checked linear velocity in world units per second.

Source

pub fn try_angvel( self, v: Vec3, ) -> Result<RigidBodyBuilder, BodyValidationError>

Checked angular velocity in radians per second.

Source

pub fn try_linear_damping( self, v: f32, ) -> Result<RigidBodyBuilder, BodyValidationError>

Checked finite, nonnegative linear damping.

Source

pub fn try_angular_damping( self, v: f32, ) -> Result<RigidBodyBuilder, BodyValidationError>

Checked finite, nonnegative angular damping.

Source

pub fn try_gravity_scale( self, v: f32, ) -> Result<RigidBodyBuilder, BodyValidationError>

Checked finite gravity scale; negative scales are allowed.

Source

pub fn try_build(self) -> Result<RigidBody, BodyValidationError>

Builds after checking pose, velocities, damping and gravity scale.

Mass is assigned by world insertion. To also check the proposed colliders and dynamic mass, use Self::try_build_with_colliders. Legacy setters can still panic before this method is reached; use the try_* setters for untrusted numeric input.

use ferravex_math::Vec2;
use ferravex_physics::d2::RigidBodyBuilder;
let body = RigidBodyBuilder::dynamic()
    .try_translation(Vec2::new(2., 3.)).unwrap()
    .try_rotation(0.5).unwrap()
    .try_linvel(Vec2::X).unwrap()
    .try_angvel(1.).unwrap()
    .try_linear_damping(0.1).unwrap()
    .try_angular_damping(0.2).unwrap()
    .try_gravity_scale(-1.).unwrap()
    .try_build().unwrap();
assert_eq!(body.linvel(), Vec2::X);
assert_eq!(body.mass(), 0.); // Mass is assigned on insertion.
let error = RigidBodyBuilder::fixed().try_linvel(Vec2::NAN).unwrap_err();
assert_eq!(error.to_string(), "linear velocity must be finite");
Source

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

Builds and validates the proposed complete collider definition.

This borrows the colliders without cloning, attaching or inserting them. Mass remains unassigned until world insertion. Validation does not reserve world capacity or guarantee stability for future forces, time steps or extreme finite coordinates/velocities.

use ferravex_math::{Quat, Vec3};
use ferravex_physics::d3::{ColliderBuilder, PhysicsWorld, RigidBodyBuilder};
let children = [ColliderBuilder::try_cuboid(1., 0.5, 0.25).unwrap()
    .try_density(2.).unwrap()
    .try_translation(Vec3::X).unwrap()
    .try_rotation(Quat::IDENTITY).unwrap()
    .try_build().unwrap()];
let body = RigidBodyBuilder::dynamic()
    .try_rotation(Vec3::Z * 0.3).unwrap()
    .try_angvel(Vec3::Z).unwrap()
    .try_build_with_colliders(&children).unwrap();
body.validate_definition(&children).unwrap();
let mut world = PhysicsWorld::new([0.; 3]);
let handle = world.insert_compound(body, children).unwrap();
assert_eq!(world.bodies[handle].mass(), 2.);
Source§

impl RigidBodyBuilder

Trait Implementations§

Source§

impl Clone for RigidBodyBuilder

Source§

fn clone(&self) -> RigidBodyBuilder

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 RigidBodyBuilder

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.