1
This commit is contained in:
parent
66410aefce
commit
1d405bd088
@ -5,6 +5,8 @@
|
||||
#include <glm/gtx/intersect.hpp>
|
||||
#include <glm/vec3.hpp>
|
||||
|
||||
#include "collision.h"
|
||||
|
||||
bool IntersectSegmentCircle(Vector2D p0, Vector2D p1, Vector2D pos, float rad)
|
||||
{
|
||||
Vector2D t = p1 - p0;
|
||||
@ -29,6 +31,37 @@ bool IntersectSegmentCircle(Vector2D p0, Vector2D p1, Vector2D pos, float rad)
|
||||
|
||||
bool IntersectSegmentAabb(Vector2D p0, Vector2D p1, Vector2D _min, Vector2D _max)
|
||||
{
|
||||
#if 1
|
||||
Vector2D c = (_min + _max) * 0.5f;
|
||||
Vector2D e = _max - c;
|
||||
Vector2D m = (p0 + p1) * 0.5f;
|
||||
Vector2D d = p1 - m;
|
||||
m = m - c;
|
||||
|
||||
float adx = std::abs(d.x);
|
||||
if (std::abs(m.x) > e.x + adx) {
|
||||
return false;
|
||||
}
|
||||
float ady = std::abs(d.y);
|
||||
if (std::abs(m.y) > e.y + ady) {
|
||||
return false;
|
||||
}
|
||||
#if 1
|
||||
if (p0.x > p1.x) {
|
||||
float tmp = p0.x;
|
||||
p0.x = p1.x;
|
||||
p1.x = tmp;
|
||||
}
|
||||
if (p0.y > p1.y) {
|
||||
float tmp = p0.y;
|
||||
p0.y = p1.y;
|
||||
p1.y = tmp;
|
||||
}
|
||||
return IntersectAabbAabb(p0, p1, _min, _max);
|
||||
#else
|
||||
return true;
|
||||
#endif
|
||||
#else
|
||||
float t = 0.0f;
|
||||
float d = FLT_MAX;
|
||||
Vector2D n = p0;
|
||||
@ -63,6 +96,7 @@ bool IntersectSegmentAabb(Vector2D p0, Vector2D p1, Vector2D _min, Vector2D _max
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool IntersectAabbCircle(Vector2D a_min, Vector2D a_max, Vector2D b_pos, float b_rad)
|
||||
|
Loading…
x
Reference in New Issue
Block a user