From 04996df61eef3fbe395a2252d7f469db7ef48cf7 Mon Sep 17 00:00:00 2001 From: Raul Santos Date: Sat, 21 Jan 2023 04:49:16 +0100 Subject: C#: Restore `Scale` and `Rotation` properties --- .../mono/glue/GodotSharp/GodotSharp/Core/Basis.cs | 33 ++++++++-------- .../glue/GodotSharp/GodotSharp/Core/Transform2D.cs | 44 +++++++++++----------- .../glue/GodotSharp/GodotSharp/Core/Transform3D.cs | 4 +- 3 files changed, 43 insertions(+), 38 deletions(-) (limited to 'modules/mono') 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 @@ -119,6 +119,24 @@ namespace Godot } } + /// + /// Assuming that the matrix is the combination of a rotation and scaling, + /// return the absolute value of scaling factors along each axis. + /// + public readonly Vector3 Scale + { + get + { + real_t detSign = Mathf.Sign(Determinant()); + return detSign * new Vector3 + ( + Column0.Length(), + Column1.Length(), + Column2.Length() + ); + } + } + /// /// Access whole columns in the form of . /// @@ -541,21 +559,6 @@ namespace Godot return orthonormalizedBasis.GetQuaternion(); } - /// - /// Assuming that the matrix is the combination of a rotation and scaling, - /// return the absolute value of scaling factors along each axis. - /// - public readonly Vector3 GetScale() - { - real_t detSign = Mathf.Sign(Determinant()); - return detSign * new Vector3 - ( - Column0.Length(), - Column1.Length(), - Column2.Length() - ); - } - /// /// Returns the inverse of the matrix. /// 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 @@ -31,6 +32,23 @@ namespace Godot /// public Vector2 origin; + /// + /// Returns the transform's rotation (in radians). + /// + public readonly real_t Rotation => Mathf.Atan2(x.y, x.x); + + /// + /// Returns the scale. + /// + public readonly Vector2 Scale + { + get + { + real_t detSign = Mathf.Sign(BasisDeterminant()); + return new Vector2(x.Length(), detSign * y.Length()); + } + } + /// /// Access whole columns in the form of . /// The third column is the vector. @@ -131,6 +149,7 @@ namespace Godot /// and is usually considered invalid. /// /// The determinant of the basis matrix. + [MethodImpl(MethodImplOptions.AggressiveInlining)] private readonly real_t BasisDeterminant() { return (x.x * y.y) - (x.y * y.x); @@ -163,23 +182,6 @@ namespace Godot return new Vector2(x.Dot(v), y.Dot(v)); } - /// - /// Returns the transform's rotation (in radians). - /// - public readonly real_t GetRotation() - { - return Mathf.Atan2(x.y, x.x); - } - - /// - /// Returns the scale. - /// - public readonly Vector2 GetScale() - { - real_t detSign = Mathf.Sign(BasisDeterminant()); - return new Vector2(x.Length(), detSign * y.Length()); - } - /// /// Interpolates this transform to the other by . /// @@ -188,11 +190,11 @@ namespace Godot /// The interpolated transform. 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 /// The interpolated transform. 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; -- cgit v1.2.3