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
63
use na::RealField;
use crate::material::{LocalMaterialProperties, Material, MaterialCombineMode, MaterialContext};
use crate::math::Vector;
#[derive(Copy, Clone, Debug)]
pub struct BasicMaterial<N: RealField> {
pub id: Option<u32>,
pub restitution: N,
pub friction: N,
pub surface_velocity: Option<Vector<N>>,
pub restitution_combine_mode: MaterialCombineMode,
pub friction_combine_mode: MaterialCombineMode,
}
impl<N: RealField> BasicMaterial<N> {
pub fn new(restitution: N, friction: N) -> Self {
BasicMaterial {
id: None,
restitution,
friction,
surface_velocity: None,
restitution_combine_mode: MaterialCombineMode::Average,
friction_combine_mode: MaterialCombineMode::Average,
}
}
}
impl<N: RealField> Material<N> for BasicMaterial<N> {
fn local_properties(&self, context: MaterialContext<N>) -> LocalMaterialProperties<N> {
LocalMaterialProperties {
id: self.id,
restitution: (self.restitution, self.restitution_combine_mode),
friction: (self.friction, self.friction_combine_mode),
surface_velocity: self
.surface_velocity
.map(|v| context.position * v)
.unwrap_or_else(Vector::zeros),
}
}
}
impl<N: RealField> Default for BasicMaterial<N> {
fn default() -> Self {
BasicMaterial::new(N::zero(), na::convert(0.5))
}
}