add quaternion utility function

palette_crush
cosmonaut 2020-12-08 17:20:10 -08:00
parent 9a7fb75ec5
commit ef948cf7fb
2 changed files with 19 additions and 1 deletions

View File

@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework> <TargetFramework>netstandard2.0</TargetFramework>

18
Utils/QuaternionUtils.cs Normal file
View File

@ -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);
}
}
}