From 0476fc5a0738b5ca0c98adbfa18451e7305672c8 Mon Sep 17 00:00:00 2001 From: Raul Santos Date: Sat, 14 Jan 2023 05:32:58 +0100 Subject: C#: Replace `Rotation` and `Scale` properties with get methods - Replace `Rotation` property with `GetRotation` method in `Transform2D`. - Replace `Scale` property with `GetScale` method in `Transform2D`. - Replace `Scale` property with `GetScale` method in `Basis`. Core does not expose set methods. --- .../mono/glue/GodotSharp/GodotSharp/Core/Basis.cs | 40 +++++--------- .../glue/GodotSharp/GodotSharp/Core/Transform2D.cs | 64 +++++++--------------- .../glue/GodotSharp/GodotSharp/Core/Transform3D.cs | 4 +- 3 files changed, 38 insertions(+), 70 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 90fdb14953..7366760e3f 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Basis.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Basis.cs @@ -119,31 +119,6 @@ namespace Godot } } - /// - /// The scale of this basis. - /// - /// Equivalent to the lengths of each column vector, but negative if the determinant is negative. - public Vector3 Scale - { - readonly get - { - real_t detSign = Mathf.Sign(Determinant()); - return detSign * new Vector3 - ( - Column0.Length(), - Column1.Length(), - Column2.Length() - ); - } - set - { - value /= Scale; // Value becomes what's called "delta_scale" in core. - Column0 *= value.x; - Column1 *= value.y; - Column2 *= value.z; - } - } - /// /// Access whole columns in the form of . /// @@ -566,6 +541,21 @@ 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 c99d91bff1..09e656af49 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Transform2D.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Transform2D.cs @@ -31,45 +31,6 @@ namespace Godot /// public Vector2 origin; - /// - /// The rotation of this transformation matrix. - /// - /// Getting is equivalent to calling with the values of . - public real_t Rotation - { - readonly get - { - return Mathf.Atan2(x.y, x.x); - } - set - { - Vector2 scale = Scale; - x.x = y.y = Mathf.Cos(value); - x.y = y.x = Mathf.Sin(value); - y.x *= -1; - Scale = scale; - } - } - - /// - /// The scale of this transformation matrix. - /// - /// Equivalent to the lengths of each column vector, but Y is negative if the determinant is negative. - public Vector2 Scale - { - readonly get - { - real_t detSign = Mathf.Sign(BasisDeterminant()); - return new Vector2(x.Length(), detSign * y.Length()); - } - set - { - value /= Scale; // Value becomes what's called "delta_scale" in core. - x *= value.x; - y *= value.y; - } - } - /// /// Access whole columns in the form of . /// The third column is the vector. @@ -202,6 +163,23 @@ 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 . /// @@ -210,11 +188,11 @@ namespace Godot /// The interpolated transform. public readonly Transform2D InterpolateWith(Transform2D transform, real_t weight) { - real_t r1 = Rotation; - real_t r2 = transform.Rotation; + real_t r1 = GetRotation(); + real_t r2 = transform.GetRotation(); - Vector2 s1 = Scale; - Vector2 s2 = transform.Scale; + Vector2 s1 = GetScale(); + Vector2 s2 = transform.GetScale(); // Slerp rotation var v1 = new Vector2(Mathf.Cos(r1), Mathf.Sin(r1)); diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Transform3D.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Transform3D.cs index 23f6d9ca04..4f0a557e0a 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.Scale; + Vector3 sourceScale = basis.GetScale(); Quaternion sourceRotation = basis.GetRotationQuaternion(); Vector3 sourceLocation = origin; - Vector3 destinationScale = transform.basis.Scale; + Vector3 destinationScale = transform.basis.GetScale(); Quaternion destinationRotation = transform.basis.GetRotationQuaternion(); Vector3 destinationLocation = transform.origin; -- cgit v1.2.3