From b526a0d824939b0f33897858721ad45f3fb0fecb Mon Sep 17 00:00:00 2001 From: Raul Santos Date: Wed, 24 Aug 2022 11:10:48 +0200 Subject: C#: Add `GetAngle` and `GetAxis` to Quaternion --- .../mono/glue/GodotSharp/GodotSharp/Core/Quaternion.cs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Quaternion.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Quaternion.cs index 529ddc2cfb..6c92638651 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Quaternion.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Quaternion.cs @@ -158,6 +158,22 @@ namespace Godot return (x * b.x) + (y * b.y) + (z * b.z) + (w * b.w); } + public real_t GetAngle() + { + return 2 * Mathf.Acos(w); + } + + public Vector3 GetAxis() + { + if (Mathf.Abs(w) > 1 - Mathf.Epsilon) + { + return new Vector3(x, y, z); + } + + real_t r = 1 / Mathf.Sqrt(1 - w * w); + return new Vector3(x * r, y * r, z * r); + } + /// /// Returns Euler angles (in the YXZ convention: when decomposing, /// first Z, then X, and Y last) corresponding to the rotation -- cgit v1.2.3