aboutsummaryrefslogtreecommitdiff
path: root/src/geometry/collider.rs
diff options
context:
space:
mode:
authorCrozet Sébastien <developer@crozet.re>2020-10-26 15:58:30 +0100
committerCrozet Sébastien <developer@crozet.re>2020-10-26 15:58:30 +0100
commit2b628f9580a826722346983ef42672d4e8dd8053 (patch)
tree9e72cc1645140eda69696eedb3c245fb667eb540 /src/geometry/collider.rs
parent3da333f11c93898808eb9233c0cf333743bbf906 (diff)
downloadrapier-2b628f9580a826722346983ef42672d4e8dd8053.tar.gz
rapier-2b628f9580a826722346983ef42672d4e8dd8053.tar.bz2
rapier-2b628f9580a826722346983ef42672d4e8dd8053.zip
Redefine capsules as a segment with a radius, allowing us to reuse the pfm_pfm_contact generator for it.
Diffstat (limited to 'src/geometry/collider.rs')
-rw-r--r--src/geometry/collider.rs35
1 files changed, 17 insertions, 18 deletions
diff --git a/src/geometry/collider.rs b/src/geometry/collider.rs
index 838dda2..ae5cc73 100644
--- a/src/geometry/collider.rs
+++ b/src/geometry/collider.rs
@@ -1,7 +1,7 @@
use crate::dynamics::{MassProperties, RigidBodyHandle, RigidBodySet};
use crate::geometry::{
Ball, Capsule, ColliderGraphIndex, Contact, Cuboid, HeightField, InteractionGraph, Proximity,
- Shape, ShapeType, Triangle, Trimesh,
+ Segment, Shape, ShapeType, Triangle, Trimesh,
};
#[cfg(feature = "dim3")]
use crate::geometry::{Cone, Cylinder, PolygonalFeatureMap, Rounded};
@@ -58,9 +58,14 @@ impl ColliderShape {
ColliderShape(Arc::new(Cuboid::new(half_extents)))
}
- /// Initialize a capsule shape aligned with the `y` axis.
- pub fn capsule(half_height: f32, radius: f32) -> Self {
- ColliderShape(Arc::new(Capsule::new(half_height, radius)))
+ /// Initialize a capsule shape from its endpoints and radius.
+ pub fn capsule(a: Point<f32>, b: Point<f32>, radius: f32) -> Self {
+ ColliderShape(Arc::new(Capsule::new(a, b, radius)))
+ }
+
+ /// Initialize a segment shape from its endpoints.
+ pub fn segment(a: Point<f32>, b: Point<f32>) -> Self {
+ ColliderShape(Arc::new(Segment::new(a, b)))
}
/// Initializes a triangle shape.
@@ -157,6 +162,7 @@ impl<'de> serde::Deserialize<'de> for ColliderShape {
Some(ShapeType::Cuboid) => deser::<A, Cuboid>(&mut seq)?,
Some(ShapeType::Capsule) => deser::<A, Capsule>(&mut seq)?,
Some(ShapeType::Triangle) => deser::<A, Triangle>(&mut seq)?,
+ Some(ShapeType::Segment) => deser::<A, Segment>(&mut seq)?,
Some(ShapeType::Trimesh) => deser::<A, Trimesh>(&mut seq)?,
Some(ShapeType::HeightField) => deser::<A, HeightField>(&mut seq)?,
#[cfg(feature = "dim3")]
@@ -349,25 +355,21 @@ impl ColliderBuilder {
/// Initialize a new collider builder with a capsule shape aligned with the `x` axis.
pub fn capsule_x(half_height: f32, radius: f32) -> Self {
- #[cfg(feature = "dim2")]
- let rot = -std::f32::consts::FRAC_PI_2;
- #[cfg(feature = "dim3")]
- let rot = Vector::z() * -std::f32::consts::FRAC_PI_2;
- Self::new(ColliderShape::capsule(half_height, radius))
- .position(Isometry::new(na::zero(), rot))
+ let p = Point::from(Vector::x() * half_height);
+ Self::new(ColliderShape::capsule(-p, p, radius))
}
/// Initialize a new collider builder with a capsule shape aligned with the `y` axis.
pub fn capsule_y(half_height: f32, radius: f32) -> Self {
- Self::new(ColliderShape::capsule(half_height, radius))
+ let p = Point::from(Vector::y() * half_height);
+ Self::new(ColliderShape::capsule(-p, p, radius))
}
/// Initialize a new collider builder with a capsule shape aligned with the `z` axis.
#[cfg(feature = "dim3")]
pub fn capsule_z(half_height: f32, radius: f32) -> Self {
- let rot = Vector::x() * std::f32::consts::FRAC_PI_2;
- Self::new(ColliderShape::capsule(half_height, radius))
- .position(Isometry::new(na::zero(), rot))
+ let p = Point::from(Vector::z() * half_height);
+ Self::new(ColliderShape::capsule(-p, p, radius))
}
/// Initialize a new collider builder with a cuboid shape defined by its half-extents.
@@ -377,11 +379,8 @@ impl ColliderBuilder {
}
/// Initializes a collider builder with a segment shape.
- ///
- /// A segment shape is modeled by a capsule with a 0 radius.
pub fn segment(a: Point<f32>, b: Point<f32>) -> Self {
- let (pos, half_height) = crate::utils::segment_to_capsule(&a, &b);
- Self::new(ColliderShape::capsule(half_height, 0.0)).position(pos)
+ Self::new(ColliderShape::segment(a, b))
}
/// Initializes a collider builder with a triangle shape.