@ -5,6 +5,23 @@ using System;
namespace SemiColinGames {
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 / 1 8 0 * 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 struct Hit {
public readonly AABB Collider ;
public readonly AABB Collider ;
public readonly Vector2 Position ;
public readonly Vector2 Position ;
@ -56,6 +73,38 @@ namespace SemiColinGames {
HalfSize = halfSize ;
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 ) {
public Hit ? Intersect ( AABB box ) {
float dx = box . Position . X - Position . X ;
float dx = box . Position . X - Position . X ;
float px = box . HalfSize . X + HalfSize . X - Math . Abs ( dx ) ;
float px = box . HalfSize . X + HalfSize . X - Math . Abs ( dx ) ;