1
This commit is contained in:
parent
e7915dbe7d
commit
570b3e3b3e
@ -31,7 +31,6 @@ 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;
|
||||
@ -46,7 +45,6 @@ bool IntersectSegmentAabb(Vector2D p0, Vector2D p1, Vector2D _min, Vector2D _max
|
||||
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;
|
||||
@ -58,45 +56,6 @@ bool IntersectSegmentAabb(Vector2D p0, Vector2D p1, Vector2D _min, Vector2D _max
|
||||
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;
|
||||
Vector2D v = p1 - p0;
|
||||
float z = v.Norm();
|
||||
v = z > (float)1e-5 ? v / z : Vector2D(1, 0);
|
||||
if (std::abs(v.x) < (float)1e-5) {
|
||||
v.x = float(2e-5);
|
||||
}
|
||||
if (std::abs(v.y) < (float)1e-5) {
|
||||
v.y = (float)2e-5;
|
||||
}
|
||||
if (std::abs(v.x) > (float)1e-5) {
|
||||
float u = (_min.x - n.x) / v.x;
|
||||
float i = (_max.x - n.x) / v.x;
|
||||
t = std::max(t, std::min(u, i));
|
||||
d = std::min(d, std::max(u, i));
|
||||
if (t > d) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (std::abs(v.y) > (float)1e-5) {
|
||||
float x = (_min.y - n.y) / v.y;
|
||||
float l = (_max.y - n.y) / v.y;
|
||||
t = std::max(t, std::min(x, l));
|
||||
d = std::min(d, std::max(x, l));
|
||||
if (t > d) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (t > z) {
|
||||
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