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.
This commit is contained in:
Raul Santos 2023-01-14 05:32:58 +01:00
parent 9711abe787
commit 0476fc5a07
No known key found for this signature in database
GPG key ID: B532473AE3A803E4
3 changed files with 38 additions and 70 deletions

View file

@ -119,31 +119,6 @@ namespace Godot
}
}
/// <summary>
/// The scale of this basis.
/// </summary>
/// <value>Equivalent to the lengths of each column vector, but negative if the determinant is negative.</value>
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;
}
}
/// <summary>
/// Access whole columns in the form of <see cref="Vector3"/>.
/// </summary>
@ -566,6 +541,21 @@ namespace Godot
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>
/// Returns the inverse of the matrix.
/// </summary>

View file

@ -31,45 +31,6 @@ namespace Godot
/// </summary>
public Vector2 origin;
/// <summary>
/// The rotation of this transformation matrix.
/// </summary>
/// <value>Getting is equivalent to calling <see cref="Mathf.Atan2(real_t, real_t)"/> with the values of <see cref="x"/>.</value>
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;
}
}
/// <summary>
/// The scale of this transformation matrix.
/// </summary>
/// <value>Equivalent to the lengths of each column vector, but Y is negative if the determinant is negative.</value>
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;
}
}
/// <summary>
/// Access whole columns in the form of <see cref="Vector2"/>.
/// The third column is the <see cref="origin"/> vector.
@ -202,6 +163,23 @@ namespace Godot
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>
/// Interpolates this transform to the other <paramref name="transform"/> by <paramref name="weight"/>.
/// </summary>
@ -210,11 +188,11 @@ namespace Godot
/// <returns>The interpolated transform.</returns>
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));

View file

@ -124,11 +124,11 @@ namespace Godot
/// <returns>The interpolated transform.</returns>
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;