diff options
| author | Sébastien Crozet <developer@crozet.re> | 2021-01-29 14:42:32 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-01-29 14:42:32 +0100 |
| commit | 7ca46f38cde6cf8bf8bf41ea6067ae5bc938205c (patch) | |
| tree | 3781b9d7c92a6a8111573ba4cae1c5d41435950e /src/dynamics/coefficient_combine_rule.rs | |
| parent | e6fc8f67faf3e37afe38d683cbd930d457f289be (diff) | |
| parent | 825f33efaec4ce6a8903751e836a0ea9c466ff92 (diff) | |
| download | rapier-7ca46f38cde6cf8bf8bf41ea6067ae5bc938205c.tar.gz rapier-7ca46f38cde6cf8bf8bf41ea6067ae5bc938205c.tar.bz2 rapier-7ca46f38cde6cf8bf8bf41ea6067ae5bc938205c.zip | |
Merge pull request #79 from dimforge/split_geom
Move most of the geometric code to another crate.
Diffstat (limited to 'src/dynamics/coefficient_combine_rule.rs')
| -rw-r--r-- | src/dynamics/coefficient_combine_rule.rs | 34 |
1 files changed, 34 insertions, 0 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), + } + } +} |
