ncollide3d/query/nonlinear_time_of_impact/
nonlinear_time_of_impact.rs

1use na::RealField;
2
3use crate::interpolation::RigidMotion;
4use crate::query::{self, TOIDispatcher, Unsupported, TOI};
5use crate::shape::{Ball, Shape};
6
7/// Computes the smallest time of impact of two shapes under translational movement.
8pub fn nonlinear_time_of_impact<N: RealField + Copy>(
9    dispatcher: &dyn TOIDispatcher<N>,
10    motion1: &dyn RigidMotion<N>,
11    g1: &dyn Shape<N>,
12    motion2: &dyn RigidMotion<N>,
13    g2: &dyn Shape<N>,
14    max_toi: N,
15    target_distance: N,
16) -> Result<Option<TOI<N>>, Unsupported> {
17    if let (Some(b1), Some(b2)) = (g1.as_shape::<Ball<N>>(), g2.as_shape::<Ball<N>>()) {
18        Ok(query::nonlinear_time_of_impact_ball_ball(
19            motion1,
20            b1,
21            motion2,
22            b2,
23            max_toi,
24            target_distance,
25        ))
26    } else if let (Some(s1), Some(s2)) = (g1.as_support_map(), g2.as_support_map()) {
27        Ok(query::nonlinear_time_of_impact_support_map_support_map(
28            motion1,
29            s1,
30            motion2,
31            s2,
32            max_toi,
33            target_distance,
34        ))
35    } else if let Some(c1) = g1.as_composite_shape() {
36        Ok(query::nonlinear_time_of_impact_composite_shape_shape(
37            dispatcher,
38            motion1,
39            c1,
40            motion2,
41            g2,
42            max_toi,
43            target_distance,
44        ))
45    } else if let Some(c2) = g2.as_composite_shape() {
46        Ok(query::nonlinear_time_of_impact_shape_composite_shape(
47            dispatcher,
48            motion1,
49            g1,
50            motion2,
51            c2,
52            max_toi,
53            target_distance,
54        ))
55    /* } else if let (Some(p1), Some(s2)) = (g1.as_shape::<Plane<N>>(), g2.as_support_map()) {
56    //        query::nonlinear_time_of_impact_plane_support_map(m1, vel1, p1, m2, vel2, s2)
57            unimplemented!()
58        } else if let (Some(s1), Some(p2)) = (g1.as_support_map(), g2.as_shape::<Plane<N>>()) {
59    //        query::nonlinear_time_of_impact_support_map_plane(m1, vel1, s1, m2, vel2, p2)
60            unimplemented!() */
61    } else {
62        Err(Unsupported)
63    }
64}