aboutsummaryrefslogtreecommitdiff
path: root/src/geometry/collider.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/collider.rs
parent865ce8a8e5301b23ca474adaaffe8b43e725803e (diff)
downloadrapier-d513c22d33ab44b0048355bcfd1db4173b3f7ece.tar.gz
rapier-d513c22d33ab44b0048355bcfd1db4173b3f7ece.tar.bz2
rapier-d513c22d33ab44b0048355bcfd1db4173b3f7ece.zip
Add cone support.
Diffstat (limited to 'src/geometry/collider.rs')
-rw-r--r--src/geometry/collider.rs29
1 files changed, 25 insertions, 4 deletions
diff --git a/src/geometry/collider.rs b/src/geometry/collider.rs
index c6cf6d0..f952b15 100644
--- a/src/geometry/collider.rs
+++ b/src/geometry/collider.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, Shape, ShapeType, Triangle, Trimesh,
+ Ball, Capsule, ColliderGraphIndex, Contact, Cuboid, HeightField, InteractionGraph, Polygon,
+ Proximity, Ray, RayIntersection, Shape, ShapeType, 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;
@@ -40,6 +40,13 @@ impl ColliderShape {
ColliderShape(Arc::new(Cylinder::new(half_height, radius)))
}
+ /// Initialize a cone shape defined by its half-height
+ /// (along along the y axis) and its basis radius.
+ #[cfg(feature = "dim3")]
+ pub fn cone(half_height: f32, radius: f32) -> Self {
+ ColliderShape(Arc::new(Cone::new(half_height, radius)))
+ }
+
/// Initialize a cuboid shape defined by its half-extents.
pub fn cuboid(half_extents: Vector<f32>) -> Self {
ColliderShape(Arc::new(Cuboid::new(half_extents)))
@@ -171,6 +178,13 @@ impl<'de> serde::Deserialize<'de> for ColliderShape {
.ok_or_else(|| serde::de::Error::invalid_length(0, &self))?;
Arc::new(shape) as Arc<dyn Shape>
}
+ #[cfg(feature = "dim3")]
+ Some(ShapeType::Cone) => {
+ let shape: Cone = seq
+ .next_element()?
+ .ok_or_else(|| serde::de::Error::invalid_length(0, &self))?;
+ Arc::new(shape) as Arc<dyn Shape>
+ }
None => {
return Err(serde::de::Error::custom(
"found invalid shape type to deserialize",
@@ -328,6 +342,13 @@ impl ColliderBuilder {
Self::new(ColliderShape::cylinder(half_height, radius))
}
+ /// Initialize a new collider builder with a cone shape defined by its half-height
+ /// (along along the y axis) and its basis radius.
+ #[cfg(feature = "dim3")]
+ pub fn cone(half_height: f32, radius: f32) -> Self {
+ Self::new(ColliderShape::cone(half_height, radius))
+ }
+
/// Initialize a new collider builder with a cuboid shape defined by its half-extents.
#[cfg(feature = "dim2")]
pub fn cuboid(hx: f32, hy: f32) -> Self {