summaryrefslogtreecommitdiffhomepage
path: root/src/rshapes.c
diff options
context:
space:
mode:
authorRay <[email protected]>2022-09-04 10:45:01 +0200
committerRay <[email protected]>2022-09-04 10:45:01 +0200
commitf4b4054de570742845fb9a7b80c579ba37d98fbd (patch)
tree35ec7c5d6e1cb39d669ab96d73b4e7a61ea95b54 /src/rshapes.c
parentaff98d7f2af466f4b066ac9a019b8ca1e450c5cd (diff)
downloadraylib-f4b4054de570742845fb9a7b80c579ba37d98fbd.tar.gz
raylib-f4b4054de570742845fb9a7b80c579ba37d98fbd.zip
REVIEWED: `CheckCollisionPointPoly()`
Diffstat (limited to 'src/rshapes.c')
-rw-r--r--src/rshapes.c13
1 files changed, 6 insertions, 7 deletions
diff --git a/src/rshapes.c b/src/rshapes.c
index 8018bbde..5e79d893 100644
--- a/src/rshapes.c
+++ b/src/rshapes.c
@@ -1632,18 +1632,17 @@ bool CheckCollisionPointTriangle(Vector2 point, Vector2 p1, Vector2 p2, Vector2
}
// Check if point is within a polygon described by array of vertices
-bool CheckCollisionPointPolygon(Vector2 point, Vector2* vertices, int verticesCount)
+// NOTE: Based on http://jeffreythompson.org/collision-detection/poly-point.php
+bool CheckCollisionPointPoly(Vector2 point, Vector2 *points, int pointCount)
{
- // http://jeffreythompson.org/collision-detection/poly-point.php
-
bool collision = false;
- if (verticesCount > 2)
+ if (pointCount > 2)
{
- for (int i = 0; i < verticesCount; i++)
+ for (int i = 0; i < pointCount; i++)
{
- Vector2 vc = vertices[i];
- Vector2 vn = vertices[i + 1];
+ Vector2 vc = points[i];
+ Vector2 vn = points[i + 1];
if ((((vc.y >= point.y) && (vn.y < point.y)) || ((vc.y < point.y) && (vn.y >= point.y))) &&
(point.x < ((vn.x - vc.x)*(point.y - vc.y)/(vn.y - vc.y) + vc.x))) collision = !collision;