diff options
author | Raul Santos <raulsntos@gmail.com> | 2022-08-24 11:10:48 +0200 |
---|---|---|
committer | Raul Santos <raulsntos@gmail.com> | 2022-08-27 12:26:38 +0200 |
commit | b526a0d824939b0f33897858721ad45f3fb0fecb (patch) | |
tree | a349a35b5f2bde989f92346f95b88c733e8bcc53 /modules/mono | |
parent | 961a086d208ce3082a2ddb43894ffe413b3ff5fe (diff) |
C#: Add `GetAngle` and `GetAxis` to Quaternion
Diffstat (limited to 'modules/mono')
-rw-r--r-- | modules/mono/glue/GodotSharp/GodotSharp/Core/Quaternion.cs | 16 |
1 files changed, 16 insertions, 0 deletions
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); + } + /// <summary> /// Returns Euler angles (in the YXZ convention: when decomposing, /// first Z, then X, and Y last) corresponding to the rotation |