From 7b9f25ca5c7617d215edecb87e880fa7800fdefb Mon Sep 17 00:00:00 2001 From: Stephen Seo Date: Thu, 2 May 2024 12:31:55 +0900 Subject: [PATCH] Add check in Sphere/Box collision for same center --- src/sc_sacd.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/sc_sacd.cpp b/src/sc_sacd.cpp index 2713cdc..7f6a218 100644 --- a/src/sc_sacd.cpp +++ b/src/sc_sacd.cpp @@ -296,6 +296,12 @@ int SC_SACD_Sphere_Box_Collision(const SC_SACD_Sphere *sphere, SC_SACD_Vec3 sphere_pos{sphere->x, sphere->y, sphere->z}; SC_SACD_Vec3 sphere_box_normal = SC_SACD_Vec3{box->x, box->y, box->z} - sphere_pos; + if (sphere_box_normal.x < 0.0001F && sphere_box_normal.x > -0.0001F && + sphere_box_normal.y < 0.0001F && sphere_box_normal.y > -0.0001F && + sphere_box_normal.z < 0.0001F && sphere_box_normal.z > -0.0001F) { + // Sphere center is box center. + return 1; + } sphere_box_normal = sphere_box_normal / std::sqrt(SC_SACD_Dot_Product(sphere_box_normal, sphere_box_normal));