add quaternion utility function
parent
9a7fb75ec5
commit
ef948cf7fb
|
@ -1,4 +1,4 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue