C#: Restore Scale
and Rotation
properties
This commit is contained in:
parent
4db3716d8d
commit
04996df61e
3 changed files with 43 additions and 38 deletions
|
@ -119,6 +119,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>
|
||||
|
@ -541,21 +559,6 @@ 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>
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Godot
|
||||
|
@ -31,6 +32,23 @@ namespace Godot
|
|||
/// </summary>
|
||||
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.
|
||||
|
@ -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);
|
||||
|
@ -163,23 +182,6 @@ 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>
|
||||
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
Loading…
Reference in a new issue