Browse Source

Merge pull request #71787 from raulsntos/dotnet/restore-properties

C#: Restore `Scale` and `Rotation` properties
Rémi Verschelde 2 years ago
parent
commit
c53066682b

+ 18 - 15
modules/mono/glue/GodotSharp/GodotSharp/Core/Basis.cs

@@ -119,6 +119,24 @@ namespace Godot
             }
             }
         }
         }
 
 
+        /// <summary>
+        /// Assuming that the matrix is the combination of a rotation and scaling,
+        /// return the absolute value of scaling factors along each axis.
+        /// </summary>
+        public readonly Vector3 Scale
+        {
+            get
+            {
+                real_t detSign = Mathf.Sign(Determinant());
+                return detSign * new Vector3
+                (
+                    Column0.Length(),
+                    Column1.Length(),
+                    Column2.Length()
+                );
+            }
+        }
+
         /// <summary>
         /// <summary>
         /// Access whole columns in the form of <see cref="Vector3"/>.
         /// Access whole columns in the form of <see cref="Vector3"/>.
         /// </summary>
         /// </summary>
@@ -541,21 +559,6 @@ namespace Godot
             return orthonormalizedBasis.GetQuaternion();
             return orthonormalizedBasis.GetQuaternion();
         }
         }
 
 
-        /// <summary>
-        /// Assuming that the matrix is the combination of a rotation and scaling,
-        /// return the absolute value of scaling factors along each axis.
-        /// </summary>
-        public readonly Vector3 GetScale()
-        {
-            real_t detSign = Mathf.Sign(Determinant());
-            return detSign * new Vector3
-            (
-                Column0.Length(),
-                Column1.Length(),
-                Column2.Length()
-            );
-        }
-
         /// <summary>
         /// <summary>
         /// Returns the inverse of the matrix.
         /// Returns the inverse of the matrix.
         /// </summary>
         /// </summary>

+ 23 - 21
modules/mono/glue/GodotSharp/GodotSharp/Core/Transform2D.cs

@@ -1,4 +1,5 @@
 using System;
 using System;
+using System.Runtime.CompilerServices;
 using System.Runtime.InteropServices;
 using System.Runtime.InteropServices;
 
 
 namespace Godot
 namespace Godot
@@ -31,6 +32,23 @@ namespace Godot
         /// </summary>
         /// </summary>
         public Vector2 origin;
         public Vector2 origin;
 
 
+        /// <summary>
+        /// Returns the transform's rotation (in radians).
+        /// </summary>
+        public readonly real_t Rotation => Mathf.Atan2(x.y, x.x);
+
+        /// <summary>
+        /// Returns the scale.
+        /// </summary>
+        public readonly Vector2 Scale
+        {
+            get
+            {
+                real_t detSign = Mathf.Sign(BasisDeterminant());
+                return new Vector2(x.Length(), detSign * y.Length());
+            }
+        }
+
         /// <summary>
         /// <summary>
         /// Access whole columns in the form of <see cref="Vector2"/>.
         /// Access whole columns in the form of <see cref="Vector2"/>.
         /// The third column is the <see cref="origin"/> vector.
         /// The third column is the <see cref="origin"/> vector.
@@ -131,6 +149,7 @@ namespace Godot
         /// and is usually considered invalid.
         /// and is usually considered invalid.
         /// </summary>
         /// </summary>
         /// <returns>The determinant of the basis matrix.</returns>
         /// <returns>The determinant of the basis matrix.</returns>
+        [MethodImpl(MethodImplOptions.AggressiveInlining)]
         private readonly real_t BasisDeterminant()
         private readonly real_t BasisDeterminant()
         {
         {
             return (x.x * y.y) - (x.y * y.x);
             return (x.x * y.y) - (x.y * y.x);
@@ -163,23 +182,6 @@ namespace Godot
             return new Vector2(x.Dot(v), y.Dot(v));
             return new Vector2(x.Dot(v), y.Dot(v));
         }
         }
 
 
-        /// <summary>
-        /// Returns the transform's rotation (in radians).
-        /// </summary>
-        public readonly real_t GetRotation()
-        {
-            return Mathf.Atan2(x.y, x.x);
-        }
-
-        /// <summary>
-        /// Returns the scale.
-        /// </summary>
-        public readonly Vector2 GetScale()
-        {
-            real_t detSign = Mathf.Sign(BasisDeterminant());
-            return new Vector2(x.Length(), detSign * y.Length());
-        }
-
         /// <summary>
         /// <summary>
         /// Interpolates this transform to the other <paramref name="transform"/> by <paramref name="weight"/>.
         /// Interpolates this transform to the other <paramref name="transform"/> by <paramref name="weight"/>.
         /// </summary>
         /// </summary>
@@ -188,11 +190,11 @@ namespace Godot
         /// <returns>The interpolated transform.</returns>
         /// <returns>The interpolated transform.</returns>
         public readonly Transform2D InterpolateWith(Transform2D transform, real_t weight)
         public readonly Transform2D InterpolateWith(Transform2D transform, real_t weight)
         {
         {
-            real_t r1 = GetRotation();
-            real_t r2 = transform.GetRotation();
+            real_t r1 = Rotation;
+            real_t r2 = transform.Rotation;
 
 
-            Vector2 s1 = GetScale();
-            Vector2 s2 = transform.GetScale();
+            Vector2 s1 = Scale;
+            Vector2 s2 = transform.Scale;
 
 
             // Slerp rotation
             // Slerp rotation
             (real_t sin1, real_t cos1) = Mathf.SinCos(r1);
             (real_t sin1, real_t cos1) = Mathf.SinCos(r1);

+ 2 - 2
modules/mono/glue/GodotSharp/GodotSharp/Core/Transform3D.cs

@@ -124,11 +124,11 @@ namespace Godot
         /// <returns>The interpolated transform.</returns>
         /// <returns>The interpolated transform.</returns>
         public readonly Transform3D InterpolateWith(Transform3D transform, real_t weight)
         public readonly Transform3D InterpolateWith(Transform3D transform, real_t weight)
         {
         {
-            Vector3 sourceScale = basis.GetScale();
+            Vector3 sourceScale = basis.Scale;
             Quaternion sourceRotation = basis.GetRotationQuaternion();
             Quaternion sourceRotation = basis.GetRotationQuaternion();
             Vector3 sourceLocation = origin;
             Vector3 sourceLocation = origin;
 
 
-            Vector3 destinationScale = transform.basis.GetScale();
+            Vector3 destinationScale = transform.basis.Scale;
             Quaternion destinationRotation = transform.basis.GetRotationQuaternion();
             Quaternion destinationRotation = transform.basis.GetRotationQuaternion();
             Vector3 destinationLocation = transform.origin;
             Vector3 destinationLocation = transform.origin;