aboutsummaryrefslogtreecommitdiff
path: root/src/geometry/broad_phase_multi_sap
diff options
context:
space:
mode:
authorSébastien Crozet <sebcrozet@dimforge.com>2024-03-17 21:20:18 +0100
committerSébastien Crozet <sebcrozet@dimforge.com>2024-03-17 21:24:28 +0100
commitecd308338b189ab569816a38a03e3f8b89669dde (patch)
treefa612abff2f23ea6a5ff04c64c07296d9fb065c8 /src/geometry/broad_phase_multi_sap
parentda92e5c2837b27433286cf0dd9d887fd44dda254 (diff)
downloadrapier-bevy-glam.tar.gz
rapier-bevy-glam.tar.bz2
rapier-bevy-glam.zip
feat: start experimenting with a glam/bevy versionbevy-glam
Diffstat (limited to 'src/geometry/broad_phase_multi_sap')
-rw-r--r--src/geometry/broad_phase_multi_sap/broad_phase.rs6
-rw-r--r--src/geometry/broad_phase_multi_sap/broad_phase_pair_event.rs8
-rw-r--r--src/geometry/broad_phase_multi_sap/sap_axis.rs2
-rw-r--r--src/geometry/broad_phase_multi_sap/sap_endpoint.rs2
-rw-r--r--src/geometry/broad_phase_multi_sap/sap_layer.rs36
-rw-r--r--src/geometry/broad_phase_multi_sap/sap_utils.rs18
6 files changed, 35 insertions, 37 deletions
diff --git a/src/geometry/broad_phase_multi_sap/broad_phase.rs b/src/geometry/broad_phase_multi_sap/broad_phase.rs
index 9e1bc06..07a5854 100644
--- a/src/geometry/broad_phase_multi_sap/broad_phase.rs
+++ b/src/geometry/broad_phase_multi_sap/broad_phase.rs
@@ -6,7 +6,7 @@ use crate::geometry::{
ColliderBroadPhaseData, ColliderChanges, ColliderHandle, ColliderPosition, ColliderSet,
ColliderShape,
};
-use crate::math::Real;
+use crate::math::*;
use crate::utils::IndexMut2;
use parry::bounding_volume::BoundingVolume;
use parry::utils::hashmap::HashMap;
@@ -361,8 +361,8 @@ impl BroadPhase {
.compute_aabb(co_pos)
.loosened(prediction_distance / 2.0);
- if aabb.mins.coords.iter().any(|e| !e.is_finite())
- || aabb.maxs.coords.iter().any(|e| !e.is_finite())
+ if aabb.mins.as_vector().iter().any(|e| !e.is_finite())
+ || aabb.maxs.as_vector().iter().any(|e| !e.is_finite())
{
// Reject Aabbs with non-finite values.
return false;
diff --git a/src/geometry/broad_phase_multi_sap/broad_phase_pair_event.rs b/src/geometry/broad_phase_multi_sap/broad_phase_pair_event.rs
index 7b489f5..5732fad 100644
--- a/src/geometry/broad_phase_multi_sap/broad_phase_pair_event.rs
+++ b/src/geometry/broad_phase_multi_sap/broad_phase_pair_event.rs
@@ -25,17 +25,17 @@ impl ColliderPair {
}
/// Constructs a pair of artificial handles that are not guaranteed to be valid..
- pub fn zero() -> Self {
+ pub fn invalid() -> Self {
Self {
- collider1: ColliderHandle::from_raw_parts(0, 0),
- collider2: ColliderHandle::from_raw_parts(0, 0),
+ collider1: ColliderHandle::PLACEHOLDER,
+ collider2: ColliderHandle::PLACEHOLDER,
}
}
}
impl Default for ColliderPair {
fn default() -> Self {
- ColliderPair::zero()
+ ColliderPair::invalid()
}
}
diff --git a/src/geometry/broad_phase_multi_sap/sap_axis.rs b/src/geometry/broad_phase_multi_sap/sap_axis.rs
index 2452148..28c0822 100644
--- a/src/geometry/broad_phase_multi_sap/sap_axis.rs
+++ b/src/geometry/broad_phase_multi_sap/sap_axis.rs
@@ -1,7 +1,7 @@
use super::{SAPEndpoint, SAPProxies, NUM_SENTINELS};
use crate::geometry::broad_phase_multi_sap::DELETED_AABB_VALUE;
use crate::geometry::SAPProxyIndex;
-use crate::math::Real;
+use crate::math::*;
use bit_vec::BitVec;
use parry::bounding_volume::BoundingVolume;
use parry::utils::hashmap::HashMap;
diff --git a/src/geometry/broad_phase_multi_sap/sap_endpoint.rs b/src/geometry/broad_phase_multi_sap/sap_endpoint.rs
index a57b8e9..482c046 100644
--- a/src/geometry/broad_phase_multi_sap/sap_endpoint.rs
+++ b/src/geometry/broad_phase_multi_sap/sap_endpoint.rs
@@ -1,5 +1,5 @@
use super::SENTINEL_VALUE;
-use crate::math::Real;
+use crate::math::*;
#[derive(Copy, Clone, Debug, PartialEq)]
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
diff --git a/src/geometry/broad_phase_multi_sap/sap_layer.rs b/src/geometry/broad_phase_multi_sap/sap_layer.rs
index 2266d56..a315cc7 100644
--- a/src/geometry/broad_phase_multi_sap/sap_layer.rs
+++ b/src/geometry/broad_phase_multi_sap/sap_layer.rs
@@ -1,7 +1,7 @@
use super::{SAPProxies, SAPProxy, SAPRegion, SAPRegionPool};
use crate::geometry::broad_phase_multi_sap::DELETED_AABB_VALUE;
use crate::geometry::{Aabb, SAPProxyIndex};
-use crate::math::{Point, Real};
+use crate::math::*;
use parry::bounding_volume::BoundingVolume;
use parry::utils::hashmap::{Entry, HashMap};
@@ -13,9 +13,9 @@ pub(crate) struct SAPLayer {
pub smaller_layer: Option<u8>,
pub larger_layer: Option<u8>,
region_width: Real,
- pub regions: HashMap<Point<i32>, SAPProxyIndex>,
+ pub regions: HashMap<[i32; DIM], SAPProxyIndex>,
#[cfg_attr(feature = "serde-serialize", serde(skip))]
- regions_to_potentially_remove: Vec<Point<i32>>, // Workspace
+ regions_to_potentially_remove: Vec<[i32; DIM]>, // Workspace
#[cfg_attr(feature = "serde-serialize", serde(skip))]
pub created_regions: Vec<SAPProxyIndex>,
}
@@ -188,7 +188,7 @@ impl SAPLayer {
/// of the new region if it did not exist and has been created by this method.
pub fn ensure_region_exists(
&mut self,
- region_key: Point<i32>,
+ region_key: [i32; DIM],
proxies: &mut SAPProxies,
pool: &mut SAPRegionPool,
) -> SAPProxyIndex {
@@ -227,15 +227,15 @@ impl SAPLayer {
#[cfg(feature = "dim2")]
let k_range = 0..1;
#[cfg(feature = "dim3")]
- let k_range = start.z..=end.z;
+ let k_range = start[2]..=end[2];
- for i in start.x..=end.x {
- for j in start.y..=end.y {
+ for i in start[0]..=end[0] {
+ for j in start[1]..=end[1] {
for _k in k_range.clone() {
#[cfg(feature = "dim2")]
- let region_key = Point::new(i, j);
+ let region_key = [i, j];
#[cfg(feature = "dim3")]
- let region_key = Point::new(i, j, _k);
+ let region_key = [i, j, _k];
let region_id = self.ensure_region_exists(region_key, proxies, pool);
let region_proxy = &mut proxies[region_id];
let region = region_proxy.data.as_region_mut();
@@ -273,21 +273,21 @@ impl SAPLayer {
let end = super::point_key(proxy_aabb.maxs, self.region_width);
// Set the Aabb of the proxy to a very large value.
- proxy_aabb.mins.coords.fill(DELETED_AABB_VALUE);
- proxy_aabb.maxs.coords.fill(DELETED_AABB_VALUE);
+ proxy_aabb.mins.as_vector_mut().fill(DELETED_AABB_VALUE);
+ proxy_aabb.maxs.as_vector_mut().fill(DELETED_AABB_VALUE);
#[cfg(feature = "dim2")]
let k_range = 0..1;
#[cfg(feature = "dim3")]
- let k_range = start.z..=end.z;
+ let k_range = start[2]..=end[2];
- for i in start.x..=end.x {
- for j in start.y..=end.y {
+ for i in start[0]..=end[0] {
+ for j in start[1]..=end[1] {
for _k in k_range.clone() {
#[cfg(feature = "dim2")]
- let key = Point::new(i, j);
+ let key = [i, j];
#[cfg(feature = "dim3")]
- let key = Point::new(i, j, _k);
+ let key = [i, j, _k];
if let Some(region_id) = self.regions.get(&key) {
let region = proxies[*region_id].data.as_region_mut();
region.predelete_proxy(proxy_index);
@@ -362,8 +362,8 @@ impl SAPLayer {
// Move the proxy to infinity.
let proxy = &mut proxies[region_id];
- proxy.aabb.mins.coords.fill(DELETED_AABB_VALUE);
- proxy.aabb.maxs.coords.fill(DELETED_AABB_VALUE);
+ proxy.aabb.mins.as_vector_mut().fill(DELETED_AABB_VALUE);
+ proxy.aabb.maxs.as_vector_mut().fill(DELETED_AABB_VALUE);
// Mark the proxy as deleted.
proxies.remove(region_id);
diff --git a/src/geometry/broad_phase_multi_sap/sap_utils.rs b/src/geometry/broad_phase_multi_sap/sap_utils.rs
index 56183eb..ec1f442 100644
--- a/src/geometry/broad_phase_multi_sap/sap_utils.rs
+++ b/src/geometry/broad_phase_multi_sap/sap_utils.rs
@@ -1,4 +1,4 @@
-use crate::math::{Point, Real, Vector};
+use crate::math::*;
use parry::bounding_volume::Aabb;
pub(crate) const NUM_SENTINELS: usize = 1;
@@ -19,19 +19,17 @@ pub(crate) fn sort2(a: u32, b: u32) -> (u32, u32) {
}
}
-pub(crate) fn clamp_point(point: Point<Real>) -> Point<Real> {
+pub(crate) fn clamp_point(point: Point) -> Point {
point.map(|e| na::clamp(e, -MAX_AABB_EXTENT, MAX_AABB_EXTENT))
}
-pub(crate) fn point_key(point: Point<Real>, region_width: Real) -> Point<i32> {
- (point / region_width)
- .coords
- .map(|e| e.floor() as i32)
- .into()
+pub(crate) fn point_key(point: Point, region_width: Real) -> [i32; DIM] {
+ let array: [Real; DIM] = (point / region_width).into_vector().into();
+ array.map(|e| e.floor() as i32)
}
-pub(crate) fn region_aabb(index: Point<i32>, region_width: Real) -> Aabb {
- let mins = index.coords.map(|i| i as Real * region_width).into();
+pub(crate) fn region_aabb(index: [i32; DIM], region_width: Real) -> Aabb {
+ let mins = index.map(|i| i as Real * region_width).into();
let maxs = mins + Vector::repeat(region_width);
Aabb::new(mins, maxs)
}
@@ -43,7 +41,7 @@ pub(crate) fn region_width(depth: i8) -> Real {
/// Computes the depth of the layer the given Aabb should be part of.
///
/// The idea here is that an Aabb should be part of a layer which has
-/// regions large enough so that one Aabb doesn't crosses too many
+/// regions large enough so that one Aabb doesn't cross too many
/// regions. But the regions must also not be too large, otherwise
/// we are loosing the benefits of Multi-SAP.
///