78 lines
2.1 KiB
C++
78 lines
2.1 KiB
C++
#pragma once
|
|
#include "J3ML/Geometry/AABB2D.hpp"
|
|
#include "J3ML/LinearAlgebra/Vector2.hpp"
|
|
|
|
namespace Solver {
|
|
|
|
/// Enumeration flags indicating cardinal direction to 8 degrees of freedom.
|
|
enum Face : unsigned int
|
|
{
|
|
NORTH = 1,
|
|
SOUTH = 2,
|
|
EAST = 4,
|
|
WEST = 8,
|
|
TOP = NORTH,
|
|
BOTTOM = SOUTH,
|
|
LEFT = EAST,
|
|
RIGHT = WEST,
|
|
NORTHEAST = NORTH | EAST,
|
|
NORTHWEST = NORTH | WEST,
|
|
SOUTHEAST = SOUTH | EAST,
|
|
SOUTHWEST = SOUTH | WEST
|
|
};
|
|
|
|
/// A structure containing the results of a raycast test.
|
|
struct RaycastHit
|
|
{
|
|
bool Hit;
|
|
Vector2 Intersection;
|
|
Vector2 SurfaceNormal;
|
|
};
|
|
|
|
|
|
struct LineSegment2D
|
|
{
|
|
Vector2 A;
|
|
Vector2 B;
|
|
Vector2 Midpoint() const
|
|
{
|
|
return Vector2(A.x + B.x, A.y + B.y) / 2.f;
|
|
}
|
|
|
|
};
|
|
|
|
|
|
struct LineSegTestResult
|
|
{
|
|
bool intersects;
|
|
Vector2 intersection;
|
|
Face face;
|
|
};
|
|
|
|
static LineSegTestResult LineSegment2DvsAABB2D(Vector2 linesegA, Vector2 linesegB, Vector2 rectCenter, Vector2 rectSize);
|
|
|
|
|
|
static LineSegTestResult LineSegment2DvsAABB2D(LineSegment2D seg, AABB2D rect);
|
|
static LineSegTestResult LineSegment2Dvs(Vector2 a1, Vector2 a2, Vector2 b1, Vector2 b2);
|
|
|
|
static LineSegTestResult LineSegment2Dvs(LineSegment2D s1, LineSegment2D s2);
|
|
|
|
bool AABB2Dvs(const Vector2& posA, const Vector2& sizeA, const Vector2& posB, const Vector2& sizeB);
|
|
|
|
bool AABB2Dvs(const AABB2D& a, const AABB2D& b);
|
|
|
|
bool AABB2DvsPoint(const Vector2& pos, const Vector2& size, const Vector2& point);
|
|
|
|
bool AABB2DvsPoint(const AABB2D& box, const Vector2& point);
|
|
|
|
Vector2 SolveAABBvsPoint(const Vector2& pos, const Vector2& size, const Vector2& point);
|
|
|
|
Vector2 SolveAABB(const Vector2& posA, const Vector2& sizeA, const Vector2& posB, const Vector2& sizeB);
|
|
|
|
Vector2 GetNormalForAABB(const Vector2& separation, const Vector2& velocity);
|
|
|
|
Vector2 SolveAABB(const AABB2D& a, const AABB2D& b);
|
|
|
|
|
|
}
|