From 90e9145978d9dfffae19e60d819080d171b16450 Mon Sep 17 00:00:00 2001 From: Maicon Santana Date: Sun, 19 Apr 2026 12:51:52 +0100 Subject: [PATCH] Making it similar to CheckCollisionSpheres to remove pow function (#5776) --- src/rmodels.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/src/rmodels.c b/src/rmodels.c index 012bf24c3..62b8a51e5 100644 --- a/src/rmodels.c +++ b/src/rmodels.c @@ -4131,18 +4131,15 @@ bool CheckCollisionBoxSphere(BoundingBox box, Vector3 center, float radius) { bool collision = false; - float dmin = 0; + Vector3 closestPoint = { + Clamp(center.x, box.min.x, box.max.x), + Clamp(center.y, box.min.y, box.max.y), + Clamp(center.z, box.min.z, box.max.z) + }; - if (center.x < box.min.x) dmin += powf(center.x - box.min.x, 2); - else if (center.x > box.max.x) dmin += powf(center.x - box.max.x, 2); + float distanceSquared = Vector3DistanceSqr(center, closestPoint); - if (center.y < box.min.y) dmin += powf(center.y - box.min.y, 2); - else if (center.y > box.max.y) dmin += powf(center.y - box.max.y, 2); - - if (center.z < box.min.z) dmin += powf(center.z - box.min.z, 2); - else if (center.z > box.max.z) dmin += powf(center.z - box.max.z, 2); - - if (dmin <= (radius*radius)) collision = true; + collision = distanceSquared <= (radius * radius); return collision; }