diff options
author | Rémi Verschelde <remi@verschelde.fr> | 2021-06-18 12:35:58 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-18 12:35:58 +0200 |
commit | 7aebb8f81c44f5f33c4387d32824a76e46266732 (patch) | |
tree | b09b30950ae57cb6d7a543678e65aeefbfd52b70 /modules | |
parent | 3fc39954ec3473cc022af615c5eb8b1ba271e008 (diff) | |
parent | 93b494d4ae136f43193a5a2da7a355938517767e (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.cs | 17 |
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> |