diff options
| author | Fun Maker <funmaker95@gmail.com> | 2024-04-21 20:48:35 +0200 |
|---|---|---|
| committer | Sébastien Crozet <sebastien@crozet.re> | 2024-05-05 16:34:55 +0200 |
| commit | 4332818e021644aa716e7ef0cca774cab09f4860 (patch) | |
| tree | e8ddfb1ea02661a9d70ad8570488f661205aa054 /src/dynamics/joint | |
| parent | a2fdeab7e16282c56b1b9a7b2bcafbb420663c39 (diff) | |
| download | rapier-4332818e021644aa716e7ef0cca774cab09f4860.tar.gz rapier-4332818e021644aa716e7ef0cca774cab09f4860.tar.bz2 rapier-4332818e021644aa716e7ef0cca774cab09f4860.zip | |
Fix joint limits not being flipped in one body constrains. (#549)
Diffstat (limited to 'src/dynamics/joint')
| -rw-r--r-- | src/dynamics/joint/generic_joint.rs | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/dynamics/joint/generic_joint.rs b/src/dynamics/joint/generic_joint.rs index 76a7fe1..98f9311 100644 --- a/src/dynamics/joint/generic_joint.rs +++ b/src/dynamics/joint/generic_joint.rs @@ -496,6 +496,26 @@ impl GenericJoint { self.motors[i].damping = damping; self } + + /// Flips the orientation of the joint, including limits and motors. + pub fn flip(&mut self) -> &mut Self { + std::mem::swap(&mut self.local_frame1, &mut self.local_frame2); + + let coupled_bits = self.coupled_axes.bits(); + + for dim in 0..SPATIAL_DIM { + if coupled_bits & (1 << dim) == 0 { + let limit = self.limits[dim]; + self.limits[dim].min = -limit.max; + self.limits[dim].max = -limit.min; + } + + self.motors[dim].target_vel = -self.motors[dim].target_vel; + self.motors[dim].target_pos = -self.motors[dim].target_pos; + } + + self + } } macro_rules! joint_conversion_methods( |
