diff options
| author | Crozet Sébastien <developer@crozet.re> | 2020-10-26 15:58:30 +0100 |
|---|---|---|
| committer | Crozet Sébastien <developer@crozet.re> | 2020-10-26 15:58:30 +0100 |
| commit | 2b628f9580a826722346983ef42672d4e8dd8053 (patch) | |
| tree | 9e72cc1645140eda69696eedb3c245fb667eb540 /src/geometry/shape.rs | |
| parent | 3da333f11c93898808eb9233c0cf333743bbf906 (diff) | |
| download | rapier-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/shape.rs')
| -rw-r--r-- | src/geometry/shape.rs | 38 |
1 files changed, 35 insertions, 3 deletions
diff --git a/src/geometry/shape.rs b/src/geometry/shape.rs index 80c9b51..8f7997e 100644 --- a/src/geometry/shape.rs +++ b/src/geometry/shape.rs @@ -1,5 +1,7 @@ use crate::dynamics::MassProperties; -use crate::geometry::{Ball, Capsule, Cuboid, HeightField, Roundable, Rounded, Triangle, Trimesh}; +use crate::geometry::{ + Ball, Capsule, Cuboid, HeightField, Roundable, Rounded, Segment, Triangle, Trimesh, +}; use crate::math::Isometry; use downcast_rs::{impl_downcast, DowncastSync}; use erased_serde::Serialize; @@ -24,6 +26,8 @@ pub enum ShapeType { Cuboid, /// A capsule shape. Capsule, + /// A segment shape. + Segment, /// A triangle shape. Triangle, /// A triangle mesh shape. @@ -205,16 +209,20 @@ impl Shape for Capsule { } fn compute_aabb(&self, position: &Isometry<f32>) -> AABB<f32> { - self.bounding_volume(position) + self.aabb(position) } fn mass_properties(&self, density: f32) -> MassProperties { - MassProperties::from_capsule(density, self.half_height, self.radius) + MassProperties::from_capsule(density, self.segment.a, self.segment.b, self.radius) } fn shape_type(&self) -> ShapeType { ShapeType::Capsule } + + fn as_polygonal_feature_map(&self) -> Option<(&dyn PolygonalFeatureMap, f32)> { + Some((&self.segment as &dyn PolygonalFeatureMap, self.radius)) + } } impl Shape for Triangle { @@ -241,6 +249,30 @@ impl Shape for Triangle { } } +impl Shape for Segment { + #[cfg(feature = "serde-serialize")] + fn as_serialize(&self) -> Option<&dyn Serialize> { + Some(self as &dyn Serialize) + } + + fn compute_aabb(&self, position: &Isometry<f32>) -> AABB<f32> { + self.bounding_volume(position) + } + + fn mass_properties(&self, _density: f32) -> MassProperties { + MassProperties::zero() + } + + fn shape_type(&self) -> ShapeType { + ShapeType::Segment + } + + #[cfg(feature = "dim3")] + fn as_polygonal_feature_map(&self) -> Option<(&dyn PolygonalFeatureMap, f32)> { + Some((self as &dyn PolygonalFeatureMap, 0.0)) + } +} + impl Shape for Trimesh { #[cfg(feature = "serde-serialize")] fn as_serialize(&self) -> Option<&dyn Serialize> { |
