Test collision system for TestGame
This commit is contained in:
@@ -188,8 +188,8 @@ public:
|
||||
loaded_tileset->cols = 80;
|
||||
loaded_tileset->rows = 60;
|
||||
loaded_tileset->file_path = "tileset.json";
|
||||
loaded_tileset->texture_path = "../megacommando.png";
|
||||
loaded_tilesheet = new JGL::Texture("../megacommando.png");
|
||||
loaded_tileset->texture_path = "assets/megacommando.png";
|
||||
loaded_tilesheet = new JGL::Texture("assets/megacommando.png");
|
||||
|
||||
write_file_contents("tileset.json", json::deparse(loaded_tileset->Serialize()));
|
||||
|
||||
|
@@ -89,7 +89,7 @@ public:
|
||||
tileset.file_path = "tileset.json";
|
||||
tileset.cols = 80;
|
||||
tileset.rows = 64;
|
||||
tileset.texture_path = "../megacommando.png";
|
||||
tileset.texture_path = "assets/megacommando.png";
|
||||
tileset.tex_width = 1024;
|
||||
tileset.tex_height = 1280;
|
||||
return tileset;
|
||||
|
77
include/SimpleAABBSolver.hpp
Normal file
77
include/SimpleAABBSolver.hpp
Normal file
@@ -0,0 +1,77 @@
|
||||
#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);
|
||||
|
||||
|
||||
}
|
Reference in New Issue
Block a user