diff options
author | Raul Santos <raulsntos@gmail.com> | 2021-12-06 19:03:11 +0100 |
---|---|---|
committer | Raul Santos <raulsntos@gmail.com> | 2021-12-06 20:18:40 +0100 |
commit | 838f80ed91e370d1a339e2b3d186e146b676213a (patch) | |
tree | b8a7e56e1a75cb064ec408cd7e2605ffd6ebe483 /modules/mono/glue | |
parent | 3ae8eda1ed30b6c32f6fc1141118c5a062161a96 (diff) |
Rename C# `Quaternion()` -> `GetQuaternion()`
To keep consistency with GDScript, the method `Quaternion()` is renamed
`GetQuaternion()`, and made `internal` so it's not exposed to scripting.
The documentation references are also fixed.
Also, the methods `GetQuaternion()` and `GetRotationQuaternion()` are
moved below `GetEuler()` to follow alphabetic order.
Diffstat (limited to 'modules/mono/glue')
-rw-r--r-- | modules/mono/glue/GodotSharp/GodotSharp/Core/Basis.cs | 164 | ||||
-rw-r--r-- | modules/mono/glue/GodotSharp/GodotSharp/Core/Quaternion.cs | 2 |
2 files changed, 83 insertions, 83 deletions
diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Basis.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Basis.cs index bfbf1a097e..656796c5c7 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Basis.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Basis.cs @@ -209,27 +209,6 @@ namespace Godot } } - /// <summary> - /// Returns the <see cref="Basis"/>'s rotation in the form of a - /// <see cref="Quaternion"/>. See <see cref="GetEuler"/> if you - /// need Euler angles, but keep in mind quaternions should generally - /// be preferred to Euler angles. - /// </summary> - /// <returns>The basis rotation.</returns> - public Quaternion GetRotationQuaternion() - { - Basis orthonormalizedBasis = Orthonormalized(); - real_t det = orthonormalizedBasis.Determinant(); - if (det < 0) - { - // Ensure that the determinant is 1, such that result is a proper - // rotation matrix which can be represented by Euler angles. - orthonormalizedBasis = orthonormalizedBasis.Scaled(-Vector3.One); - } - - return orthonormalizedBasis.Quaternion(); - } - internal void SetQuaternionScale(Quaternion quaternion, Vector3 scale) { SetDiagonal(scale); @@ -272,8 +251,8 @@ namespace Godot /// The returned vector contains the rotation angles in /// the format (X angle, Y angle, Z angle). /// - /// Consider using the <see cref="Quaternion()"/> method instead, which - /// returns a <see cref="Godot.Quaternion"/> quaternion instead of Euler angles. + /// Consider using the <see cref="GetRotationQuaternion"/> method instead, which + /// returns a <see cref="Quaternion"/> quaternion instead of Euler angles. /// </summary> /// <returns>A <see cref="Vector3"/> representing the basis rotation in Euler angles.</returns> public Vector3 GetEuler() @@ -309,6 +288,85 @@ namespace Godot } /// <summary> + /// Returns the basis's rotation in the form of a quaternion. + /// See <see cref="GetEuler()"/> if you need Euler angles, but keep in + /// mind that quaternions should generally be preferred to Euler angles. + /// </summary> + /// <returns>A <see cref="Quaternion"/> representing the basis's rotation.</returns> + internal Quaternion GetQuaternion() + { + real_t trace = Row0[0] + Row1[1] + Row2[2]; + + if (trace > 0.0f) + { + real_t s = Mathf.Sqrt(trace + 1.0f) * 2f; + real_t inv_s = 1f / s; + return new Quaternion( + (Row2[1] - Row1[2]) * inv_s, + (Row0[2] - Row2[0]) * inv_s, + (Row1[0] - Row0[1]) * inv_s, + s * 0.25f + ); + } + + if (Row0[0] > Row1[1] && Row0[0] > Row2[2]) + { + real_t s = Mathf.Sqrt(Row0[0] - Row1[1] - Row2[2] + 1.0f) * 2f; + real_t inv_s = 1f / s; + return new Quaternion( + s * 0.25f, + (Row0[1] + Row1[0]) * inv_s, + (Row0[2] + Row2[0]) * inv_s, + (Row2[1] - Row1[2]) * inv_s + ); + } + + if (Row1[1] > Row2[2]) + { + real_t s = Mathf.Sqrt(-Row0[0] + Row1[1] - Row2[2] + 1.0f) * 2f; + real_t inv_s = 1f / s; + return new Quaternion( + (Row0[1] + Row1[0]) * inv_s, + s * 0.25f, + (Row1[2] + Row2[1]) * inv_s, + (Row0[2] - Row2[0]) * inv_s + ); + } + else + { + real_t s = Mathf.Sqrt(-Row0[0] - Row1[1] + Row2[2] + 1.0f) * 2f; + real_t inv_s = 1f / s; + return new Quaternion( + (Row0[2] + Row2[0]) * inv_s, + (Row1[2] + Row2[1]) * inv_s, + s * 0.25f, + (Row1[0] - Row0[1]) * inv_s + ); + } + } + + /// <summary> + /// Returns the <see cref="Basis"/>'s rotation in the form of a + /// <see cref="Quaternion"/>. See <see cref="GetEuler"/> if you + /// need Euler angles, but keep in mind quaternions should generally + /// be preferred to Euler angles. + /// </summary> + /// <returns>The basis rotation.</returns> + public Quaternion GetRotationQuaternion() + { + Basis orthonormalizedBasis = Orthonormalized(); + real_t det = orthonormalizedBasis.Determinant(); + if (det < 0) + { + // Ensure that the determinant is 1, such that result is a proper + // rotation matrix which can be represented by Euler angles. + orthonormalizedBasis = orthonormalizedBasis.Scaled(-Vector3.One); + } + + return orthonormalizedBasis.GetQuaternion(); + } + + /// <summary> /// Get rows by index. Rows are not very useful for user code, /// but are more efficient for some internal calculations. /// </summary> @@ -600,64 +658,6 @@ namespace Godot ); } - /// <summary> - /// Returns the basis's rotation in the form of a quaternion. - /// See <see cref="GetEuler()"/> if you need Euler angles, but keep in - /// mind that quaternions should generally be preferred to Euler angles. - /// </summary> - /// <returns>A <see cref="Godot.Quaternion"/> representing the basis's rotation.</returns> - public Quaternion Quaternion() - { - real_t trace = Row0[0] + Row1[1] + Row2[2]; - - if (trace > 0.0f) - { - real_t s = Mathf.Sqrt(trace + 1.0f) * 2f; - real_t inv_s = 1f / s; - return new Quaternion( - (Row2[1] - Row1[2]) * inv_s, - (Row0[2] - Row2[0]) * inv_s, - (Row1[0] - Row0[1]) * inv_s, - s * 0.25f - ); - } - - if (Row0[0] > Row1[1] && Row0[0] > Row2[2]) - { - real_t s = Mathf.Sqrt(Row0[0] - Row1[1] - Row2[2] + 1.0f) * 2f; - real_t inv_s = 1f / s; - return new Quaternion( - s * 0.25f, - (Row0[1] + Row1[0]) * inv_s, - (Row0[2] + Row2[0]) * inv_s, - (Row2[1] - Row1[2]) * inv_s - ); - } - - if (Row1[1] > Row2[2]) - { - real_t s = Mathf.Sqrt(-Row0[0] + Row1[1] - Row2[2] + 1.0f) * 2f; - real_t inv_s = 1f / s; - return new Quaternion( - (Row0[1] + Row1[0]) * inv_s, - s * 0.25f, - (Row1[2] + Row2[1]) * inv_s, - (Row0[2] - Row2[0]) * inv_s - ); - } - else - { - real_t s = Mathf.Sqrt(-Row0[0] - Row1[1] + Row2[2] + 1.0f) * 2f; - real_t inv_s = 1f / s; - return new Quaternion( - (Row0[2] + Row2[0]) * inv_s, - (Row1[2] + Row2[1]) * inv_s, - s * 0.25f, - (Row1[0] - Row0[1]) * inv_s - ); - } - } - private static readonly Basis[] _orthoBases = { new Basis(1f, 0f, 0f, 0f, 1f, 0f, 0f, 0f, 1f), new Basis(0f, -1f, 0f, 1f, 0f, 0f, 0f, 0f, 1f), @@ -745,7 +745,7 @@ namespace Godot /// given in the vector format as (X angle, Y angle, Z angle). /// /// Consider using the <see cref="Basis(Quaternion)"/> constructor instead, which - /// uses a <see cref="Godot.Quaternion"/> quaternion instead of Euler angles. + /// uses a <see cref="Quaternion"/> quaternion instead of Euler angles. /// </summary> /// <param name="eulerYXZ">The Euler angles to create the basis from.</param> public Basis(Vector3 eulerYXZ) diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Quaternion.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Quaternion.cs index dfb8e87bce..e38dca414f 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Quaternion.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Quaternion.cs @@ -377,7 +377,7 @@ namespace Godot /// <param name="basis">The <see cref="Basis"/> to construct from.</param> public Quaternion(Basis basis) { - this = basis.Quaternion(); + this = basis.GetQuaternion(); } /// <summary> |