diff options
| author | Crozet Sébastien <developer@crozet.re> | 2020-11-02 18:47:27 +0100 |
|---|---|---|
| committer | Crozet Sébastien <developer@crozet.re> | 2020-11-02 18:47:27 +0100 |
| commit | a4a4ddb5b4f03a6cf855ff4120803863e3c60a4f (patch) | |
| tree | 63662f1a0c3dbe083cc64903bcb42cedec62d254 /src/dynamics | |
| parent | 9c72a0458b89741ce31744efa2d33f4b75de0d79 (diff) | |
| download | rapier-a4a4ddb5b4f03a6cf855ff4120803863e3c60a4f.tar.gz rapier-a4a4ddb5b4f03a6cf855ff4120803863e3c60a4f.tar.bz2 rapier-a4a4ddb5b4f03a6cf855ff4120803863e3c60a4f.zip | |
Implement joint removal.
Diffstat (limited to 'src/dynamics')
| -rw-r--r-- | src/dynamics/joint/joint_set.rs | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/dynamics/joint/joint_set.rs b/src/dynamics/joint/joint_set.rs index 2b1895f..5144d97 100644 --- a/src/dynamics/joint/joint_set.rs +++ b/src/dynamics/joint/joint_set.rs @@ -181,6 +181,38 @@ impl JointSet { } } + /// Removes a joint from this set. + /// + /// If `wake_up` is set to `true`, then the bodies attached to this joint will be + /// automatically woken up. + pub fn remove( + &mut self, + handle: JointHandle, + bodies: &mut RigidBodySet, + wake_up: bool, + ) -> Option<Joint> { + let id = self.joint_ids.remove(handle)?; + let endpoints = self.joint_graph.graph.edge_endpoints(id)?; + + if wake_up { + // Wake-up the bodies attached to this joint. + if let Some(rb_handle) = self.joint_graph.graph.node_weight(endpoints.0) { + bodies.wake_up(*rb_handle, true); + } + if let Some(rb_handle) = self.joint_graph.graph.node_weight(endpoints.1) { + bodies.wake_up(*rb_handle, true); + } + } + + let removed_joint = self.joint_graph.graph.remove_edge(id); + + if let Some(edge) = self.joint_graph.graph.edge_weight(id) { + self.joint_ids[edge.handle] = id; + } + + removed_joint + } + pub(crate) fn remove_rigid_body( &mut self, deleted_id: RigidBodyGraphIndex, |
