From eeca0c03394f158631be6c01d7e852cfbcd22a70 Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Wed, 20 Feb 2013 12:22:05 +0000 Subject: [PATCH] math: add Box2D and Box3D classes. --- src/lol/math/geometry.h | 53 ++++++++++++++++++++++++++++------------- 1 file changed, 37 insertions(+), 16 deletions(-) diff --git a/src/lol/math/geometry.h b/src/lol/math/geometry.h index 61f172ee..f6d1c662 100644 --- a/src/lol/math/geometry.h +++ b/src/lol/math/geometry.h @@ -27,27 +27,48 @@ namespace lol { - bool TriangleIsectTriangle(vec3 const &v00, vec3 const &v01, vec3 const &v02, - vec3 const &v10, vec3 const &v11, vec3 const &v12, - vec3 &iP00, vec3 &iP10); - bool RayIsectTriangleSide(vec3 const &v0, vec3 const &v1, vec3 const &v2, - vec3 const &iP0, vec3 const &iP1, - vec3 &iV0, int &iIdx0, vec3 &iV1, int &iIdx1); - bool RayIsectTriangle(vec3 const &rayP, vec3 const &rayD, - vec3 const &triV0, vec3 const &triV1, vec3 const &triV2, - vec3 &vi); + +struct Box2D +{ + inline Box2D(vec2 a, vec2 b) + : A(a), + B(b) + {} + + vec2 A, B; +}; + +struct Box3D +{ + inline Box3D(vec3 a, vec3 b) + : A(a), + B(b) + {} + + vec3 A, B; +}; + +bool TriangleIsectTriangle(vec3 const &v00, vec3 const &v01, vec3 const &v02, + vec3 const &v10, vec3 const &v11, vec3 const &v12, + vec3 &iP00, vec3 &iP10); +bool RayIsectTriangleSide(vec3 const &v0, vec3 const &v1, vec3 const &v2, + vec3 const &iP0, vec3 const &iP1, + vec3 &iV0, int &iIdx0, vec3 &iV1, int &iIdx1); +bool RayIsectTriangle(vec3 const &rayP, vec3 const &rayD, + vec3 const &triV0, vec3 const &triV1, vec3 const &triV2, + vec3 &vi); #define RAY_ISECT_NOTHING 0 #define RAY_ISECT_ALL 1 #define RAY_ISECT_NONE 2 #define RAY_ISECT_P0 3 #define RAY_ISECT_P1 4 - int RayIsectRay(vec3 const &rayP00, vec3 const &rayP01, - vec3 const &rayP10, vec3 const &rayP11, - vec3 &vIsec); - vec3 ProjPointOnPlane(vec3 const &point, vec3 const &planeP, vec3 const &planeN); - bool RayIsectPlane(vec3 const &rayP0, vec3 const &rayP1, - vec3 const &planeP, vec3 const &planeN, - vec3 &vIsec, bool test_line_only = false); +int RayIsectRay(vec3 const &rayP00, vec3 const &rayP01, + vec3 const &rayP10, vec3 const &rayP11, + vec3 &vIsec); +vec3 ProjPointOnPlane(vec3 const &point, vec3 const &planeP, vec3 const &planeN); +bool RayIsectPlane(vec3 const &rayP0, vec3 const &rayP1, + vec3 const &planeP, vec3 const &planeN, + vec3 &vIsec, bool test_line_only = false); } /* namespace lol */