1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
pub use self::generic_joint::*;
pub use self::joint::*;
pub use self::rigid_body::*;

pub use self::fixed_joint::*;
pub use self::prismatic_joint::*;
pub use self::revolute_joint::*;
pub use self::rope_joint::*;
pub use self::spring_joint::*;

use bevy::reflect::Reflect;
use rapier::dynamics::CoefficientCombineRule as RapierCoefficientCombineRule;

#[cfg(feature = "dim3")]
pub use self::spherical_joint::*;

mod generic_joint;
mod joint;
mod rigid_body;

mod fixed_joint;
mod prismatic_joint;
mod revolute_joint;
mod rope_joint;

#[cfg(feature = "dim3")]
mod spherical_joint;
mod spring_joint;

/// 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)`.
///
/// This only affects entities with a [`RigidBody`] component.
#[derive(Copy, Clone, Debug, PartialEq, Eq, Reflect, Default)]
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
pub enum CoefficientCombineRule {
    #[default]
    /// 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 From<CoefficientCombineRule> for RapierCoefficientCombineRule {
    fn from(combine_rule: CoefficientCombineRule) -> RapierCoefficientCombineRule {
        match combine_rule {
            CoefficientCombineRule::Average => RapierCoefficientCombineRule::Average,
            CoefficientCombineRule::Min => RapierCoefficientCombineRule::Min,
            CoefficientCombineRule::Multiply => RapierCoefficientCombineRule::Multiply,
            CoefficientCombineRule::Max => RapierCoefficientCombineRule::Max,
        }
    }
}