From 93b494d4ae136f43193a5a2da7a355938517767e Mon Sep 17 00:00:00 2001 From: Aaron Franke Date: Mon, 7 Dec 2020 01:40:46 -0500 Subject: Add Quaternion angle_to method --- .../mono/glue/GodotSharp/GodotSharp/Core/Quaternion.cs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'modules/mono/glue') 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 @@ -113,6 +113,23 @@ namespace Godot get { return Dot(this); } } + /// + /// 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 + /// will not work reliably. + /// + /// The other quaternion. + /// The angle between the quaternions. + public real_t AngleTo(Quaternion to) + { + real_t dot = Dot(to); + return Mathf.Acos(Mathf.Clamp(dot * dot * 2 - 1, -1, 1)); + } + /// /// Performs a cubic spherical interpolation between quaternions `preA`, /// this vector, `b`, and `postB`, by the given amount `t`. -- cgit v1.2.3