@@ -11,9 +11,10 @@ use sys::{ffi_methods, GodotFfi};
1111
1212use crate :: builtin:: math:: { FloatExt , GlamConv , GlamType } ;
1313use 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 } ;
1515
1616use std:: fmt;
17+ use std:: ops:: Mul ;
1718
1819/// Vector used for 3D math using floating point coordinates.
1920///
@@ -248,6 +249,14 @@ impl_vector3_vector4_fns!(Vector3, (x, y, z));
248249
249250impl_vector_operators ! ( Vector3 , real, ( x, y, z) ) ;
250251
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+
251260/// Formats the vector like Godot: `(x, y, z)`.
252261impl fmt:: Display for Vector3 {
253262 fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
@@ -412,6 +421,21 @@ mod test {
412421 assert_eq_approx ! ( sum_refs, Vector3 :: new( 12.0 , 15.0 , 18.0 ) ) ;
413422 }
414423
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+
415439 #[ cfg( feature = "serde" ) ]
416440 #[ test]
417441 fn serde_roundtrip ( ) {
0 commit comments