Skip to content

Commit

Permalink
Merge pull request #1 from ProfJski/ProfJski-patch-1
Browse files Browse the repository at this point in the history
Update CheckCollisionSpheres() to avoid sqrt
  • Loading branch information
ProfJski authored May 8, 2019
2 parents 97c8a28 + d3dae38 commit 4330b09
Showing 1 changed file with 1 addition and 11 deletions.
12 changes: 1 addition & 11 deletions src/models.c
Original file line number Diff line number Diff line change
Expand Up @@ -2472,17 +2472,7 @@ void DrawBoundingBox(BoundingBox box, Color color)
// Detect collision between two spheres
bool CheckCollisionSpheres(Vector3 centerA, float radiusA, Vector3 centerB, float radiusB)
{
bool collision = false;

float dx = centerA.x - centerB.x; // X distance between centers
float dy = centerA.y - centerB.y; // Y distance between centers
float dz = centerA.z - centerB.z; // Y distance between centers

float distance = sqrtf(dx*dx + dy*dy + dz*dz); // Distance between centers

if (distance <= (radiusA + radiusB)) collision = true;

return collision;
return Vector3DotProduct(Vector3Subtract(B,A),Vector3Subtract(B,A))<=(RadA+RadB)*(RadA+RadB);
}

// Detect collision between two boxes
Expand Down

0 comments on commit 4330b09

Please sign in to comment.