diff options
| author | Rémi Verschelde <rverschelde@gmail.com> | 2023-01-26 23:42:46 +0100 | 
|---|---|---|
| committer | Rémi Verschelde <rverschelde@gmail.com> | 2023-01-26 23:42:46 +0100 | 
| commit | c53066682bcf74372db2b22953463a328a3da24f (patch) | |
| tree | b718a5e29690fd25c849cc38f00d0747a5a7975c | |
| parent | fdd02b88277daf566e7f3c1d2532fca2d59d50f6 (diff) | |
| parent | 04996df61eef3fbe395a2252d7f469db7ef48cf7 (diff) | |
Merge pull request #71787 from raulsntos/dotnet/restore-properties
C#: Restore `Scale` and `Rotation` properties
3 files changed, 43 insertions, 38 deletions
diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Basis.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Basis.cs index b57317e1d0..2b139a78bd 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Basis.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Basis.cs @@ -120,6 +120,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>          /// Access whole columns in the form of <see cref="Vector3"/>.          /// </summary>          /// <param name="column">Which column vector.</param> @@ -542,21 +560,6 @@ 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 GetScale() -        { -            real_t detSign = Mathf.Sign(Determinant()); -            return detSign * new Vector3 -            ( -                Column0.Length(), -                Column1.Length(), -                Column2.Length() -            ); -        } - -        /// <summary>          /// Returns the inverse of the matrix.          /// </summary>          /// <returns>The inverse matrix.</returns> diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Transform2D.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Transform2D.cs index fa060e3a53..1dfa83ffc6 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Transform2D.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Transform2D.cs @@ -1,4 +1,5 @@  using System; +using System.Runtime.CompilerServices;  using System.Runtime.InteropServices;  namespace Godot @@ -32,6 +33,23 @@ namespace Godot          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>          /// Access whole columns in the form of <see cref="Vector2"/>.          /// The third column is the <see cref="origin"/> vector.          /// </summary> @@ -131,6 +149,7 @@ namespace Godot          /// and is usually considered invalid.          /// </summary>          /// <returns>The determinant of the basis matrix.</returns> +        [MethodImpl(MethodImplOptions.AggressiveInlining)]          private readonly real_t BasisDeterminant()          {              return (x.x * y.y) - (x.y * y.x); @@ -164,23 +183,6 @@ namespace Godot          }          /// <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>          /// Interpolates this transform to the other <paramref name="transform"/> by <paramref name="weight"/>.          /// </summary>          /// <param name="transform">The other transform.</param> @@ -188,11 +190,11 @@ namespace Godot          /// <returns>The interpolated transform.</returns>          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              (real_t sin1, real_t cos1) = Mathf.SinCos(r1); diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Transform3D.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Transform3D.cs index 6b2475fc59..ce5f98a6fc 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Transform3D.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Transform3D.cs @@ -124,11 +124,11 @@ namespace Godot          /// <returns>The interpolated transform.</returns>          public readonly Transform3D InterpolateWith(Transform3D transform, real_t weight)          { -            Vector3 sourceScale = basis.GetScale(); +            Vector3 sourceScale = basis.Scale;              Quaternion sourceRotation = basis.GetRotationQuaternion();              Vector3 sourceLocation = origin; -            Vector3 destinationScale = transform.basis.GetScale(); +            Vector3 destinationScale = transform.basis.Scale;              Quaternion destinationRotation = transform.basis.GetRotationQuaternion();              Vector3 destinationLocation = transform.origin;  |