From 65161c6809a412c559f3c2089d90330d9c3ba7bb Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Thu, 21 Feb 2013 13:11:37 +0000 Subject: [PATCH] math: add BoxIsectBox() method to test interesections. --- src/lol/math/geometry.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/lol/math/geometry.h b/src/lol/math/geometry.h index bbc159a4..8122fa90 100644 --- a/src/lol/math/geometry.h +++ b/src/lol/math/geometry.h @@ -58,6 +58,17 @@ struct Box3D vec3 A, B; }; +static inline bool BoxIsectBox(Box2D const &b1, Box2D const &b2) +{ + vec2 c1 = 0.5f * (b1.A + b1.B); + vec2 c2 = 0.5f * (b2.A + b2.B); + vec2 e1 = 0.5f * (b1.B - b1.A); + vec2 e2 = 0.5f * (b2.B - b2.A); + + return abs(c1.x - c2.x) < abs(e1.x) + abs(e2.x) + || abs(c1.y - c2.y) < abs(e1.y) + abs(e2.y); +} + bool TriangleIsectTriangle(vec3 const &v00, vec3 const &v01, vec3 const &v02, vec3 const &v10, vec3 const &v11, vec3 const &v12, vec3 &iP00, vec3 &iP10);