From 8ad0ef75b8f0e4e9f60cc1b2fe71b30197c61f98 Mon Sep 17 00:00:00 2001 From: Raul Santos Date: Wed, 24 Aug 2022 13:00:43 +0200 Subject: C#: Add `Exp` and `Log` to Quaternion --- .../mono/glue/GodotSharp/GodotSharp/Core/Quaternion.cs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'modules/mono/glue/GodotSharp') diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Quaternion.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Quaternion.cs index 6c92638651..fea6a49b7d 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Quaternion.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Quaternion.cs @@ -158,6 +158,18 @@ namespace Godot return (x * b.x) + (y * b.y) + (z * b.z) + (w * b.w); } + public Quaternion Exp() + { + Vector3 v = new Vector3(x, y, z); + real_t theta = v.Length(); + v = v.Normalized(); + if (theta < Mathf.Epsilon || !v.IsNormalized()) + { + return new Quaternion(0, 0, 0, 1); + } + return new Quaternion(v, theta); + } + public real_t GetAngle() { return 2 * Mathf.Acos(w); @@ -217,6 +229,12 @@ namespace Godot return Mathf.Abs(LengthSquared - 1) <= Mathf.Epsilon; } + public Quaternion Log() + { + Vector3 v = GetAxis() * GetAngle(); + return new Quaternion(v.x, v.y, v.z, 0); + } + /// /// Returns a copy of the quaternion, normalized to unit length. /// -- cgit v1.2.3