contact_query3d/
contact_query3d.rs

1use parry3d::math::{Pose, Vector};
2use parry3d::query;
3use parry3d::shape::{Ball, Cuboid};
4
5fn main() {
6    let cuboid = Cuboid::new(Vector::new(1.0, 1.0, 1.0));
7    let ball = Ball::new(1.0);
8    let prediction = 1.0;
9
10    let cuboid_pos = Pose::identity();
11    let ball_pos_penetrating = Pose::translation(1.0, 1.0, 1.0);
12    let ball_pos_in_prediction = Pose::translation(2.0, 2.0, 2.0);
13    let ball_pos_too_far = Pose::translation(3.0, 3.0, 3.0);
14
15    let ctct_penetrating = query::contact(
16        &ball_pos_penetrating,
17        &ball,
18        &cuboid_pos,
19        &cuboid,
20        prediction,
21    )
22    .unwrap();
23    let ctct_in_prediction = query::contact(
24        &ball_pos_in_prediction,
25        &ball,
26        &cuboid_pos,
27        &cuboid,
28        prediction,
29    )
30    .unwrap();
31    let ctct_too_far =
32        query::contact(&ball_pos_too_far, &ball, &cuboid_pos, &cuboid, prediction).unwrap();
33
34    assert!(ctct_penetrating.unwrap().dist <= 0.0);
35    assert!(ctct_in_prediction.unwrap().dist >= 0.0);
36    assert_eq!(ctct_too_far, None);
37}