ncollide3d/shape/
support_map.rs

1//! Traits for support mapping based shapes.
2
3use crate::math::{Isometry, Point, Vector};
4use na::{RealField, Unit};
5
6/// Traits of convex shapes representable by a support mapping function.
7///
8/// # Parameters:
9///   * V - type of the support mapping direction argument and of the returned point.
10pub trait SupportMap<N: RealField + Copy> {
11    // Evaluates the support function of this shape.
12    //
13    // A support function is a function associating a vector to the shape point which maximizes
14    // their dot product.
15    fn local_support_point(&self, dir: &Vector<N>) -> Point<N>;
16
17    /// Same as `self.local_support_point` except that `dir` is normalized.
18    fn local_support_point_toward(&self, dir: &Unit<Vector<N>>) -> Point<N> {
19        self.local_support_point(dir.as_ref())
20    }
21
22    // Evaluates the support function of this shape transformed by `transform`.
23    //
24    // A support function is a function associating a vector to the shape point which maximizes
25    // their dot product.
26    fn support_point(&self, transform: &Isometry<N>, dir: &Vector<N>) -> Point<N> {
27        let local_dir = transform.inverse_transform_vector(dir);
28        transform * self.local_support_point(&local_dir)
29    }
30
31    /// Same as `self.support_point` except that `dir` is normalized.
32    fn support_point_toward(&self, transform: &Isometry<N>, dir: &Unit<Vector<N>>) -> Point<N> {
33        let local_dir = Unit::new_unchecked(transform.inverse_transform_vector(dir));
34        transform * self.local_support_point_toward(&local_dir)
35    }
36}