diff --git a/Shared/Geometry.cs b/Shared/Geometry.cs index ccb1545..678c174 100644 --- a/Shared/Geometry.cs +++ b/Shared/Geometry.cs @@ -5,6 +5,23 @@ using System; namespace SemiColinGames { + // Math functions that return floats rather than doubles, for convenience. + public static class FMath { + public const float PI = (float) Math.PI; + + public static float DegToRad(float degrees) { + return PI / 180 * degrees; + } + + public static float Sin(double degrees) { + return (float) Math.Sin(degrees); + } + + public static float Cos(double degrees) { + return (float) Math.Cos(degrees); + } + } + public readonly struct Hit { public readonly AABB Collider; public readonly Vector2 Position; @@ -56,6 +73,38 @@ namespace SemiColinGames { HalfSize = halfSize; } + public float Top { + get { return Position.Y - HalfSize.Y; } + } + + public float Bottom { + get { return Position.Y + HalfSize.Y; } + } + + public float Left { + get { return Position.X - HalfSize.X; } + } + + public float Right { + get { return Position.X + HalfSize.X; } + } + + public Vector2 TopLeft { + get { return new Vector2(Left, Top); } + } + + public Vector2 TopRight { + get { return new Vector2(Right, Top); } + } + + public Vector2 BottomLeft { + get { return new Vector2(Left, Bottom); } + } + + public Vector2 BottomRight { + get { return new Vector2(Right, Bottom); } + } + public Hit? Intersect(AABB box) { float dx = box.Position.X - Position.X; float px = box.HalfSize.X + HalfSize.X - Math.Abs(dx);