@@ -25,6 +25,10 @@ pub struct SphericalJoint {
2525 pub local_anchor1 : Vector ,
2626 /// Attachment point on the second body.
2727 pub local_anchor2 : Vector ,
28+ /// Rotation applied on the first body. This allows to orient the body relative to the `swing_axis`.
29+ pub local_rotation1 : Rotation ,
30+ /// Rotation applied on the second body.
31+ pub local_rotation2 : Rotation ,
2832 /// An axis that the attached bodies can swing around. This is normally the x-axis.
2933 pub swing_axis : Vector3 ,
3034 /// An axis that the attached bodies can twist around. This is normally the y-axis.
@@ -96,6 +100,8 @@ impl Joint for SphericalJoint {
96100 entity2,
97101 local_anchor1 : Vector :: ZERO ,
98102 local_anchor2 : Vector :: ZERO ,
103+ local_rotation1 : Rotation :: default ( ) ,
104+ local_rotation2 : Rotation :: default ( ) ,
99105 swing_axis : Vector3 :: X ,
100106 twist_axis : Vector3 :: Y ,
101107 swing_limit : None ,
@@ -193,8 +199,8 @@ impl SphericalJoint {
193199 dt : Scalar ,
194200 ) -> Torque {
195201 if let Some ( joint_limit) = self . swing_limit {
196- let a1 = * body1. rotation * self . swing_axis ;
197- let a2 = * body2. rotation * self . swing_axis ;
202+ let a1 = * body1. rotation * self . local_rotation1 * self . swing_axis ;
203+ let a2 = * body2. rotation * self . local_rotation2 * self . swing_axis ;
198204
199205 let n = a1. cross ( a2) ;
200206 let n_magnitude = n. length ( ) ;
@@ -230,11 +236,11 @@ impl SphericalJoint {
230236 dt : Scalar ,
231237 ) -> Torque {
232238 if let Some ( joint_limit) = self . twist_limit {
233- let a1 = * body1. rotation * self . swing_axis ;
234- let a2 = * body2. rotation * self . swing_axis ;
239+ let a1 = * body1. rotation * self . local_rotation1 * self . swing_axis ;
240+ let a2 = * body2. rotation * self . local_rotation2 * self . swing_axis ;
235241
236- let b1 = * body1. rotation * self . twist_axis ;
237- let b2 = * body2. rotation * self . twist_axis ;
242+ let b1 = * body1. rotation * self . local_rotation1 * self . twist_axis ;
243+ let b2 = * body2. rotation * self . local_rotation2 * self . twist_axis ;
238244
239245 let n = a1 + a2;
240246 let n_magnitude = n. length ( ) ;
0 commit comments