ncollide3d/query/contact/
contact_plane_support_map.rs

1use crate::math::{Isometry, Point};
2use crate::query::Contact;
3use crate::shape::{Plane, SupportMap};
4use na::{self, RealField};
5
6/// Contact between a plane and a support-mapped shape (Cuboid, ConvexHull, etc.)
7pub fn contact_plane_support_map<N: RealField + Copy, G: ?Sized + SupportMap<N>>(
8    mplane: &Isometry<N>,
9    plane: &Plane<N>,
10    mother: &Isometry<N>,
11    other: &G,
12    prediction: N,
13) -> Option<Contact<N>> {
14    let plane_normal = mplane * plane.normal;
15    let plane_center = Point::from(mplane.translation.vector);
16    let deepest = other.support_point_toward(mother, &-plane_normal);
17
18    let distance = plane_normal.dot(&(plane_center - deepest));
19
20    if distance > -prediction {
21        let c1 = deepest + *plane_normal * distance;
22
23        Some(Contact::new(c1, deepest, plane_normal, distance))
24    } else {
25        None
26    }
27}
28
29/// Contact between a support-mapped shape (Cuboid, ConvexHull, etc.) and a plane.
30pub fn contact_support_map_plane<N: RealField + Copy, G: ?Sized + SupportMap<N>>(
31    mother: &Isometry<N>,
32    other: &G,
33    mplane: &Isometry<N>,
34    plane: &Plane<N>,
35    prediction: N,
36) -> Option<Contact<N>> {
37    contact_plane_support_map(mplane, plane, mother, other, prediction).map(|mut c| {
38        c.flip();
39        c
40    })
41}