-
-
Notifications
You must be signed in to change notification settings - Fork 261
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
126 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
use crate::{ | ||
parry::{self, shape::Shape, query::{Unsupported, Contact}}, | ||
prelude::*, | ||
utils::pos_rot_to_iso, | ||
}; | ||
|
||
/// Results from [`closest_points`] | ||
pub enum ClosestPoints { | ||
/// The two objects are intersecting. | ||
Intersecting, | ||
/// The two objects are non-intersecting but closer than a given user-defined distance. | ||
WithinMargin(Vect, Vect), | ||
/// The two objects are non-intersecting and further than a given user-defined distance. | ||
Disjoint, | ||
} | ||
|
||
use parry::query::closest_points::ClosestPoints as ParryClosestPoints; | ||
impl From<ParryClosestPoints> for ClosestPoints { | ||
fn from(parry: ParryClosestPoints) -> ClosestPoints { | ||
match parry { | ||
ParryClosestPoints::Intersecting => ClosestPoints::Intersecting, | ||
ParryClosestPoints::Disjoint => ClosestPoints::Disjoint, | ||
ParryClosestPoints::WithinMargin(p1, p2) => { | ||
ClosestPoints::WithinMargin(p1.into(), p2.into()) | ||
} | ||
} | ||
} | ||
} | ||
|
||
/// Computes the pair of closest points between two shapes. | ||
/// | ||
/// Returns `ClosestPoints::Disjoint` if the objects are separated by a distance greater than `max_dist`. The result points in `ClosestPoints::WithinMargin` are expressed in world-space. | ||
pub fn closest_points( | ||
pos1: Vect, | ||
rot1: Rot, | ||
shape1: &dyn Shape, | ||
pos2: Vect, | ||
rot2: Rot, | ||
shape2: &dyn Shape, | ||
max_dist: Real, | ||
physics_scale: Real, | ||
) -> Result<ClosestPoints, Unsupported> { | ||
let iso1 = pos_rot_to_iso(pos1, rot1, physics_scale); | ||
let iso2 = pos_rot_to_iso(pos2, rot2, physics_scale); | ||
|
||
parry::query::closest_points(&iso1, shape1, &iso2, shape2, max_dist) | ||
.map(|parry| parry.into()) | ||
} | ||
|
||
/// Computes the minimum distance separating two shapes. | ||
/// | ||
/// Returns 0.0 if the objects are touching or penetrating. | ||
pub fn distance( | ||
pos1: Vect, | ||
rot1: Rot, | ||
shape1: &dyn Shape, | ||
pos2: Vect, | ||
rot2: Rot, | ||
shape2: &dyn Shape, | ||
physics_scale: Real, | ||
) -> Result<Real, Unsupported> { | ||
let iso1 = pos_rot_to_iso(pos1, rot1, physics_scale); | ||
let iso2 = pos_rot_to_iso(pos2, rot2, physics_scale); | ||
|
||
parry::query::distance(&iso1, shape1, &iso2, shape2) | ||
} | ||
|
||
/// Computes one pair of contact points point between two shapes. | ||
/// | ||
/// Returns None if the objects are separated by a distance greater than prediction. The result is given in world-space. | ||
pub fn contact( | ||
pos1: Vect, | ||
rot1: Rot, | ||
shape1: &dyn Shape, | ||
pos2: Vect, | ||
rot2: Rot, | ||
shape2: &dyn Shape, | ||
prediction: Real, | ||
physics_scale: Real, | ||
) -> Result<Option<Contact>, Unsupported> { | ||
let iso1 = pos_rot_to_iso(pos1, rot1, physics_scale); | ||
let iso2 = pos_rot_to_iso(pos2, rot2, physics_scale); | ||
|
||
parry::query::contact(&iso1, shape1, &iso2, shape2, prediction) | ||
} | ||
|
||
/// Tests whether two shapes are intersecting. | ||
pub fn intersection_test( | ||
pos1: Vect, | ||
rot1: Rot, | ||
shape1: &dyn Shape, | ||
pos2: Vect, | ||
rot2: Rot, | ||
shape2: &dyn Shape, | ||
physics_scale: Real, | ||
) -> Result<bool, Unsupported> { | ||
let iso1 = pos_rot_to_iso(pos1, rot1, physics_scale); | ||
let iso2 = pos_rot_to_iso(pos2, rot2, physics_scale); | ||
|
||
parry::query::intersection_test(&iso1, shape1, &iso2, shape2) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters