charcoal/OpenGLEngine/Collision.h

37 lines
742 B
C
Raw Permalink Normal View History

2018-10-18 04:48:05 +00:00
#pragma once
#include "PhysicsTypes.h"
namespace charcoal
{
namespace physics
{
namespace collision
{
// 4 comparisons
bool point_in_rect(const Rect& rect, float x, float y)
{
return
y < rect.top &&
y > rect.bottom &&
x > rect.left &&
x < rect.right;
}
// 8 * 4 = 32 comparisons
bool rect_in_rect(const Rect& a, const Rect& b)
{
return
point_in_rect(a, b.left, b.top) ||
point_in_rect(a, b.left, b.bottom) ||
point_in_rect(a, b.right, b.top) ||
point_in_rect(a, b.right, b.bottom) ||
point_in_rect(b, a.left, a.top) ||
point_in_rect(b, a.left, a.bottom) ||
point_in_rect(b, a.right, a.top) ||
point_in_rect(b, a.right, a.bottom);
}
}
}
}