summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorRémi Verschelde <remi@verschelde.fr>2021-06-18 12:35:58 +0200
committerGitHub <noreply@github.com>2021-06-18 12:35:58 +0200
commit7aebb8f81c44f5f33c4387d32824a76e46266732 (patch)
treeb09b30950ae57cb6d7a543678e65aeefbfd52b70 /modules
parent3fc39954ec3473cc022af615c5eb8b1ba271e008 (diff)
parent93b494d4ae136f43193a5a2da7a355938517767e (diff)
Merge pull request #44156 from aaronfranke/quat-angle-to
Add Quaternion angle_to method
Diffstat (limited to 'modules')
-rw-r--r--modules/mono/glue/GodotSharp/GodotSharp/Core/Quaternion.cs17
1 files changed, 17 insertions, 0 deletions
diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Quaternion.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Quaternion.cs
index b087b4c200..817103994a 100644
--- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Quaternion.cs
+++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Quaternion.cs
@@ -114,6 +114,23 @@ namespace Godot
}
/// <summary>
+ /// Returns the angle between this quaternion and `to`.
+ /// This is the magnitude of the angle you would need to rotate
+ /// by to get from one to the other.
+ ///
+ /// Note: This method has an abnormally high amount
+ /// of floating-point error, so methods such as
+ /// <see cref="Mathf.IsZeroApprox"/> will not work reliably.
+ /// </summary>
+ /// <param name="to">The other quaternion.</param>
+ /// <returns>The angle between the quaternions.</returns>
+ public real_t AngleTo(Quaternion to)
+ {
+ real_t dot = Dot(to);
+ return Mathf.Acos(Mathf.Clamp(dot * dot * 2 - 1, -1, 1));
+ }
+
+ /// <summary>
/// Performs a cubic spherical interpolation between quaternions `preA`,
/// this vector, `b`, and `postB`, by the given amount `t`.
/// </summary>