diff options
author | Raul Santos <raulsntos@gmail.com> | 2023-01-21 04:49:16 +0100 |
---|---|---|
committer | Raul Santos <raulsntos@gmail.com> | 2023-01-21 04:59:13 +0100 |
commit | 04996df61eef3fbe395a2252d7f469db7ef48cf7 (patch) | |
tree | 868df9f94c59e279b39b0ba340912f6e75714ab5 /modules/mono | |
parent | 4db3716d8d9bbc95c031818b190002602558b0f2 (diff) |
C#: Restore `Scale` and `Rotation` properties
Diffstat (limited to 'modules/mono')
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; |