Making it similar to CheckCollisionSpheres to remove pow function (#5776)

This commit is contained in:
Maicon Santana
2026-04-19 12:51:52 +01:00
committed by GitHub
parent 9060ac7c95
commit 90e9145978

View File

@ -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;
}