raycast fin
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
#include "game/aabb.h"
|
||||
#include "core/types.h"
|
||||
#include <math.h>
|
||||
|
||||
bool AABB_Collide(AABB a, AABB b)
|
||||
{
|
||||
@@ -19,17 +19,18 @@ bool AABB_Slab(V2f origin, V2f point, AABB a)
|
||||
{
|
||||
V2f start = a.pos;
|
||||
V2f finish = {a.pos.x + a.size.x, a.pos.y + a.size.y};
|
||||
V2f direction = {origin.x - point.x, origin.y - point.y};
|
||||
V2f invdirection = {1 / (origin.x - point.x), 1 / (origin.y - point.y)};
|
||||
// x
|
||||
F32 tLow = (start.x - origin.x) / direction.x;
|
||||
F32 tHigh = (finish.x - origin.x) / direction.x;
|
||||
F32 tLow = (start.x - origin.x) * invdirection.x;
|
||||
F32 tHigh = (finish.x - origin.x) * invdirection.x;
|
||||
F32 tMin = min(tLow, tHigh);
|
||||
F32 tMax = max(tLow, tHigh);
|
||||
// y
|
||||
tLow = (start.x - origin.x) / direction.x;
|
||||
tHigh = (finish.x - origin.x) / direction.x;
|
||||
tLow = (start.y - origin.y) * invdirection.y;
|
||||
tHigh = (finish.y - origin.y) * invdirection.y;
|
||||
|
||||
tMin = max(tMin, min(tLow, tHigh));
|
||||
tMax = min(tMax, max(tLow, tHigh));
|
||||
return tMax >= max(0.0, tMin);
|
||||
|
||||
return tMax >= tMin;
|
||||
}
|
||||
Reference in New Issue
Block a user