From 3664e1734bcbc758d49b8f9b918729d08f135a2a Mon Sep 17 00:00:00 2001 From: Stephen Seo Date: Fri, 26 Apr 2024 13:13:59 +0900 Subject: [PATCH] Tweak to representation of box coordinates Previous implementation assumed coords was a corner of the box. This changes the representation for the coords to denote the center of the box. --- src/sd_sacd.cpp | 19 ++++++++++++++++--- src/sd_sacd.h | 2 ++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/sd_sacd.cpp b/src/sd_sacd.cpp index 4eb8c26..ebafe61 100644 --- a/src/sd_sacd.cpp +++ b/src/sd_sacd.cpp @@ -5,9 +5,22 @@ int SC_SACD_AABB_Box_Collision(const SC_SACD_AABB_Box *a, const SC_SACD_AABB_Box *b) { - return (a->x < (b->x + b->width) && (a->x + a->width) > b->x && - a->y < (b->y + b->height) && (a->y + a->height) > b->y && - a->z < (b->z + b->depth) && (a->z + a->depth) > b->z) + float ax_min = a->x - a->width / 2.0F; + float ax_max = a->x + a->width / 2.0F; + float ay_min = a->y - a->height / 2.0F; + float ay_max = a->y + a->height / 2.0F; + float az_min = a->z - a->depth / 2.0F; + float az_max = a->z + a->depth / 2.0F; + + float bx_min = b->x - b->width / 2.0F; + float bx_max = b->x + b->width / 2.0F; + float by_min = b->y - b->height / 2.0F; + float by_max = b->y + b->height / 2.0F; + float bz_min = b->z - b->depth / 2.0F; + float bz_max = b->z + b->depth / 2.0F; + + return (ax_min < bx_max && ax_max > bx_min && ay_min < by_max && + ay_max > by_min && az_min < bz_max && az_max > bz_min) ? 1 : 0; } diff --git a/src/sd_sacd.h b/src/sd_sacd.h index 432aa11..4893046 100644 --- a/src/sd_sacd.h +++ b/src/sd_sacd.h @@ -31,6 +31,7 @@ typedef struct SC_SACD_EXPORT SC_SACD_Mat3 { } SC_SACD_Mat3; typedef struct SC_SACD_EXPORT SC_SACD_AABB_Box { + /// Coordinates are to center of box. float x; float y; float z; @@ -43,6 +44,7 @@ typedef struct SC_SACD_EXPORT SC_SACD_AABB_Box { } SC_SACD_AABB_Box; typedef struct SC_SACD_EXPORT SC_SACD_Generic_Box { + /// Coordinates are to center of box. float x; float y; float z;