diff --git a/a8/collision.cc b/a8/collision.cc index b4ca95b..7341d15 100644 --- a/a8/collision.cc +++ b/a8/collision.cc @@ -85,6 +85,104 @@ namespace a8 return u1 > 0.000001f && u2 > 0.000001; } + bool IntersectAabbObb(a8::Vec2 a_min, a8::Vec2 a_max, a8::Vec2 b_pos, float rotate) + { + struct Segment + { + a8::Vec2 point1; + a8::Vec2 point2; + a8::Vec2 dir; + }; + std::vector a_edges; + std::vector b_edges; + for (int i = 0; i < 3; ++i) { + Segment seg; + switch (i) { + case 0: + { + seg.point1 = a_min; + seg.point2 = a_min + a8::Vec2(a_max.x - a_min.x, 0); + seg.dir = seg.point2 - seg.point1; + } + break; + case 1: + { + seg.point1 = a_min + a8::Vec2(a_max.x - a_min.x, 0); + seg.point2 = a_max; + seg.dir = seg.point2 - seg.point1; + } + break; + case 2: + { + seg.point1 = a_max; + seg.point2 = a_min + a8::Vec2(0, a_max.y - a_min.y); + seg.dir = seg.point2 - seg.point1; + } + break; + case 3: + { + seg.point1 = a_min + a8::Vec2(0, a_max.y - a_min.y); + seg.point2 = a_min; + seg.dir = seg.point2 - seg.point1; + } + break; + default: + { + abort(); + } + } + a_edges.push_back(seg); + } + for (int i = 0; i < 3; ++i) { + Segment seg; + switch (i) { + case 0: + { + seg.point1 = a_min; + seg.point2 = a_min + a8::Vec2(a_max.x - a_min.x, 0); + seg.dir = seg.point2 - seg.point1; + } + break; + case 1: + { + seg.point1 = a_min + a8::Vec2(a_max.x - a_min.x, 0); + seg.point2 = a_max; + seg.dir = seg.point2 - seg.point1; + } + break; + case 2: + { + seg.point1 = a_max; + seg.point2 = a_min + a8::Vec2(0, a_max.y - a_min.y); + seg.dir = seg.point2 - seg.point1; + } + break; + case 3: + { + seg.point1 = a_min + a8::Vec2(0, a_max.y - a_min.y); + seg.point2 = a_min; + seg.dir = seg.point2 - seg.point1; + } + break; + default: + { + abort(); + } + } + b_edges.push_back(seg); + } + auto GetProjectionWithAxis = + [] (std::vector vertices, a8::Vec2 axis) -> a8::Vec2 { + axis.Normalize(); + float _min = vertices[0].Dot(axis); + float _max = _min; + for (a8::Vec2& v : vertices) { + + } + }; + return false; + } + bool IntersectCircleCircle(a8::Vec2 a_pos, float a_rad, a8::Vec2 b_pos, float b_rad) { float t = a_rad + b_rad; diff --git a/a8/collision.h b/a8/collision.h index ff49d04..e43ca69 100644 --- a/a8/collision.h +++ b/a8/collision.h @@ -9,6 +9,7 @@ namespace a8 bool IntersectSegmentAabb(a8::Vec2 p0, a8::Vec2 p1, a8::Vec2 _min, a8::Vec2 _max); bool IntersectAabbCircle(a8::Vec2 a_min, a8::Vec2 a_max, a8::Vec2 b_pos, float b_rad); bool IntersectAabbAabb(a8::Vec2 a_min, a8::Vec2 a_max, a8::Vec2 b_min, a8::Vec2 b_max); + bool IntersectAabbObb(a8::Vec2 a_min, a8::Vec2 a_max, a8::Vec2 b_pos, float rotate); bool IntersectCircleCircle(a8::Vec2 a_pos, float a_rad, a8::Vec2 b_pos, float b_rad); bool IntersectSectorCircle(a8::Vec2 a_pos, float angle, float a_rad, a8::Vec2 b_pos, float b_rad); bool IntersectSectorAabb(a8::Vec2 a_pos, float angle, float a_rad, a8::Vec2 b_min, a8::Vec2 b_max);