Skip to content

Commit

Permalink
feat: add Aabb::intersects_moving_aabb
Browse files Browse the repository at this point in the history
  • Loading branch information
sebcrozet committed Apr 28, 2024
1 parent 471c27e commit 267f025
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/bounding_volume/aabb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -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<Real>) -> bool {
for i in 0..DIM {
Expand All @@ -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<Real>) -> 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<Aabb> {
let result = Aabb {
Expand Down

0 comments on commit 267f025

Please sign in to comment.