aboutsummaryrefslogtreecommitdiff
path: root/src/geometry/shape.rs
diff options
context:
space:
mode:
authorCrozet Sébastien <developer@crozet.re>2020-10-20 14:16:01 +0200
committerCrozet Sébastien <developer@crozet.re>2020-10-20 14:16:01 +0200
commitd513c22d33ab44b0048355bcfd1db4173b3f7ece (patch)
tree274f768c6798d9564483c86a423f131be4750360 /src/geometry/shape.rs
parent865ce8a8e5301b23ca474adaaffe8b43e725803e (diff)
downloadrapier-d513c22d33ab44b0048355bcfd1db4173b3f7ece.tar.gz
rapier-d513c22d33ab44b0048355bcfd1db4173b3f7ece.tar.bz2
rapier-d513c22d33ab44b0048355bcfd1db4173b3f7ece.zip
Add cone support.
Diffstat (limited to 'src/geometry/shape.rs')
-rw-r--r--src/geometry/shape.rs41
1 files changed, 37 insertions, 4 deletions
diff --git a/src/geometry/shape.rs b/src/geometry/shape.rs
index c9e0a3a..b972a3e 100644
--- a/src/geometry/shape.rs
+++ b/src/geometry/shape.rs
@@ -1,10 +1,10 @@
use crate::dynamics::{MassProperties, RigidBodyHandle, RigidBodySet};
-#[cfg(feature = "dim3")]
-use crate::geometry::PolygonalFeatureMap;
use crate::geometry::{
- Ball, Capsule, ColliderGraphIndex, Contact, Cuboid, Cylinder, HeightField, InteractionGraph,
- Polygon, Proximity, Ray, RayIntersection, Triangle, Trimesh,
+ Ball, Capsule, ColliderGraphIndex, Contact, Cuboid, HeightField, InteractionGraph, Polygon,
+ Proximity, Ray, RayIntersection, Triangle, Trimesh,
};
+#[cfg(feature = "dim3")]
+use crate::geometry::{Cone, Cylinder, PolygonalFeatureMap};
use crate::math::{AngVector, Isometry, Point, Rotation, Vector};
use downcast_rs::{impl_downcast, DowncastSync};
use erased_serde::Serialize;
@@ -35,6 +35,9 @@ pub enum ShapeType {
#[cfg(feature = "dim3")]
/// A cylindrical shape.
Cylinder,
+ #[cfg(feature = "dim3")]
+ /// A cylindrical shape.
+ Cone,
// /// A custom shape type.
// Custom(u8),
}
@@ -104,6 +107,11 @@ impl dyn Shape {
pub fn as_cylinder(&self) -> Option<&Cylinder> {
self.downcast_ref()
}
+
+ /// Converts this abstract shape to a cone, if it is one.
+ pub fn as_cone(&self) -> Option<&Cone> {
+ self.downcast_ref()
+ }
}
impl Shape for Ball {
@@ -273,3 +281,28 @@ impl Shape for Cylinder {
Some(self as &dyn PolygonalFeatureMap)
}
}
+
+#[cfg(feature = "dim3")]
+impl Shape for Cone {
+ #[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::from_cone(density, self.half_height, self.radius)
+ }
+
+ fn shape_type(&self) -> ShapeType {
+ ShapeType::Cone
+ }
+
+ #[cfg(feature = "dim3")]
+ fn as_polygonal_feature_map(&self) -> Option<&dyn PolygonalFeatureMap> {
+ Some(self as &dyn PolygonalFeatureMap)
+ }
+}