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: f32Authored static friction in 0..=1000, at least sliding friction.
sliding_friction: f32Authored sliding friction in 0..=1000.
rolling_resistance: f32Contact 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: f32Authored restitution in 0..=1.
friction_rule: CombineRuleRule shared by static and sliding friction; the pair’s higher rule wins.
restitution_rule: CombineRuleIndependent restitution rule; the pair’s higher rule wins.
Implementations§
Source§impl PhysicsMaterial
impl PhysicsMaterial
Sourcepub fn try_new(
static_friction: f32,
sliding_friction: f32,
restitution: f32,
) -> Result<PhysicsMaterial, MaterialError>
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());Sourcepub fn validate(self) -> Result<(), MaterialError>
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());Sourcepub fn valid(self) -> bool
pub fn valid(self) -> bool
Whether this material meets the authored bounds of Self::validate.
Sourcepub fn try_combine(
self,
other: PhysicsMaterial,
) -> Result<PhysicsMaterial, MaterialError>
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
impl Clone for PhysicsMaterial
Source§fn clone(&self) -> PhysicsMaterial
fn clone(&self) -> PhysicsMaterial
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more