Struct PhysicsMaterial

Source
pub struct PhysicsMaterial {
    pub static_friction: f32,
    pub sliding_friction: f32,
    pub rolling_resistance: f32,
    pub restitution: f32,
    pub friction_rule: CombineRule,
    pub restitution_rule: CombineRule,
}
Expand description

Authored collider coefficients, or effective coefficients from a material pair.

Struct literals remain supported. Use Self::validate before applying an authored value, or Self::try_new for default-rule authoring. Pair outputs may exceed the authored friction limit when using Multiply; see Self::try_combine. These operations allocate no storage.

Fields§

§static_friction: f32

Authored static friction in 0..=1000, at least sliding friction.

§sliding_friction: f32

Authored sliding friction in 0..=1000.

§rolling_resistance: f32

Contact torque impulse limit = normal impulse * this length (meters). Authored range is 0..=10. Resists rolling and spin; zero retains the historical behavior. Pairs always use the arithmetic mean.

§restitution: f32

Authored restitution in 0..=1.

§friction_rule: CombineRule

Rule shared by static and sliding friction; the pair’s higher rule wins.

§restitution_rule: CombineRule

Independent restitution rule; the pair’s higher rule wins.

Implementations§

Source§

impl PhysicsMaterial

Source

pub fn try_new( static_friction: f32, sliding_friction: f32, restitution: f32, ) -> Result<PhysicsMaterial, MaterialError>

Author checked coefficients with the default mixing rules and no rolling resistance. Invalid values are rejected, never clamped or reordered.

use ferravex_physics::PhysicsMaterial;

let rubber = PhysicsMaterial::try_new(0.9, 0.7, 0.8).unwrap();
assert!(rubber.valid());
assert!(PhysicsMaterial::try_new(0.2, 0.7, 0.8).is_err());
Source

pub fn validate(self) -> Result<(), MaterialError>

Validate authored coefficients without changing them.

Reports the first error in this order: static friction range, sliding friction range, sliding/static ordering, rolling resistance, restitution. All bounds are inclusive; signed zero and positive subnormals are valid. Every non-finite value is rejected. Mixing rules do not affect validity.

use ferravex_physics::{CombineRule, PhysicsMaterial};

let material = PhysicsMaterial {
    rolling_resistance: 0.05,
    restitution_rule: CombineRule::Maximum,
    ..PhysicsMaterial::default()
};
assert!(material.validate().is_ok());
let invalid = PhysicsMaterial { restitution: 1.01, ..material };
assert!(invalid.validate().is_err());
Source

pub fn valid(self) -> bool

Whether this material meets the authored bounds of Self::validate.

Source

pub fn try_combine( self, other: PhysicsMaterial, ) -> Result<PhysicsMaterial, MaterialError>

Inspect the effective contact material using the solver’s pair rules.

Validates self, then other, as authored materials. For each of friction and restitution, the higher-priority CombineRule wins. Rolling resistance always uses the arithmetic mean. Inputs are unchanged.

The result is finite and nonnegative, with static friction at least sliding friction and restitution in 0..=1. Friction is not clamped: Multiply can yield up to 1_000_000, preserving solver behavior. Such a result is contact data and can fail Self::validate if reused as an authored collider material (or as an input to this helper).

Zero friction on either collider makes default geometric mixing zero. Maximum can override that behavior; zero is not an unconditional opt-out of friction. Rolling resistance is independent of friction coefficients.

use ferravex_physics::{CombineRule, PhysicsMaterial};

let ice = PhysicsMaterial::try_new(0.0, 0.0, 0.0).unwrap();
let rubber = PhysicsMaterial::try_new(0.9, 0.7, 0.8).unwrap();
let contact = ice.try_combine(rubber).unwrap();
assert_eq!(contact.sliding_friction, 0.0);
assert_eq!(contact.restitution, 0.4);
assert_eq!(contact, rubber.try_combine(ice).unwrap());
let grip = PhysicsMaterial { friction_rule: CombineRule::Maximum, ..rubber };
assert_eq!(ice.try_combine(grip).unwrap().sliding_friction, 0.7);

Trait Implementations§

Source§

impl Clone for PhysicsMaterial

Source§

fn clone(&self) -> PhysicsMaterial

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 PhysicsMaterial

Source§

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

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

impl Default for PhysicsMaterial

Source§

fn default() -> PhysicsMaterial

Returns the “default value” for a type. Read more
Source§

impl PartialEq for PhysicsMaterial

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for PhysicsMaterial

Source§

impl StructuralPartialEq for PhysicsMaterial

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.