diff --git a/src/bounding_volume/aabb.rs b/src/bounding_volume/aabb.rs index f8b93d84..ed32cb05 100644 --- a/src/bounding_volume/aabb.rs +++ b/src/bounding_volume/aabb.rs @@ -11,6 +11,7 @@ use num::Bounded; #[cfg(not(feature = "std"))] use na::ComplexField; // for .abs() +use crate::query::{Ray, RayCast}; #[cfg(feature = "rkyv")] use rkyv::{bytecheck, CheckBytes}; @@ -201,6 +202,7 @@ impl Aabb { BoundingSphere::new(center, radius) } + /// Does this AABB contains a point expressed in the same coordinate frame as `self`. #[inline] pub fn contains_local_point(&self, point: &Point) -> bool { for i in 0..DIM { @@ -212,6 +214,19 @@ impl Aabb { true } + /// Does this AABB intersects an AABB `aabb2` moving at velocity `vel12` relative to `self`. + #[inline] + pub fn intersects_moving_aabb(&self, aabb2: &Self, vel12: Vector) -> bool { + // Minkowski sum. + let msum = Aabb { + mins: self.mins - aabb2.maxs.coords, + maxs: self.maxs - aabb2.mins.coords, + }; + let ray = Ray::new(Point::origin(), vel12); + + msum.intersects_local_ray(&ray, 1.0) + } + /// Computes the intersection of this `Aabb` and another one. pub fn intersection(&self, other: &Aabb) -> Option { let result = Aabb {