diff --git a/Kav.Framework.csproj b/Kav.Framework.csproj index 494053c..90aacaa 100644 --- a/Kav.Framework.csproj +++ b/Kav.Framework.csproj @@ -1,4 +1,4 @@ - + netstandard2.0 diff --git a/Utils/QuaternionUtils.cs b/Utils/QuaternionUtils.cs new file mode 100644 index 0000000..2d12391 --- /dev/null +++ b/Utils/QuaternionUtils.cs @@ -0,0 +1,18 @@ +using Microsoft.Xna.Framework; + +namespace Kav.Utils +{ + public static class QuaternionUtils + { + // assumes that the input vectors are normalized and orthogonal + public static Quaternion LookAt(in Vector3 forward, in Vector3 up) + { + Matrix orientation = Matrix.Identity; + orientation.Forward = forward; + orientation.Right = Vector3.Normalize(Vector3.Cross(forward, up)); + orientation.Up = Vector3.Cross(orientation.Right, forward); + + return Quaternion.CreateFromRotationMatrix(orientation); + } + } +}