From a4a4ddb5b4f03a6cf855ff4120803863e3c60a4f Mon Sep 17 00:00:00 2001 From: Crozet Sébastien Date: Mon, 2 Nov 2020 18:47:27 +0100 Subject: Implement joint removal. --- src/dynamics/joint/joint_set.rs | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'src/dynamics') 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 { + 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, -- cgit