diff options
| author | Sébastien Crozet <developer@crozet.re> | 2020-08-31 17:58:14 +0200 |
|---|---|---|
| committer | Sébastien Crozet <developer@crozet.re> | 2020-08-31 19:05:14 +0200 |
| commit | df2156ffd02ea1b8c86e86f1d68c5e4e915e6d98 (patch) | |
| tree | 53c08d57b3fdbfcb94654a61fd68fcec5d66bffd /src/geometry | |
| parent | cc05bad0410128b163e81e9f703ccb841f6a9a08 (diff) | |
| download | rapier-df2156ffd02ea1b8c86e86f1d68c5e4e915e6d98.tar.gz rapier-df2156ffd02ea1b8c86e86f1d68c5e4e915e6d98.tar.bz2 rapier-df2156ffd02ea1b8c86e86f1d68c5e4e915e6d98.zip | |
Allow the removal of a collider.
Diffstat (limited to 'src/geometry')
| -rw-r--r-- | src/geometry/broad_phase_multi_sap.rs | 4 | ||||
| -rw-r--r-- | src/geometry/collider.rs | 41 | ||||
| -rw-r--r-- | src/geometry/collider_set.rs | 6 |
3 files changed, 44 insertions, 7 deletions
diff --git a/src/geometry/broad_phase_multi_sap.rs b/src/geometry/broad_phase_multi_sap.rs index 0505e21..054fccf 100644 --- a/src/geometry/broad_phase_multi_sap.rs +++ b/src/geometry/broad_phase_multi_sap.rs @@ -662,7 +662,7 @@ mod test { let rb = RigidBodyBuilder::new_dynamic().build(); let co = ColliderBuilder::ball(0.5).build(); let hrb = bodies.insert(rb); - let hco = colliders.insert(co, hrb, &mut bodies); + colliders.insert(co, hrb, &mut bodies); broad_phase.update_aabbs(0.0, &bodies, &mut colliders); @@ -681,7 +681,7 @@ mod test { let rb = RigidBodyBuilder::new_dynamic().build(); let co = ColliderBuilder::ball(0.5).build(); let hrb = bodies.insert(rb); - let hco = colliders.insert(co, hrb, &mut bodies); + colliders.insert(co, hrb, &mut bodies); // Make sure the proxy handles is recycled properly. broad_phase.update_aabbs(0.0, &bodies, &mut colliders); diff --git a/src/geometry/collider.rs b/src/geometry/collider.rs index 2457212..01c78ac 100644 --- a/src/geometry/collider.rs +++ b/src/geometry/collider.rs @@ -3,7 +3,7 @@ use crate::geometry::{ Ball, Capsule, ColliderGraphIndex, Contact, Cuboid, HeightField, InteractionGraph, Polygon, Proximity, Triangle, Trimesh, }; -use crate::math::{Isometry, Point, Vector}; +use crate::math::{AngVector, Isometry, Point, Rotation, Vector}; use na::Point3; use ncollide::bounding_volume::{HasBoundingVolume, AABB}; use num::Zero; @@ -159,6 +159,11 @@ impl Collider { &self.position } + /// The position of this collider wrt the body it is attached to. + pub fn position_wrt_parent(&self) -> &Isometry<f32> { + &self.delta + } + /// The density of this collider. pub fn density(&self) -> f32 { self.density @@ -347,7 +352,41 @@ impl ColliderBuilder { self } + /// Sets the initial translation of the collider to be created, + /// relative to the rigid-body it is attached to. + #[cfg(feature = "dim2")] + pub fn translation(mut self, x: f32, y: f32) -> Self { + self.delta.translation.x = x; + self.delta.translation.y = y; + self + } + + /// Sets the initial translation of the collider to be created, + /// relative to the rigid-body it is attached to. + #[cfg(feature = "dim3")] + pub fn translation(mut self, x: f32, y: f32, z: f32) -> Self { + self.delta.translation.x = x; + self.delta.translation.y = y; + self.delta.translation.z = z; + self + } + + /// Sets the initial orientation of the collider to be created, + /// relative to the rigid-body it is attached to. + pub fn rotation(mut self, angle: AngVector<f32>) -> Self { + self.delta.rotation = Rotation::new(angle); + self + } + + /// Sets the initial position (translation and orientation) of the collider to be created, + /// relative to the rigid-body it is attached to. + pub fn position(mut self, pos: Isometry<f32>) -> Self { + self.delta = pos; + self + } + /// Set the position of this collider in the local-space of the rigid-body it is attached to. + #[deprecated(note = "Use `.position` instead.")] pub fn delta(mut self, delta: Isometry<f32>) -> Self { self.delta = delta; self diff --git a/src/geometry/collider_set.rs b/src/geometry/collider_set.rs index 73d4a06..22bba1b 100644 --- a/src/geometry/collider_set.rs +++ b/src/geometry/collider_set.rs @@ -47,7 +47,6 @@ impl ColliderSet { parent_handle: RigidBodyHandle, bodies: &mut RigidBodySet, ) -> ColliderHandle { - let mass_properties = coll.mass_properties(); coll.parent = parent_handle; let parent = bodies .get_mut_internal(parent_handle) @@ -55,9 +54,8 @@ impl ColliderSet { coll.position = parent.position * coll.delta; coll.predicted_position = parent.predicted_position * coll.delta; let handle = self.colliders.insert(coll); - parent.colliders.push(handle); - parent.mass_properties += mass_properties; - parent.update_world_mass_properties(); + let coll = self.colliders.get(handle).unwrap(); + parent.add_collider_internal(handle, &coll); bodies.activate(parent_handle); handle } |
