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
use crate::math::{Point, Real, Vector};
use crate::shape::SupportMap;
use na;
use num::Zero;
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(PartialEq, Debug, Copy, Clone)]
pub struct Cone {
pub half_height: Real,
pub radius: Real,
}
impl Cone {
pub fn new(half_height: Real, radius: Real) -> Cone {
Cone {
half_height,
radius,
}
}
}
impl SupportMap for Cone {
#[inline]
fn local_support_point(&self, dir: &Vector<Real>) -> Point<Real> {
let mut vres = *dir;
vres[1] = 0.0;
if vres.normalize_mut().is_zero() {
vres = na::zero();
vres[1] = self.half_height.copysign(dir[1]);
} else {
vres = vres * self.radius;
vres[1] = -self.half_height;
if dir.dot(&vres) < dir[1] * self.half_height {
vres = na::zero();
vres[1] = self.half_height
}
}
Point::from(vres)
}
}