@@ -247,11 +247,18 @@ impl Transform {
247247 self . basis . is_equal_approx ( & other. basis ) && self . origin . is_equal_approx ( other. origin )
248248 }
249249
250- /// Interpolates the transform to other Transform by
251- /// weight amount (on the range of 0.0 to 1.0).
250+ /// Interpolates the transform to other Transform by weight amount (on the range of 0.0 to 1.0).
252251 /// Assuming the two transforms are located on a sphere surface.
253252 #[ inline]
253+ #[ deprecated = "This is the Godot 4 rename of `interpolate_with`. It will be removed in favor of the original Godot 3 naming in a future version." ]
254254 pub fn sphere_interpolate_with ( & self , other : & Transform , weight : f32 ) -> Self {
255+ self . interpolate_with ( other, weight)
256+ }
257+
258+ /// Interpolates the transform to other Transform by weight amount (on the range of 0.0 to 1.0).
259+ /// Assuming the two transforms are located on a sphere surface.
260+ #[ inline]
261+ pub fn interpolate_with ( & self , other : & Transform , weight : f32 ) -> Self {
255262 let src_scale = self . basis . scale ( ) ;
256263 let src_rot = self . basis . to_quat ( ) ;
257264 let src_loc = self . origin ;
@@ -268,16 +275,6 @@ impl Transform {
268275 }
269276 }
270277
271- /// Interpolates the transform to other Transform by
272- /// weight amount (on the range of 0.0 to 1.0).
273- #[ inline]
274- pub fn interpolate_with ( & self , other : & Transform , weight : f32 ) -> Self {
275- Transform {
276- basis : self . basis . lerp ( & other. basis , weight) ,
277- origin : self . origin . linear_interpolate ( other. origin , weight) ,
278- }
279- }
280-
281278 #[ doc( hidden) ]
282279 #[ inline]
283280 pub fn sys ( & self ) -> * const sys:: godot_transform {
@@ -314,6 +311,30 @@ impl MulAssign<Transform> for Transform {
314311mod tests {
315312 use super :: * ;
316313
314+ /// Equivalent GDScript, in case Godot values need to be updated:
315+ ///
316+ /// ```gdscript
317+ /// func test_inputs():
318+ /// var basis = Basis(Vector3(37.51756, 20.39467, 49.96816))
319+ /// var t = Transform(
320+ /// basis.x,
321+ /// basis.y,
322+ /// basis.z,
323+ /// Vector3(0.0, 0.0, 0.0))
324+ /// t = t.translated(Vector3(0.5, -1.0, 0.25))
325+ /// t = t.scaled(Vector3(0.25, 0.5, 2.0))
326+ ///
327+ /// basis = Basis(Vector3(12.23, 50.46, 93.94))
328+ /// var t2 = Transform(
329+ /// basis.x,
330+ /// basis.y,
331+ /// basis.z,
332+ /// Vector3(0.0, 0.0, 0.0))
333+ /// t2 = t2.translated(Vector3(1.5, -2.0, 1.25))
334+ /// t2 = t2.scaled(Vector3(0.5, 0.58, 1.0))
335+ ///
336+ /// return [t, t2]
337+ /// ```
317338 fn test_inputs ( ) -> ( Transform , Transform ) {
318339 let basis = Basis :: from_euler ( Vector3 :: new ( 37.51756 , 20.39467 , 49.96816 ) ) ;
319340 let mut t = Transform :: from_basis_origin (
@@ -376,22 +397,19 @@ mod tests {
376397 assert ! ( expected. is_equal_approx( & t) )
377398 }
378399
379- /*
380400 #[ test]
381401 fn inverse_is_sane ( ) {
382402 let t = test_inputs ( ) . 0 . inverse ( ) ;
383403 let expected = Transform :: from_basis_origin (
384- // Fix values
385- Vector3::new(0.309725, -0.66022015, 3.9329607),
386- Vector3::new(-0.57629496, 1.8808193, 0.3611141),
387- Vector3::new(-0.47722515, -0.14864945, 0.012628445),
388- Vector3::new(-0.7398631, 0.0425314, 0.03682696),
404+ Vector3 :: new ( 0.019358 , -0.041264 , 0.24581 ) ,
405+ Vector3 :: new ( -0.144074 , 0.470205 , 0.090279 ) ,
406+ Vector3 :: new ( -1.908901 , -0.594598 , 0.050514 ) ,
407+ Vector3 :: new ( -0.739863 , 0.042531 , 0.036827 ) ,
389408 ) ;
390409
391410 println ! ( "TF: {t:?}" ) ;
392411 assert ! ( expected. is_equal_approx( & t) )
393412 }
394- */
395413
396414 #[ test]
397415 fn orthonormalization_is_sane ( ) {
@@ -409,31 +427,12 @@ mod tests {
409427 }
410428
411429 #[ test]
412- fn linear_interpolation_is_sane ( ) {
430+ fn spherical_interpolation_is_sane ( ) {
413431 // Godot reports:
414432 // t = 0.019358, -0.041264, 0.24581, -0.144074, 0.470205, 0.090279, -1.908901, -0.594598, 0.050514 - 0.112395, -0.519672, -0.347224
415433 // t2 = 0.477182, 0.118214, 0.09123, -0.165859, 0.521769, 0.191437, -0.086105, -0.367178, 0.926157 - 0.593383, -1.05303, 1.762894
416- // TODO: Get new godot result. https://github.com/godotengine/godot/commit/61759da5b35e44003ab3ffe3d4024dd611d17eff changed how Transform3D.linear_interpolate works
417- // For now assuming this is sane - examined the new implementation manually.
418434 let ( t, t2) = test_inputs ( ) ;
419435 let result = t. interpolate_with ( & t2, 0.5 ) ;
420- let expected = Transform :: from_basis_origin (
421- Vector3 :: new ( 0.24826992 , -0.15496635 , -0.997503 ) ,
422- Vector3 :: new ( 0.038474888 , 0.49598676 , -0.4808879 ) ,
423- Vector3 :: new ( 0.16852 , 0.14085774 , 0.48833522 ) ,
424- Vector3 :: new ( 0.352889 , -0.786351 , 0.707835 ) ,
425- ) ;
426- assert ! ( expected. is_equal_approx( & result) )
427- }
428-
429- #[ test]
430- fn sphere_linear_interpolation_is_sane ( ) {
431- // Godot reports:
432- // t = 0.019358, -0.041264, 0.24581, -0.144074, 0.470205, 0.090279, -1.908901, -0.594598, 0.050514 - 0.112395, -0.519672, -0.347224
433- // t2 = 0.477182, 0.118214, 0.09123, -0.165859, 0.521769, 0.191437, -0.086105, -0.367178, 0.926157 - 0.593383, -1.05303, 1.762894
434- // result = 0.727909, -0.029075, 0.486138, -0.338385, 0.6514, 0.156468, -0.910002, -0.265481, 0.330678 - 0.352889, -0.786351, 0.707835
435- let ( t, t2) = test_inputs ( ) ;
436- let result = t. sphere_interpolate_with ( & t2, 0.5 ) ;
437436 let expected = Transform :: from_basis_origin (
438437 Vector3 :: new ( 0.7279087 , -0.19632529 , -0.45626357 ) ,
439438 Vector3 :: new ( -0.05011323 , 0.65140045 , -0.22942543 ) ,
0 commit comments