ncollide3d/shape/
cone.rs
1use crate::math::{Point, Vector};
4use crate::shape::SupportMap;
5use na::{self, RealField};
6
7#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
9#[derive(PartialEq, Debug, Copy, Clone)]
10pub struct Cone<N> {
11 pub half_height: N,
13 pub radius: N,
15}
16
17impl<N: RealField + Copy> Cone<N> {
18 pub fn new(half_height: N, radius: N) -> Cone<N> {
24 Cone {
25 half_height,
26 radius,
27 }
28 }
29
30 #[inline]
32 #[deprecated(note = "use the `self.half_height` public field directly.")]
33 pub fn half_height(&self) -> N {
34 self.half_height
35 }
36
37 #[inline]
39 #[deprecated(note = "use the `self.radius` public field directly.")]
40 pub fn radius(&self) -> N {
41 self.radius
42 }
43}
44
45impl<N: RealField + Copy> SupportMap<N> for Cone<N> {
46 #[inline]
47 fn local_support_point(&self, dir: &Vector<N>) -> Point<N> {
48 let mut vres = *dir;
49
50 vres[1] = na::zero();
51
52 if vres.normalize_mut().is_zero() {
53 vres = na::zero();
54 vres[1] = self.half_height.copysign(dir[1]);
55 } else {
56 vres = vres * self.radius;
57 vres[1] = -self.half_height;
58
59 if dir.dot(&vres) < dir[1] * self.half_height {
60 vres = na::zero();
61 vres[1] = self.half_height
62 }
63 }
64
65 Point::from(vres)
66 }
67}