File tree 3 files changed +35
-2
lines changed
itest/rust/src/builtin_tests/geometry
3 files changed +35
-2
lines changed Original file line number Diff line number Diff line change @@ -281,6 +281,15 @@ impl Mul<Quaternion> for Quaternion {
281
281
}
282
282
}
283
283
284
+ impl Mul < Vector3 > for Quaternion {
285
+ type Output = Vector3 ;
286
+
287
+ fn mul ( self , rhs : Vector3 ) -> Self :: Output {
288
+ // TODO: should we panic if this quaternion is not normalized
289
+ Vector3 :: from_glam ( self . to_glam ( ) . mul_vec3 ( rhs. to_glam ( ) ) )
290
+ }
291
+ }
292
+
284
293
// SAFETY:
285
294
// This type is represented as `Self` in Godot, so `*mut Self` is sound.
286
295
unsafe impl GodotFfi for Quaternion {
Original file line number Diff line number Diff line change @@ -419,14 +419,14 @@ macro_rules! impl_vector_fns {
419
419
}
420
420
421
421
/// Converts the corresponding `glam` type to `Self`.
422
- fn from_glam( v: $GlamVector) -> Self {
422
+ pub ( crate ) fn from_glam( v: $GlamVector) -> Self {
423
423
Self :: new(
424
424
$( v. $comp ) ,*
425
425
)
426
426
}
427
427
428
428
/// Converts `self` to the corresponding `glam` type.
429
- fn to_glam( self ) -> $GlamVector {
429
+ pub ( crate ) fn to_glam( self ) -> $GlamVector {
430
430
<$GlamVector>:: new(
431
431
$( self . $comp ) ,*
432
432
)
Original file line number Diff line number Diff line change @@ -178,4 +178,28 @@ fn quaternion_spherical_cubic_interpolate_in_time() {
178
178
) ;
179
179
assert_eq ! ( outcome, Quaternion :: default ( ) )
180
180
}
181
+
182
+ #[ itest]
183
+ fn quaternion_mul1 ( ) {
184
+ use std:: f32:: consts:: PI ;
185
+ use godot:: builtin:: real;
186
+
187
+ let q = Quaternion :: from_axis_angle ( Vector3 :: UP , PI / 2.0 as real ) ;
188
+ let rotated = q * Vector3 :: new ( 1.0 , 4.2 , 0.0 ) ;
189
+ assert_eq_approx ! ( rotated. x, 0.0 ) ;
190
+ assert_eq_approx ! ( rotated. y, 4.2 ) ;
191
+ assert_eq_approx ! ( rotated. z, -1.0 ) ;
192
+ }
193
+
194
+ #[ itest]
195
+ fn quaternion_mul2 ( ) {
196
+ use std:: f32:: consts:: PI ;
197
+ use godot:: builtin:: real;
198
+
199
+ let q = Quaternion :: from_axis_angle ( -Vector3 :: UP , PI / 2.0 as real ) ;
200
+ let rotated = q * Vector3 :: new ( 1.0 , 4.2 , 2.0 ) ;
201
+ assert_eq_approx ! ( rotated. x, -2.0 ) ;
202
+ assert_eq_approx ! ( rotated. y, 4.2 ) ;
203
+ assert_eq_approx ! ( rotated. z, 1.0 ) ;
204
+ }
181
205
// TODO more tests
You can’t perform that action at this time.
0 commit comments