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
use na::RealField;
use ncollide::utils::SortedPair;
use std::collections::HashMap;
use crate::material::MaterialId;
#[derive(Clone)]
pub struct MaterialsCoefficientsTable<N: RealField> {
friction: HashMap<SortedPair<u32>, N>,
restitution: HashMap<SortedPair<u32>, N>,
}
impl<N: RealField> MaterialsCoefficientsTable<N> {
pub fn new() -> Self {
MaterialsCoefficientsTable {
friction: HashMap::new(),
restitution: HashMap::new(),
}
}
pub fn set_friction_coefficient(&mut self, m1: MaterialId, m2: MaterialId, coeff: N) {
let _ = self.friction.insert(SortedPair::new(m1, m2), coeff);
}
pub fn set_restitution_coefficient(&mut self, m1: MaterialId, m2: MaterialId, coeff: N) {
let _ = self.restitution.insert(SortedPair::new(m1, m2), coeff);
}
pub fn friction_coefficient(&self, m1: MaterialId, m2: MaterialId) -> Option<N> {
self.friction.get(&SortedPair::new(m1, m2)).cloned()
}
pub fn restitution_coefficient(&self, m1: MaterialId, m2: MaterialId) -> Option<N> {
self.restitution.get(&SortedPair::new(m1, m2)).cloned()
}
}