@@ -11,9 +11,10 @@ use sys::{ffi_methods, GodotFfi};
11
11
12
12
use crate :: builtin:: math:: { FloatExt , GlamConv , GlamType } ;
13
13
use crate :: builtin:: vectors:: Vector3Axis ;
14
- use crate :: builtin:: { inner, real, Basis , RVec3 , Vector2 , Vector3i } ;
14
+ use crate :: builtin:: { inner, real, Basis , RVec3 , Transform3D , Vector2 , Vector3i } ;
15
15
16
16
use std:: fmt;
17
+ use std:: ops:: Mul ;
17
18
18
19
/// Vector used for 3D math using floating point coordinates.
19
20
///
@@ -248,6 +249,14 @@ impl_vector3_vector4_fns!(Vector3, (x, y, z));
248
249
249
250
impl_vector_operators ! ( Vector3 , real, ( x, y, z) ) ;
250
251
252
+ impl Mul < Transform3D > for Vector3 {
253
+ type Output = Self ;
254
+
255
+ fn mul ( self , rhs : Transform3D ) -> Self :: Output {
256
+ rhs. glam2 ( & self , |t, v| t. inverse ( ) . transform_point3 ( v) )
257
+ }
258
+ }
259
+
251
260
/// Formats the vector like Godot: `(x, y, z)`.
252
261
impl fmt:: Display for Vector3 {
253
262
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
@@ -412,6 +421,21 @@ mod test {
412
421
assert_eq_approx ! ( sum_refs, Vector3 :: new( 12.0 , 15.0 , 18.0 ) ) ;
413
422
}
414
423
424
+ #[ test]
425
+ fn transform_multiplication ( ) {
426
+ let transform = Transform3D :: new ( Basis :: IDENTITY , Vector3 :: new ( 5. , 50. , 0.5 ) )
427
+ . rotated ( Vector3 :: new ( 1.0 , 2.0 , 3.0 ) . normalized ( ) , 1.0 ) ;
428
+ let vector = Vector3 :: new ( 10. , 100. , 1.0 ) ;
429
+ assert_eq_approx ! (
430
+ transform * vector,
431
+ Vector3 :: new( -81.93149 , 111.8101 , 59.27044 )
432
+ ) ;
433
+ assert_eq_approx ! (
434
+ vector * transform,
435
+ Vector3 :: new( 74.41499 , 11.49629 , 3.03081 )
436
+ ) ;
437
+ }
438
+
415
439
#[ cfg( feature = "serde" ) ]
416
440
#[ test]
417
441
fn serde_roundtrip ( ) {
0 commit comments