diff options
| author | Crozet Sébastien <developer@crozet.re> | 2021-01-21 16:03:27 +0100 |
|---|---|---|
| committer | Crozet Sébastien <developer@crozet.re> | 2021-01-21 16:03:27 +0100 |
| commit | 98d3980db7a9803f4ee965237599a87771a417d1 (patch) | |
| tree | b46aeef3ef6f703d0e938b5e1b778aa0f73a4680 /src/dynamics | |
| parent | 8f330b2a00610e5b68c1acd9208120e8f750c7aa (diff) | |
| download | rapier-98d3980db7a9803f4ee965237599a87771a417d1.tar.gz rapier-98d3980db7a9803f4ee965237599a87771a417d1.tar.bz2 rapier-98d3980db7a9803f4ee965237599a87771a417d1.zip | |
Allow several rules for combining friction/restitution coefficients.
Diffstat (limited to 'src/dynamics')
| -rw-r--r-- | src/dynamics/coefficient_combine_rule.rs | 34 | ||||
| -rw-r--r-- | src/dynamics/mod.rs | 2 | ||||
| -rw-r--r-- | src/dynamics/rigid_body.rs | 4 |
3 files changed, 39 insertions, 1 deletions
diff --git a/src/dynamics/coefficient_combine_rule.rs b/src/dynamics/coefficient_combine_rule.rs new file mode 100644 index 0000000..5e8b4a0 --- /dev/null +++ b/src/dynamics/coefficient_combine_rule.rs @@ -0,0 +1,34 @@ +use crate::math::Real; + +/// Rules used to combine two coefficients. +/// +/// This is used to determine the effective restitution and +/// friction coefficients for a contact between two colliders. +/// Each collider has its combination rule of type +/// `CoefficientCombineRule`. And the rule +/// actually used is given by `max(first_combine_rule as usize, second_combine_rule as usize)`. +#[derive(Copy, Clone, Debug, PartialEq, Eq)] +#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))] +pub enum CoefficientCombineRule { + /// The two coefficients are averaged. + Average = 0, + /// The smallest coefficient is chosen. + Min, + /// The two coefficients are multiplied. + Multiply, + /// The greatest coefficient is chosen. + Max, +} + +impl CoefficientCombineRule { + pub(crate) fn combine(coeff1: Real, coeff2: Real, rule_value1: u8, rule_value2: u8) -> Real { + let effective_rule = rule_value1.max(rule_value2); + + match effective_rule { + 0 => (coeff1 + coeff1) / 2.0, + 1 => coeff1.min(coeff2), + 2 => coeff1 * coeff2, + _ => coeff1.max(coeff2), + } + } +} diff --git a/src/dynamics/mod.rs b/src/dynamics/mod.rs index d7ce0c1..0bc0b05 100644 --- a/src/dynamics/mod.rs +++ b/src/dynamics/mod.rs @@ -11,6 +11,7 @@ pub use self::rigid_body::{ActivationStatus, BodyStatus, RigidBody, RigidBodyBui pub use self::rigid_body_set::{BodyPair, RigidBodyHandle, RigidBodySet}; pub use cdl::mass_properties::MassProperties; // #[cfg(not(feature = "parallel"))] +pub use self::coefficient_combine_rule::CoefficientCombineRule; pub(crate) use self::joint::JointGraphEdge; pub(crate) use self::rigid_body::RigidBodyChanges; #[cfg(not(feature = "parallel"))] @@ -18,6 +19,7 @@ pub(crate) use self::solver::IslandSolver; #[cfg(feature = "parallel")] pub(crate) use self::solver::ParallelIslandSolver; +mod coefficient_combine_rule; mod integration_parameters; mod joint; mod rigid_body; diff --git a/src/dynamics/rigid_body.rs b/src/dynamics/rigid_body.rs index 9279e4f..85fdec9 100644 --- a/src/dynamics/rigid_body.rs +++ b/src/dynamics/rigid_body.rs @@ -62,8 +62,10 @@ pub struct RigidBody { pub(crate) mass_properties: MassProperties, /// The world-space center of mass of the rigid-body. pub world_com: Point<Real>, + /// The inverse mass taking into account translation locking. pub effective_inv_mass: Real, - /// The square-root of the inverse angular inertia tensor of the rigid-body. + /// The square-root of the world-space inverse angular inertia tensor of the rigid-body, + /// taking into account rotation locking. pub effective_world_inv_inertia_sqrt: AngularInertia<Real>, /// The linear velocity of the rigid-body. pub(crate) linvel: Vector<Real>, |
