@@ -25,6 +25,10 @@ pub struct SphericalJoint {
25
25
pub local_anchor1 : Vector ,
26
26
/// Attachment point on the second body.
27
27
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 ,
28
32
/// An axis that the attached bodies can swing around. This is normally the x-axis.
29
33
pub swing_axis : Vector3 ,
30
34
/// An axis that the attached bodies can twist around. This is normally the y-axis.
@@ -96,6 +100,8 @@ impl Joint for SphericalJoint {
96
100
entity2,
97
101
local_anchor1 : Vector :: ZERO ,
98
102
local_anchor2 : Vector :: ZERO ,
103
+ local_rotation1 : Rotation :: default ( ) ,
104
+ local_rotation2 : Rotation :: default ( ) ,
99
105
swing_axis : Vector3 :: X ,
100
106
twist_axis : Vector3 :: Y ,
101
107
swing_limit : None ,
@@ -193,8 +199,8 @@ impl SphericalJoint {
193
199
dt : Scalar ,
194
200
) -> Torque {
195
201
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 ;
198
204
199
205
let n = a1. cross ( a2) ;
200
206
let n_magnitude = n. length ( ) ;
@@ -230,11 +236,11 @@ impl SphericalJoint {
230
236
dt : Scalar ,
231
237
) -> Torque {
232
238
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 ;
235
241
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 ;
238
244
239
245
let n = a1 + a2;
240
246
let n_magnitude = n. length ( ) ;
0 commit comments