From 3b83eb41da11980aaebba9f7314a9cf6c529788e Mon Sep 17 00:00:00 2001 From: cosmonaut Date: Fri, 26 Mar 2021 12:07:46 -0700 Subject: [PATCH] add LookAt method to Quaternion --- src/Math/Quaternion.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/Math/Quaternion.cs b/src/Math/Quaternion.cs index 5a9b0aa0..c795b756 100644 --- a/src/Math/Quaternion.cs +++ b/src/Math/Quaternion.cs @@ -881,6 +881,16 @@ namespace MoonWorks.Math result.W = quaternion.W * num; } + public static Quaternion LookAt(in Vector3 forward, in Vector3 up) + { + Matrix4x4 orientation = Matrix4x4.Identity; + orientation.Forward = forward; + orientation.Right = Vector3.Normalize(Vector3.Cross(forward, up)); + orientation.Up = Vector3.Cross(orientation.Right, forward); + + return Quaternion.CreateFromRotationMatrix(orientation); + } + #endregion #region Public Static Operator Overloads