box3d_rust/distance/
mod.rs1mod cast;
18mod gjk;
19mod simplex;
20mod toi;
21mod types;
22
23pub use cast::{get_sweep_transform, shape_cast};
24pub use gjk::{get_point_support, get_proxy_support, shape_distance};
25pub use toi::time_of_impact;
26pub use types::{
27 CastOutput, DistanceInput, DistanceOutput, ShapeCastPairInput, ShapeProxy, Simplex,
28 SimplexCache, SimplexVertex, Sweep, ToiInput, ToiOutput, ToiState,
29};
30
31use crate::constants::MAX_SHAPE_CAST_POINTS;
32use crate::math_functions::{
33 add, invert_transform, make_aabb, make_matrix_from_quat, min_int, mul_mv, Aabb, Transform, Vec3,
34};
35
36pub fn make_proxy(points: &[Vec3], radius: f32) -> ShapeProxy {
40 let count = min_int(points.len() as i32, MAX_SHAPE_CAST_POINTS as i32);
41 let mut proxy = ShapeProxy {
42 count,
43 radius,
44 ..Default::default()
45 };
46 proxy.points[..count as usize].copy_from_slice(&points[..count as usize]);
47 proxy
48}
49
50pub fn make_local_proxy(proxy: &ShapeProxy, transform: Transform) -> ShapeProxy {
53 let inv_transform = invert_transform(transform);
54 let r = make_matrix_from_quat(inv_transform.q);
55
56 let count = min_int(proxy.count, MAX_SHAPE_CAST_POINTS as i32);
57 let mut local = ShapeProxy {
58 count,
59 radius: proxy.radius,
60 ..Default::default()
61 };
62 for i in 0..count as usize {
63 local.points[i] = add(mul_mv(r, proxy.points[i]), inv_transform.p);
64 }
65 local
66}
67
68pub fn compute_proxy_aabb(proxy: &ShapeProxy) -> Aabb {
70 debug_assert!(proxy.count > 0);
71 make_aabb(&proxy.points[..proxy.count as usize], proxy.radius)
72}