19 lines
		
	
	
		
			592 B
		
	
	
	
		
			C#
		
	
	
			
		
		
	
	
			19 lines
		
	
	
		
			592 B
		
	
	
	
		
			C#
		
	
	
| 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);
 | |
|         }
 | |
|     }
 | |
| }
 |