@@ -25,6 +25,12 @@ pub struct RevoluteJoint {
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 `aligned_axis`.
29
+ #[ cfg( feature = "3d" ) ]
30
+ pub local_rotation1 : Rotation ,
31
+ /// Rotation applied on the second body.
32
+ #[ cfg( feature = "3d" ) ]
33
+ pub local_rotation2 : Rotation ,
28
34
/// A unit vector that controls which axis should be aligned for both entities.
29
35
///
30
36
/// In 2D this should always be the Z axis.
@@ -105,6 +111,10 @@ impl Joint for RevoluteJoint {
105
111
entity2,
106
112
local_anchor1 : Vector :: ZERO ,
107
113
local_anchor2 : Vector :: ZERO ,
114
+ #[ cfg( feature = "3d" ) ]
115
+ local_rotation1 : Rotation :: default ( ) ,
116
+ #[ cfg( feature = "3d" ) ]
117
+ local_rotation2 : Rotation :: default ( ) ,
108
118
aligned_axis : Vector3 :: Z ,
109
119
angle_limit : None ,
110
120
damping_linear : 1.0 ,
@@ -194,8 +204,8 @@ impl RevoluteJoint {
194
204
195
205
#[ cfg( feature = "3d" ) ]
196
206
fn get_rotation_difference ( & self , rot1 : & Rotation , rot2 : & Rotation ) -> Vector3 {
197
- let a1 = rot1 * self . aligned_axis ;
198
- let a2 = rot2 * self . aligned_axis ;
207
+ let a1 = * rot1 * self . local_rotation1 * self . aligned_axis ;
208
+ let a2 = * rot2 * self . local_rotation2 * self . aligned_axis ;
199
209
a1. cross ( a2)
200
210
}
201
211
@@ -215,9 +225,13 @@ impl RevoluteJoint {
215
225
#[ cfg( feature = "3d" ) ]
216
226
{
217
227
// [n, n1, n2] = [a1, b1, b2], where [a, b, c] are perpendicular unit axes on the bodies.
218
- let a1 = * body1. rotation * self . aligned_axis ;
219
- let b1 = * body1. rotation * self . aligned_axis . any_orthonormal_vector ( ) ;
220
- let b2 = * body2. rotation * self . aligned_axis . any_orthonormal_vector ( ) ;
228
+ let a1 = * body1. rotation * self . local_rotation1 * self . aligned_axis ;
229
+ let b1 = * body1. rotation
230
+ * self . local_rotation1
231
+ * self . aligned_axis . any_orthonormal_vector ( ) ;
232
+ let b2 = * body2. rotation
233
+ * self . local_rotation2
234
+ * self . aligned_axis . any_orthonormal_vector ( ) ;
221
235
angle_limit. compute_correction ( a1, b1, b2, dt)
222
236
}
223
237
} ) else {
0 commit comments