Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@OptimisticPeach
Created May 26, 2018 15:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save OptimisticPeach/49ee99379d4f03e8cc0ef76ba2499d0f to your computer and use it in GitHub Desktop.
Save OptimisticPeach/49ee99379d4f03e8cc0ef76ba2499d0f to your computer and use it in GitHub Desktop.
/// <summary>
/// Spherically interpolates a pair of vectors given a percentage <c>t</c>
/// </summary>
/// <param name="end">The End result once t is equal to 1</param>
/// <param name="t">The percent such that 0 < t < 1 </param>
/// <remarks>
/// Adapted from https://gist.github.com/manveru/384873
/// </remarks>
public static Vector3 Slerp(this Vector3 source, Vector3 end, float t)
{
float Omega = (float)Math.Acos(Vector3.Dot(source, end));
if (Omega != float.NaN && Omega != 0f)
{
float Denom = 1f / (float)Math.Sin(Omega);
return source * (float)(Math.Sin((1 - t) * Omega) * Denom) +
(end * (float)Math.Sin((t * Omega) * Denom));
}
else
return source;
}
public static void DrawText3D(this SpriteBatch source, GraphicsDevice GD, Matrix View, Matrix Proj, Matrix World, Color C, Vector3 Pos, SpriteFont Font, String Text)
{
Vector2 NewPos = new Vector2();
var projectedPos = GD.Viewport.Project(Pos, Proj, View, World);
NewPos.X = projectedPos.X;
NewPos.Y = projectedPos.Y;
source.DrawString(Font, Text, NewPos, C);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment