mirror of
https://github.com/raysan5/raylib.git
synced 2026-04-19 21:43:41 -04:00
Making it similar to CheckCollisionSpheres to remove pow function (#5776)
This commit is contained in:
@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user