aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRay <raysan5@gmail.com>2019-05-09 16:09:49 +0200
committerRay <raysan5@gmail.com>2019-05-09 16:09:49 +0200
commit46bac0ba2c4e00eae12c6070e2c028244be75c75 (patch)
tree6699f835385292f0e1bfa66489fc098e1a660383 /src
parent5fd3f13cb673a9abb721e6d87919c1d9461a6670 (diff)
downloadraylib-46bac0ba2c4e00eae12c6070e2c028244be75c75.tar.gz
raylib-46bac0ba2c4e00eae12c6070e2c028244be75c75.zip
Add comment in CheckCollisionSpheres()
Diffstat (limited to 'src')
-rw-r--r--src/models.c19
1 files changed, 18 insertions, 1 deletions
diff --git a/src/models.c b/src/models.c
index fc93c141..3f809f8d 100644
--- a/src/models.c
+++ b/src/models.c
@@ -2472,7 +2472,24 @@ void DrawBoundingBox(BoundingBox box, Color color)
// Detect collision between two spheres
bool CheckCollisionSpheres(Vector3 centerA, float radiusA, Vector3 centerB, float radiusB)
{
- return Vector3DotProduct(Vector3Subtract(centerB,centerA),Vector3Subtract(centerB,centerA))<=(radiusA+radiusB)*(radiusA+radiusB);
+ bool collision = false;
+
+ // Simple way to check for collision, just checking distance between two points
+ // Unfortunately, sqrtf() is a costly operation, so we avoid it with following solution
+ /*
+ 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;
+ */
+
+ // Check for distances squared to avoid sqrtf()
+ collision = (Vector3DotProduct(Vector3Subtract(centerB, centerA), Vector3Subtract(centerB, centerA)) <= (radiusA + radiusB)*(radiusA + radiusB));
+
+ return collision;
}
// Detect collision between two boxes