aboutsummaryrefslogtreecommitdiff
path: root/src/dynamics/joint/multibody_joint
diff options
context:
space:
mode:
authorSébastien Crozet <developer@crozet.re>2022-06-23 16:23:39 +0200
committerSébastien Crozet <developer@crozet.re>2022-07-03 13:55:41 +0200
commit5063f3bb4fec2716f78a208552ee260f22428840 (patch)
treeb5665abb9c97469354c8c4dfd1a3fca21057ce16 /src/dynamics/joint/multibody_joint
parentcd0be8c076c69b88bb1848de72228225eeccb52d (diff)
downloadrapier-5063f3bb4fec2716f78a208552ee260f22428840.tar.gz
rapier-5063f3bb4fec2716f78a208552ee260f22428840.tar.bz2
rapier-5063f3bb4fec2716f78a208552ee260f22428840.zip
Add the ability to disable contacts between two rigid-bodies attached by joints
Diffstat (limited to 'src/dynamics/joint/multibody_joint')
-rw-r--r--src/dynamics/joint/multibody_joint/multibody_joint_set.rs35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/dynamics/joint/multibody_joint/multibody_joint_set.rs b/src/dynamics/joint/multibody_joint/multibody_joint_set.rs
index f1b2ffe..c25de73 100644
--- a/src/dynamics/joint/multibody_joint/multibody_joint_set.rs
+++ b/src/dynamics/joint/multibody_joint/multibody_joint_set.rs
@@ -321,6 +321,41 @@ impl MultibodyJointSet {
))
}
+ /// Returns the the joint between two rigid-bodies (if it exists).
+ pub fn joint_between(
+ &self,
+ rb1: RigidBodyHandle,
+ rb2: RigidBodyHandle,
+ ) -> Option<(MultibodyJointHandle, &Multibody, &MultibodyLink)> {
+ let id1 = self.rb2mb.get(rb1.0)?;
+ let id2 = self.rb2mb.get(rb2.0)?;
+
+ // Both bodies must be part of the same multibody.
+ if id1.multibody != id2.multibody {
+ return None;
+ }
+
+ let mb = self.multibodies.get(id1.multibody.0)?;
+
+ // NOTE: if there is a joint between these two bodies, then
+ // one of the bodies must be the parent of the other.
+ let link1 = mb.link(id1.id)?;
+ let parent1 = link1.parent_id()?;
+
+ if parent1 == id2.id {
+ Some((MultibodyJointHandle(rb1.0), mb, &link1))
+ } else {
+ let link2 = mb.link(id2.id)?;
+ let parent2 = link2.parent_id()?;
+
+ if parent2 == id1.id {
+ Some((MultibodyJointHandle(rb2.0), mb, &link2))
+ } else {
+ None
+ }
+ }
+ }
+
/// Iterates through all the joints attached to the given rigid-body.
pub fn attached_joints(
&self,