From d513c22d33ab44b0048355bcfd1db4173b3f7ece Mon Sep 17 00:00:00 2001 From: Crozet Sébastien Date: Tue, 20 Oct 2020 14:16:01 +0200 Subject: Add cone support. --- src/geometry/shape.rs | 41 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 37 insertions(+), 4 deletions(-) (limited to 'src/geometry/shape.rs') 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) -> AABB { + 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) + } +} -- cgit