From 267f0258c0b12fe9e554fc6eb2dbbd06e6d2272f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Crozet?= Date: Sun, 14 Apr 2024 15:47:04 +0200 Subject: [PATCH] feat: add Aabb::intersects_moving_aabb --- src/bounding_volume/aabb.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) 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 {