diff options
| author | Sébastien Crozet <developer@crozet.re> | 2021-02-24 11:26:53 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-02-24 11:26:53 +0100 |
| commit | 649eba10130673534a60b17a0343b15208e5d622 (patch) | |
| tree | 0a5532b645945bbe542ad9a41d1344a318f307d8 /src/dynamics/rigid_body_set.rs | |
| parent | d31a327b45118a77bd9676f350f110683a235acf (diff) | |
| parent | 3cc2738e5fdcb0d25818b550cdff93eab75f1b20 (diff) | |
| download | rapier-649eba10130673534a60b17a0343b15208e5d622.tar.gz rapier-649eba10130673534a60b17a0343b15208e5d622.tar.bz2 rapier-649eba10130673534a60b17a0343b15208e5d622.zip | |
Merge pull request #120 from dimforge/contact_modification
Add the ability to modify the contact points seen by the constraints solver
Diffstat (limited to 'src/dynamics/rigid_body_set.rs')
| -rw-r--r-- | src/dynamics/rigid_body_set.rs | 42 |
1 files changed, 38 insertions, 4 deletions
diff --git a/src/dynamics/rigid_body_set.rs b/src/dynamics/rigid_body_set.rs index 79d5827..f459d4f 100644 --- a/src/dynamics/rigid_body_set.rs +++ b/src/dynamics/rigid_body_set.rs @@ -234,13 +234,27 @@ impl RigidBodySet { self.bodies.get(handle.0) } + fn mark_as_modified( + handle: RigidBodyHandle, + rb: &mut RigidBody, + modified_bodies: &mut Vec<RigidBodyHandle>, + modified_all_bodies: bool, + ) { + if !modified_all_bodies && !rb.changes.contains(RigidBodyChanges::MODIFIED) { + rb.changes = RigidBodyChanges::MODIFIED; + modified_bodies.push(handle); + } + } + /// Gets a mutable reference to the rigid-body with the given handle. pub fn get_mut(&mut self, handle: RigidBodyHandle) -> Option<&mut RigidBody> { let result = self.bodies.get_mut(handle.0)?; - if !self.modified_all_bodies && !result.changes.contains(RigidBodyChanges::MODIFIED) { - result.changes = RigidBodyChanges::MODIFIED; - self.modified_bodies.push(handle); - } + Self::mark_as_modified( + handle, + result, + &mut self.modified_bodies, + self.modified_all_bodies, + ); Some(result) } @@ -300,6 +314,26 @@ impl RigidBodySet { .filter_map(move |h| Some((*h, bodies.get(h.0)?))) } + /// Applies the given function on all the active dynamic rigid-bodies + /// contained by this set. + #[inline(always)] + pub fn foreach_active_dynamic_body_mut( + &mut self, + mut f: impl FnMut(RigidBodyHandle, &mut RigidBody), + ) { + for handle in &self.active_dynamic_set { + if let Some(rb) = self.bodies.get_mut(handle.0) { + Self::mark_as_modified( + *handle, + rb, + &mut self.modified_bodies, + self.modified_all_bodies, + ); + f(*handle, rb) + } + } + } + #[inline(always)] pub(crate) fn foreach_active_body_mut_internal( &mut self, |
