diff options
Diffstat (limited to 'src/geometry')
| -rw-r--r-- | src/geometry/broad_phase_multi_sap.rs | 4 | ||||
| -rw-r--r-- | src/geometry/collider.rs | 42 | ||||
| -rw-r--r-- | src/geometry/collider_set.rs | 6 | ||||
| -rw-r--r-- | src/geometry/contact.rs | 24 | ||||
| -rw-r--r-- | src/geometry/contact_generator/ball_polygon_contact_generator.rs | 1 | ||||
| -rw-r--r-- | src/geometry/contact_generator/cuboid_polygon_contact_generator.rs | 1 | ||||
| -rw-r--r-- | src/geometry/narrow_phase.rs | 7 | ||||
| -rw-r--r-- | src/geometry/proximity_detector/ball_polygon_proximity_detector.rs | 1 | ||||
| -rw-r--r-- | src/geometry/proximity_detector/cuboid_polygon_proximity_detector.rs | 1 |
9 files changed, 74 insertions, 13 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..aed76c8 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; @@ -150,6 +150,7 @@ impl Collider { } /// The position of this collider expressed in the local-space of the rigid-body it is attached to. + #[deprecated(note = "use `.position_wrt_parent()` instead.")] pub fn delta(&self) -> &Isometry<f32> { &self.delta } @@ -159,6 +160,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 +353,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 } diff --git a/src/geometry/contact.rs b/src/geometry/contact.rs index 0beec0a..7e235c2 100644 --- a/src/geometry/contact.rs +++ b/src/geometry/contact.rs @@ -273,16 +273,21 @@ pub struct ContactManifold { /// The pair of subshapes involved in this contact manifold. pub subshape_index_pair: (usize, usize), pub(crate) warmstart_multiplier: f32, - // We put the friction and restitution here because - // this avoids reading the colliders inside of the + // The two following are set by the constraints solver. + pub(crate) constraint_index: usize, + pub(crate) position_constraint_index: usize, + // We put the following fields here to avoids reading the colliders inside of the // contact preparation method. /// The friction coefficient for of all the contacts on this contact manifold. pub friction: f32, /// The restitution coefficient for all the contacts on this contact manifold. pub restitution: f32, - // The following are set by the constraints solver. - pub(crate) constraint_index: usize, - pub(crate) position_constraint_index: usize, + /// The relative position between the first collider and its parent at the time the + /// contact points were generated. + pub delta1: Isometry<f32>, + /// The relative position between the second collider and its parent at the time the + /// contact points were generated. + pub delta2: Isometry<f32>, } impl ContactManifold { @@ -290,6 +295,8 @@ impl ContactManifold { pair: ColliderPair, subshapes: (usize, usize), body_pair: BodyPair, + delta1: Isometry<f32>, + delta2: Isometry<f32>, friction: f32, restitution: f32, ) -> ContactManifold { @@ -308,6 +315,8 @@ impl ContactManifold { warmstart_multiplier: Self::min_warmstart_multiplier(), friction, restitution, + delta1, + delta2, constraint_index: 0, position_constraint_index: 0, } @@ -329,6 +338,8 @@ impl ContactManifold { warmstart_multiplier: self.warmstart_multiplier, friction: self.friction, restitution: self.restitution, + delta1: self.delta1, + delta2: self.delta2, constraint_index: self.constraint_index, position_constraint_index: self.position_constraint_index, } @@ -349,6 +360,8 @@ impl ContactManifold { pair, (subshape1, subshape2), BodyPair::new(coll1.parent, coll2.parent), + *coll1.position_wrt_parent(), + *coll2.position_wrt_parent(), (coll1.friction + coll2.friction) * 0.5, (coll1.restitution + coll2.restitution) * 0.5, ) @@ -391,6 +404,7 @@ impl ContactManifold { self.pair = self.pair.swap(); self.body_pair = self.body_pair.swap(); self.subshape_index_pair = (self.subshape_index_pair.1, self.subshape_index_pair.0); + std::mem::swap(&mut self.delta1, &mut self.delta2); } pub(crate) fn update_warmstart_multiplier(&mut self) { diff --git a/src/geometry/contact_generator/ball_polygon_contact_generator.rs b/src/geometry/contact_generator/ball_polygon_contact_generator.rs index e69de29..8b13789 100644 --- a/src/geometry/contact_generator/ball_polygon_contact_generator.rs +++ b/src/geometry/contact_generator/ball_polygon_contact_generator.rs @@ -0,0 +1 @@ + diff --git a/src/geometry/contact_generator/cuboid_polygon_contact_generator.rs b/src/geometry/contact_generator/cuboid_polygon_contact_generator.rs index e69de29..8b13789 100644 --- a/src/geometry/contact_generator/cuboid_polygon_contact_generator.rs +++ b/src/geometry/contact_generator/cuboid_polygon_contact_generator.rs @@ -0,0 +1 @@ + diff --git a/src/geometry/narrow_phase.rs b/src/geometry/narrow_phase.rs index 3eb2c30..1a36511 100644 --- a/src/geometry/narrow_phase.rs +++ b/src/geometry/narrow_phase.rs @@ -96,7 +96,7 @@ impl NarrowPhase { } // We have to manage the fact that one other collider will - // hive its graph index changed because of the node's swap-remove. + // have its graph index changed because of the node's swap-remove. if let Some(replacement) = self .proximity_graph .remove_node(proximity_graph_id) @@ -129,6 +129,11 @@ impl NarrowPhase { if let (Some(co1), Some(co2)) = colliders.get2_mut_internal(pair.collider1, pair.collider2) { + if co1.parent == co2.parent { + // Same parents. Ignore collisions. + continue; + } + if co1.is_sensor() || co2.is_sensor() { let gid1 = co1.proximity_graph_index; let gid2 = co2.proximity_graph_index; diff --git a/src/geometry/proximity_detector/ball_polygon_proximity_detector.rs b/src/geometry/proximity_detector/ball_polygon_proximity_detector.rs index e69de29..8b13789 100644 --- a/src/geometry/proximity_detector/ball_polygon_proximity_detector.rs +++ b/src/geometry/proximity_detector/ball_polygon_proximity_detector.rs @@ -0,0 +1 @@ + diff --git a/src/geometry/proximity_detector/cuboid_polygon_proximity_detector.rs b/src/geometry/proximity_detector/cuboid_polygon_proximity_detector.rs index e69de29..8b13789 100644 --- a/src/geometry/proximity_detector/cuboid_polygon_proximity_detector.rs +++ b/src/geometry/proximity_detector/cuboid_polygon_proximity_detector.rs @@ -0,0 +1 @@ + |
