From 9bf1321f8f1d2e116f44c2461a53f302c4ef4171 Mon Sep 17 00:00:00 2001 From: Crozet Sébastien Date: Tue, 8 Dec 2020 17:31:49 +0100 Subject: Outsource the contact manifold, SAT, and some shapes. --- src/geometry/round_cylinder.rs | 49 +++++++++++++++--------------------------- 1 file changed, 17 insertions(+), 32 deletions(-) (limited to 'src/geometry/round_cylinder.rs') diff --git a/src/geometry/round_cylinder.rs b/src/geometry/round_cylinder.rs index ce8b43b..450a9fc 100644 --- a/src/geometry/round_cylinder.rs +++ b/src/geometry/round_cylinder.rs @@ -1,10 +1,10 @@ use crate::geometry::Cylinder; use crate::math::{Isometry, Point, Vector}; -use na::Unit; -use ncollide::query::{ - algorithms::VoronoiSimplex, PointProjection, PointQuery, Ray, RayCast, RayIntersection, +use buckler::query::{ + gjk::VoronoiSimplex, PointProjection, PointQuery, Ray, RayCast, RayIntersection, }; -use ncollide::shape::{FeatureId, SupportMap}; +use buckler::shape::{FeatureId, SupportMap}; +use na::Unit; /// A rounded cylinder. #[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))] @@ -28,7 +28,7 @@ impl RoundCylinder { } } -impl SupportMap for RoundCylinder { +impl SupportMap for RoundCylinder { fn local_support_point(&self, dir: &Vector) -> Point { self.local_support_point_toward(&Unit::new_normalize(*dir)) } @@ -52,43 +52,29 @@ impl SupportMap for RoundCylinder { } } -impl RayCast for RoundCylinder { - fn toi_and_normal_with_ray( +impl RayCast for RoundCylinder { + fn cast_local_ray_and_get_normal( &self, - m: &Isometry, - ray: &Ray, + ray: &Ray, max_toi: f32, solid: bool, - ) -> Option> { - let ls_ray = ray.inverse_transform_by(m); - - ncollide::query::ray_intersection_with_support_map_with_params( - &Isometry::identity(), + ) -> Option { + buckler::query::details::local_ray_intersection_with_support_map_with_params( self, &mut VoronoiSimplex::new(), - &ls_ray, + ray, max_toi, solid, ) - .map(|mut res| { - res.normal = m * res.normal; - res - }) } } // TODO: if PointQuery had a `project_point_with_normal` method, we could just // call this and adjust the projected point accordingly. -impl PointQuery for RoundCylinder { +impl PointQuery for RoundCylinder { #[inline] - fn project_point( - &self, - m: &Isometry, - point: &Point, - solid: bool, - ) -> PointProjection { - ncollide::query::point_projection_on_support_map( - m, + fn project_local_point(&self, point: &Point, solid: bool) -> PointProjection { + buckler::query::details::local_point_projection_on_support_map( self, &mut VoronoiSimplex::new(), point, @@ -97,11 +83,10 @@ impl PointQuery for RoundCylinder { } #[inline] - fn project_point_with_feature( + fn project_local_point_and_get_feature( &self, - m: &Isometry, point: &Point, - ) -> (PointProjection, FeatureId) { - (self.project_point(m, point, false), FeatureId::Unknown) + ) -> (PointProjection, FeatureId) { + (self.project_local_point(point, false), FeatureId::Unknown) } } -- cgit From cc6d1b973002b4d366bc81ec6bf9e8240ad7b404 Mon Sep 17 00:00:00 2001 From: Crozet Sébastien Date: Mon, 14 Dec 2020 15:51:43 +0100 Subject: Outsource the Shape trait, wquadtree, and shape types. --- src/geometry/round_cylinder.rs | 92 ------------------------------------------ 1 file changed, 92 deletions(-) delete mode 100644 src/geometry/round_cylinder.rs (limited to 'src/geometry/round_cylinder.rs') diff --git a/src/geometry/round_cylinder.rs b/src/geometry/round_cylinder.rs deleted file mode 100644 index 450a9fc..0000000 --- a/src/geometry/round_cylinder.rs +++ /dev/null @@ -1,92 +0,0 @@ -use crate::geometry::Cylinder; -use crate::math::{Isometry, Point, Vector}; -use buckler::query::{ - gjk::VoronoiSimplex, PointProjection, PointQuery, Ray, RayCast, RayIntersection, -}; -use buckler::shape::{FeatureId, SupportMap}; -use na::Unit; - -/// A rounded cylinder. -#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))] -#[derive(Copy, Clone, Debug)] -pub struct RoundCylinder { - /// The cylinder being rounded. - pub cylinder: Cylinder, - /// The rounding radius. - pub border_radius: f32, -} - -impl RoundCylinder { - /// Create sa new cylinder where all its edges and vertices are rounded by a radius of `radius`. - /// - /// This is done by applying a dilation of the given radius to the cylinder. - pub fn new(half_height: f32, radius: f32, border_radius: f32) -> Self { - Self { - cylinder: Cylinder::new(half_height, radius), - border_radius, - } - } -} - -impl SupportMap for RoundCylinder { - fn local_support_point(&self, dir: &Vector) -> Point { - self.local_support_point_toward(&Unit::new_normalize(*dir)) - } - - fn local_support_point_toward(&self, dir: &Unit>) -> Point { - self.cylinder.local_support_point_toward(dir) + **dir * self.border_radius - } - - fn support_point(&self, transform: &Isometry, dir: &Vector) -> Point { - let local_dir = transform.inverse_transform_vector(dir); - transform * self.local_support_point(&local_dir) - } - - fn support_point_toward( - &self, - transform: &Isometry, - dir: &Unit>, - ) -> Point { - let local_dir = Unit::new_unchecked(transform.inverse_transform_vector(dir)); - transform * self.local_support_point_toward(&local_dir) - } -} - -impl RayCast for RoundCylinder { - fn cast_local_ray_and_get_normal( - &self, - ray: &Ray, - max_toi: f32, - solid: bool, - ) -> Option { - buckler::query::details::local_ray_intersection_with_support_map_with_params( - self, - &mut VoronoiSimplex::new(), - ray, - max_toi, - solid, - ) - } -} - -// TODO: if PointQuery had a `project_point_with_normal` method, we could just -// call this and adjust the projected point accordingly. -impl PointQuery for RoundCylinder { - #[inline] - fn project_local_point(&self, point: &Point, solid: bool) -> PointProjection { - buckler::query::details::local_point_projection_on_support_map( - self, - &mut VoronoiSimplex::new(), - point, - solid, - ) - } - - #[inline] - fn project_local_point_and_get_feature( - &self, - point: &Point, - ) -> (PointProjection, FeatureId) { - (self.project_local_point(point, false), FeatureId::Unknown) - } -} -- cgit