MoonTools.Bonk/Bonk/Vector2Extensions.cs

18 lines
551 B
C#
Raw Normal View History

2019-10-25 10:46:47 +00:00
using Microsoft.Xna.Framework;
namespace MoonTools.Core.Bonk.Extensions
{
2019-10-25 19:42:39 +00:00
internal static class Vector2Extensions
2019-10-25 10:46:47 +00:00
{
2019-10-26 05:00:34 +00:00
internal static float Cross(this Vector2 a, Vector2 b)
2019-10-25 10:46:47 +00:00
{
2019-10-26 05:00:34 +00:00
return Vector3.Cross(new Vector3(a.X, a.Y, 0), new Vector3(b.X, b.Y, 0)).Z;
2019-10-25 10:46:47 +00:00
}
2019-10-26 05:00:34 +00:00
internal static Vector2 Perpendicular(this Vector2 a, Vector2 b)
2019-10-25 10:46:47 +00:00
{
2019-10-26 05:00:34 +00:00
var ab = b - a;
return a.Cross(b) > 0 ? Vector2.Normalize(new Vector2(ab.Y, ab.X)) : Vector2.Normalize(new Vector2(ab.Y, -ab.X));
2019-10-25 10:46:47 +00:00
}
}
}