From 865ce8a8e5301b23ca474adaaffe8b43e725803e Mon Sep 17 00:00:00 2001 From: Crozet Sébastien Date: Tue, 20 Oct 2020 11:55:33 +0200 Subject: Collider shape: use a trait-object instead of an enum. --- src/geometry/shape.rs | 275 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 275 insertions(+) create mode 100644 src/geometry/shape.rs (limited to 'src/geometry/shape.rs') diff --git a/src/geometry/shape.rs b/src/geometry/shape.rs new file mode 100644 index 0000000..c9e0a3a --- /dev/null +++ b/src/geometry/shape.rs @@ -0,0 +1,275 @@ +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, +}; +use crate::math::{AngVector, Isometry, Point, Rotation, Vector}; +use downcast_rs::{impl_downcast, DowncastSync}; +use erased_serde::Serialize; +use na::Point3; +use ncollide::bounding_volume::{HasBoundingVolume, AABB}; +use ncollide::query::{PointQuery, RayCast}; +use num::Zero; +use num_derive::FromPrimitive; +use std::any::Any; + +#[derive(Copy, Clone, Debug, FromPrimitive)] +/// Enum representing the type of a shape. +pub enum ShapeType { + /// A ball shape. + Ball = 1, + /// A convex polygon shape. + Polygon, + /// A cuboid shape. + Cuboid, + /// A capsule shape. + Capsule, + /// A triangle shape. + Triangle, + /// A triangle mesh shape. + Trimesh, + /// A heightfield shape. + HeightField, + #[cfg(feature = "dim3")] + /// A cylindrical shape. + Cylinder, + // /// A custom shape type. + // Custom(u8), +} + +/// Trait implemented by shapes usable by Rapier. +pub trait Shape: RayCast + PointQuery + DowncastSync { + /// Convert this shape as a serializable entity. + #[cfg(feature = "serde-serialize")] + fn as_serialize(&self) -> Option<&dyn Serialize> { + None + } + + /// Computes the AABB of this shape. + fn compute_aabb(&self, position: &Isometry) -> AABB; + + /// Compute the mass-properties of this shape given its uniform density. + fn mass_properties(&self, density: f32) -> MassProperties; + + /// Gets the type tag of this shape. + fn shape_type(&self) -> ShapeType; + + /// Converts this shape to a polygonal feature-map, if it is one. + #[cfg(feature = "dim3")] + fn as_polygonal_feature_map(&self) -> Option<&dyn PolygonalFeatureMap> { + None + } + + // fn as_rounded(&self) -> Option<&Rounded>> { + // None + // } +} + +impl_downcast!(sync Shape); + +impl dyn Shape { + /// Converts this abstract shape to a ball, if it is one. + pub fn as_ball(&self) -> Option<&Ball> { + self.downcast_ref() + } + + /// Converts this abstract shape to a cuboid, if it is one. + pub fn as_cuboid(&self) -> Option<&Cuboid> { + self.downcast_ref() + } + + /// Converts this abstract shape to a capsule, if it is one. + pub fn as_capsule(&self) -> Option<&Capsule> { + self.downcast_ref() + } + + /// Converts this abstract shape to a triangle, if it is one. + pub fn as_triangle(&self) -> Option<&Triangle> { + self.downcast_ref() + } + + /// Converts this abstract shape to a triangle mesh, if it is one. + pub fn as_trimesh(&self) -> Option<&Trimesh> { + self.downcast_ref() + } + + /// Converts this abstract shape to a heightfield, if it is one. + pub fn as_heightfield(&self) -> Option<&HeightField> { + self.downcast_ref() + } + + /// Converts this abstract shape to a cylinder, if it is one. + pub fn as_cylinder(&self) -> Option<&Cylinder> { + self.downcast_ref() + } +} + +impl Shape for Ball { + #[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_ball(density, self.radius) + } + + fn shape_type(&self) -> ShapeType { + ShapeType::Ball + } +} + +// impl Shape for Polygon { +// #[cfg(feature = "serde-serialize")] +// fn as_serialize(&self) -> Option<&dyn Serialize> { +// Some(self as &dyn Serialize) +// } +// +// fn compute_aabb(&self, position: &Isometry) -> AABB { +// self.aabb(position) +// } +// +// fn mass_properties(&self, _density: f32) -> MassProperties { +// unimplemented!() +// } +// +// fn shape_type(&self) -> ShapeType { +// ShapeType::Polygon +// } +// } + +impl Shape for Cuboid { + #[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_cuboid(density, self.half_extents) + } + + fn shape_type(&self) -> ShapeType { + ShapeType::Cuboid + } + + #[cfg(feature = "dim3")] + fn as_polygonal_feature_map(&self) -> Option<&dyn PolygonalFeatureMap> { + Some(self as &dyn PolygonalFeatureMap) + } +} + +impl Shape for Capsule { + #[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_capsule(density, self.half_height, self.radius) + } + + fn shape_type(&self) -> ShapeType { + ShapeType::Capsule + } +} + +impl Shape for Triangle { + #[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::zero() + } + + fn shape_type(&self) -> ShapeType { + ShapeType::Triangle + } + + #[cfg(feature = "dim3")] + fn as_polygonal_feature_map(&self) -> Option<&dyn PolygonalFeatureMap> { + Some(self as &dyn PolygonalFeatureMap) + } +} + +impl Shape for Trimesh { + #[cfg(feature = "serde-serialize")] + fn as_serialize(&self) -> Option<&dyn Serialize> { + Some(self as &dyn Serialize) + } + + fn compute_aabb(&self, position: &Isometry) -> AABB { + self.aabb(position) + } + + fn mass_properties(&self, _density: f32) -> MassProperties { + MassProperties::zero() + } + + fn shape_type(&self) -> ShapeType { + ShapeType::Trimesh + } +} + +impl Shape for HeightField { + #[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::zero() + } + + fn shape_type(&self) -> ShapeType { + ShapeType::HeightField + } +} + +#[cfg(feature = "dim3")] +impl Shape for Cylinder { + #[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_cylinder(density, self.half_height, self.radius) + } + + fn shape_type(&self) -> ShapeType { + ShapeType::Cylinder + } + + #[cfg(feature = "dim3")] + fn as_polygonal_feature_map(&self) -> Option<&dyn PolygonalFeatureMap> { + Some(self as &dyn PolygonalFeatureMap) + } +} -- cgit 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 From 64958470950cd9832a669b1bd5d70a2aeb6a85ef Mon Sep 17 00:00:00 2001 From: Crozet Sébastien Date: Tue, 20 Oct 2020 15:57:54 +0200 Subject: Add rounded cylinder. --- src/geometry/shape.rs | 68 ++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 57 insertions(+), 11 deletions(-) (limited to 'src/geometry/shape.rs') diff --git a/src/geometry/shape.rs b/src/geometry/shape.rs index b972a3e..822a5b0 100644 --- a/src/geometry/shape.rs +++ b/src/geometry/shape.rs @@ -1,7 +1,7 @@ use crate::dynamics::{MassProperties, RigidBodyHandle, RigidBodySet}; use crate::geometry::{ Ball, Capsule, ColliderGraphIndex, Contact, Cuboid, HeightField, InteractionGraph, Polygon, - Proximity, Ray, RayIntersection, Triangle, Trimesh, + Proximity, Ray, RayIntersection, Roundable, Rounded, Triangle, Trimesh, }; #[cfg(feature = "dim3")] use crate::geometry::{Cone, Cylinder, PolygonalFeatureMap}; @@ -9,7 +9,7 @@ use crate::math::{AngVector, Isometry, Point, Rotation, Vector}; use downcast_rs::{impl_downcast, DowncastSync}; use erased_serde::Serialize; use na::Point3; -use ncollide::bounding_volume::{HasBoundingVolume, AABB}; +use ncollide::bounding_volume::{BoundingVolume, HasBoundingVolume, AABB}; use ncollide::query::{PointQuery, RayCast}; use num::Zero; use num_derive::FromPrimitive; @@ -40,6 +40,18 @@ pub enum ShapeType { Cone, // /// A custom shape type. // Custom(u8), + // /// A cuboid with rounded corners. + // RoundedCuboid, + // /// A triangle with rounded corners. + // RoundedTriangle, + // /// A triangle-mesh with rounded corners. + // RoundedTrimesh, + // /// An heightfield with rounded corners. + // RoundedHeightField, + /// A cylinder with rounded corners. + RoundedCylinder, + // /// A cone with rounded corners. + // RoundedCone, } /// Trait implemented by shapes usable by Rapier. @@ -61,7 +73,7 @@ pub trait Shape: RayCast + PointQuery + DowncastSync { /// Converts this shape to a polygonal feature-map, if it is one. #[cfg(feature = "dim3")] - fn as_polygonal_feature_map(&self) -> Option<&dyn PolygonalFeatureMap> { + fn as_polygonal_feature_map(&self) -> Option<(&dyn PolygonalFeatureMap, f32)> { None } @@ -112,6 +124,15 @@ impl dyn Shape { pub fn as_cone(&self) -> Option<&Cone> { self.downcast_ref() } + + /// Converts this abstract shape to a cone, if it is one. + pub fn as_rounded(&self) -> Option<&Rounded> + where + S: Roundable, + Rounded: Shape, + { + self.downcast_ref() + } } impl Shape for Ball { @@ -171,8 +192,8 @@ impl Shape for Cuboid { } #[cfg(feature = "dim3")] - fn as_polygonal_feature_map(&self) -> Option<&dyn PolygonalFeatureMap> { - Some(self as &dyn PolygonalFeatureMap) + fn as_polygonal_feature_map(&self) -> Option<(&dyn PolygonalFeatureMap, f32)> { + Some((self as &dyn PolygonalFeatureMap, 0.0)) } } @@ -214,8 +235,8 @@ impl Shape for Triangle { } #[cfg(feature = "dim3")] - fn as_polygonal_feature_map(&self) -> Option<&dyn PolygonalFeatureMap> { - Some(self as &dyn PolygonalFeatureMap) + fn as_polygonal_feature_map(&self) -> Option<(&dyn PolygonalFeatureMap, f32)> { + Some((self as &dyn PolygonalFeatureMap, 0.0)) } } @@ -277,8 +298,8 @@ impl Shape for Cylinder { } #[cfg(feature = "dim3")] - fn as_polygonal_feature_map(&self) -> Option<&dyn PolygonalFeatureMap> { - Some(self as &dyn PolygonalFeatureMap) + fn as_polygonal_feature_map(&self) -> Option<(&dyn PolygonalFeatureMap, f32)> { + Some((self as &dyn PolygonalFeatureMap, 0.0)) } } @@ -302,7 +323,32 @@ impl Shape for Cone { } #[cfg(feature = "dim3")] - fn as_polygonal_feature_map(&self) -> Option<&dyn PolygonalFeatureMap> { - Some(self as &dyn PolygonalFeatureMap) + fn as_polygonal_feature_map(&self) -> Option<(&dyn PolygonalFeatureMap, f32)> { + Some((self as &dyn PolygonalFeatureMap, 0.0)) + } +} + +#[cfg(feature = "dim3")] +impl Shape for Rounded { + fn as_serialize(&self) -> Option<&dyn Serialize> { + Some(self as &dyn Serialize) + } + + fn compute_aabb(&self, position: &Isometry) -> AABB { + self.shape.compute_aabb(position).loosened(self.radius) + } + + fn mass_properties(&self, density: f32) -> MassProperties { + // We ignore the margin here. + self.shape.mass_properties(density) + } + + fn shape_type(&self) -> ShapeType { + ShapeType::RoundedCylinder + } + + #[cfg(feature = "dim3")] + fn as_polygonal_feature_map(&self) -> Option<(&dyn PolygonalFeatureMap, f32)> { + Some((&self.shape as &dyn PolygonalFeatureMap, self.radius)) } } -- cgit From 949e3f5384a366c3bff5415c5db4635e811a580e Mon Sep 17 00:00:00 2001 From: Crozet Sébastien Date: Tue, 20 Oct 2020 16:22:53 +0200 Subject: Fix many warnings. --- src/geometry/shape.rs | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) (limited to 'src/geometry/shape.rs') diff --git a/src/geometry/shape.rs b/src/geometry/shape.rs index 822a5b0..b6350e9 100644 --- a/src/geometry/shape.rs +++ b/src/geometry/shape.rs @@ -1,19 +1,17 @@ -use crate::dynamics::{MassProperties, RigidBodyHandle, RigidBodySet}; -use crate::geometry::{ - Ball, Capsule, ColliderGraphIndex, Contact, Cuboid, HeightField, InteractionGraph, Polygon, - Proximity, Ray, RayIntersection, Roundable, Rounded, Triangle, Trimesh, -}; -#[cfg(feature = "dim3")] -use crate::geometry::{Cone, Cylinder, PolygonalFeatureMap}; -use crate::math::{AngVector, Isometry, Point, Rotation, Vector}; +use crate::dynamics::MassProperties; +use crate::geometry::{Ball, Capsule, Cuboid, HeightField, Roundable, Rounded, Triangle, Trimesh}; +use crate::math::Isometry; use downcast_rs::{impl_downcast, DowncastSync}; use erased_serde::Serialize; -use na::Point3; -use ncollide::bounding_volume::{BoundingVolume, HasBoundingVolume, AABB}; +use ncollide::bounding_volume::{HasBoundingVolume, AABB}; use ncollide::query::{PointQuery, RayCast}; use num::Zero; use num_derive::FromPrimitive; -use std::any::Any; +#[cfg(feature = "dim3")] +use { + crate::geometry::{Cone, Cylinder, PolygonalFeatureMap}, + ncollide::bounding_volume::BoundingVolume, +}; #[derive(Copy, Clone, Debug, FromPrimitive)] /// Enum representing the type of a shape. @@ -49,6 +47,7 @@ pub enum ShapeType { // /// An heightfield with rounded corners. // RoundedHeightField, /// A cylinder with rounded corners. + #[cfg(feature = "dim3")] RoundedCylinder, // /// A cone with rounded corners. // RoundedCone, @@ -116,11 +115,13 @@ impl dyn Shape { } /// Converts this abstract shape to a cylinder, if it is one. + #[cfg(feature = "dim3")] pub fn as_cylinder(&self) -> Option<&Cylinder> { self.downcast_ref() } /// Converts this abstract shape to a cone, if it is one. + #[cfg(feature = "dim3")] pub fn as_cone(&self) -> Option<&Cone> { self.downcast_ref() } @@ -226,7 +227,7 @@ impl Shape for Triangle { self.bounding_volume(position) } - fn mass_properties(&self, density: f32) -> MassProperties { + fn mass_properties(&self, _density: f32) -> MassProperties { MassProperties::zero() } -- cgit From f7a6f433d62ea427f6e2233365a6f534ca7e1c63 Mon Sep 17 00:00:00 2001 From: Crozet Sébastien Date: Tue, 20 Oct 2020 18:14:20 +0200 Subject: Rename rounded -> round. --- src/geometry/shape.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/geometry/shape.rs') diff --git a/src/geometry/shape.rs b/src/geometry/shape.rs index b6350e9..80c9b51 100644 --- a/src/geometry/shape.rs +++ b/src/geometry/shape.rs @@ -48,7 +48,7 @@ pub enum ShapeType { // RoundedHeightField, /// A cylinder with rounded corners. #[cfg(feature = "dim3")] - RoundedCylinder, + RoundCylinder, // /// A cone with rounded corners. // RoundedCone, } @@ -345,7 +345,7 @@ impl Shape for Rounded { } fn shape_type(&self) -> ShapeType { - ShapeType::RoundedCylinder + ShapeType::RoundCylinder } #[cfg(feature = "dim3")] -- cgit From 2b628f9580a826722346983ef42672d4e8dd8053 Mon Sep 17 00:00:00 2001 From: Crozet Sébastien Date: Mon, 26 Oct 2020 15:58:30 +0100 Subject: Redefine capsules as a segment with a radius, allowing us to reuse the pfm_pfm_contact generator for it. --- src/geometry/shape.rs | 38 +++++++++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) (limited to 'src/geometry/shape.rs') 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) -> AABB { - 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) -> AABB { + 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> { -- cgit From 12e85e0dc26bc0c6ebc00c52549fdacd4752c9fd Mon Sep 17 00:00:00 2001 From: Crozet Sébastien Date: Mon, 26 Oct 2020 16:12:32 +0100 Subject: AddAdd missing feature-gate. --- src/geometry/shape.rs | 1 + 1 file changed, 1 insertion(+) (limited to 'src/geometry/shape.rs') diff --git a/src/geometry/shape.rs b/src/geometry/shape.rs index 8f7997e..3f1ca04 100644 --- a/src/geometry/shape.rs +++ b/src/geometry/shape.rs @@ -4,6 +4,7 @@ use crate::geometry::{ }; use crate::math::Isometry; use downcast_rs::{impl_downcast, DowncastSync}; +#[cfg(feature = "serde-serialize")] use erased_serde::Serialize; use ncollide::bounding_volume::{HasBoundingVolume, AABB}; use ncollide::query::{PointQuery, RayCast}; -- cgit From 3fd4a62a2e4d6f5d97412bf80561c23ba43e40a5 Mon Sep 17 00:00:00 2001 From: Crozet Sébastien Date: Mon, 26 Oct 2020 16:18:44 +0100 Subject: Fix 2D compilation. --- src/geometry/shape.rs | 1 + 1 file changed, 1 insertion(+) (limited to 'src/geometry/shape.rs') diff --git a/src/geometry/shape.rs b/src/geometry/shape.rs index 3f1ca04..54a156b 100644 --- a/src/geometry/shape.rs +++ b/src/geometry/shape.rs @@ -221,6 +221,7 @@ impl Shape for Capsule { ShapeType::Capsule } + #[cfg(feature = "dim3")] fn as_polygonal_feature_map(&self) -> Option<(&dyn PolygonalFeatureMap, f32)> { Some((&self.segment as &dyn PolygonalFeatureMap, self.radius)) } -- cgit From ba6655be8e4b781bfaac06282e1c7d53a56111f5 Mon Sep 17 00:00:00 2001 From: Crozet Sébastien Date: Mon, 26 Oct 2020 16:24:58 +0100 Subject: Fix build when serialization is not enabled. --- src/geometry/shape.rs | 1 + 1 file changed, 1 insertion(+) (limited to 'src/geometry/shape.rs') diff --git a/src/geometry/shape.rs b/src/geometry/shape.rs index 54a156b..8f40fd4 100644 --- a/src/geometry/shape.rs +++ b/src/geometry/shape.rs @@ -365,6 +365,7 @@ impl Shape for Cone { #[cfg(feature = "dim3")] impl Shape for Rounded { + #[cfg(feature = "serde-serialize")] fn as_serialize(&self) -> Option<&dyn Serialize> { Some(self as &dyn Serialize) } -- cgit From 8c872dc0af9ece127a87b4adb112b0e1ed6ab249 Mon Sep 17 00:00:00 2001 From: Crozet Sébastien Date: Tue, 27 Oct 2020 09:20:40 +0100 Subject: Replace the Rounded type by a non-generic RoundCylinder type. --- src/geometry/shape.rs | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) (limited to 'src/geometry/shape.rs') diff --git a/src/geometry/shape.rs b/src/geometry/shape.rs index 8f40fd4..982e484 100644 --- a/src/geometry/shape.rs +++ b/src/geometry/shape.rs @@ -1,6 +1,6 @@ use crate::dynamics::MassProperties; use crate::geometry::{ - Ball, Capsule, Cuboid, HeightField, Roundable, Rounded, Segment, Triangle, Trimesh, + Ball, Capsule, Cuboid, HeightField, RoundCylinder, Segment, Triangle, Trimesh, }; use crate::math::Isometry; use downcast_rs::{impl_downcast, DowncastSync}; @@ -132,11 +132,8 @@ impl dyn Shape { } /// Converts this abstract shape to a cone, if it is one. - pub fn as_rounded(&self) -> Option<&Rounded> - where - S: Roundable, - Rounded: Shape, - { + #[cfg(feature = "dim3")] + pub fn as_round_cylinder(&self) -> Option<&RoundCylinder> { self.downcast_ref() } } @@ -364,19 +361,21 @@ impl Shape for Cone { } #[cfg(feature = "dim3")] -impl Shape for Rounded { +impl Shape for RoundCylinder { #[cfg(feature = "serde-serialize")] fn as_serialize(&self) -> Option<&dyn Serialize> { Some(self as &dyn Serialize) } fn compute_aabb(&self, position: &Isometry) -> AABB { - self.shape.compute_aabb(position).loosened(self.radius) + self.cylinder + .compute_aabb(position) + .loosened(self.border_radius) } fn mass_properties(&self, density: f32) -> MassProperties { // We ignore the margin here. - self.shape.mass_properties(density) + self.cylinder.mass_properties(density) } fn shape_type(&self) -> ShapeType { @@ -385,6 +384,9 @@ impl Shape for Rounded { #[cfg(feature = "dim3")] fn as_polygonal_feature_map(&self) -> Option<(&dyn PolygonalFeatureMap, f32)> { - Some((&self.shape as &dyn PolygonalFeatureMap, self.radius)) + Some(( + &self.cylinder as &dyn PolygonalFeatureMap, + self.border_radius, + )) } } -- cgit From ffbc3c02c7d328d5c48a3efb84d35f5911f1880b Mon Sep 17 00:00:00 2001 From: Crozet Sébastien Date: Tue, 27 Oct 2020 09:25:58 +0100 Subject: Fix 2D compilation. --- src/geometry/shape.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'src/geometry/shape.rs') diff --git a/src/geometry/shape.rs b/src/geometry/shape.rs index 982e484..ec43bf7 100644 --- a/src/geometry/shape.rs +++ b/src/geometry/shape.rs @@ -1,7 +1,5 @@ use crate::dynamics::MassProperties; -use crate::geometry::{ - Ball, Capsule, Cuboid, HeightField, RoundCylinder, Segment, Triangle, Trimesh, -}; +use crate::geometry::{Ball, Capsule, Cuboid, HeightField, Segment, Triangle, Trimesh}; use crate::math::Isometry; use downcast_rs::{impl_downcast, DowncastSync}; #[cfg(feature = "serde-serialize")] @@ -12,7 +10,7 @@ use num::Zero; use num_derive::FromPrimitive; #[cfg(feature = "dim3")] use { - crate::geometry::{Cone, Cylinder, PolygonalFeatureMap}, + crate::geometry::{Cone, Cylinder, PolygonalFeatureMap, RoundCylinder}, ncollide::bounding_volume::BoundingVolume, }; -- cgit