Skip to content

Commit

Permalink
fix CheckCollisionPointPoly (#3750)
Browse files Browse the repository at this point in the history
  • Loading branch information
mllimo authored Jan 22, 2024
1 parent 68c32a4 commit ef92ced
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/rshapes.c
Original file line number Diff line number Diff line change
Expand Up @@ -2196,21 +2196,21 @@ bool CheckCollisionPointTriangle(Vector2 point, Vector2 p1, Vector2 p2, Vector2
// NOTE: Based on http://jeffreythompson.org/collision-detection/poly-point.php
bool CheckCollisionPointPoly(Vector2 point, Vector2 *points, int pointCount)
{
bool collision = false;
bool inside = false;

if (pointCount > 2)
{
for (int i = 0; i < pointCount - 1; i++)
for (int i = 0, j = pointCount - 1; i < pointCount; j = i++)
{
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;
if ((points[i].y > point.y) != (points[j].y > point.y) &&
(point.x < (points[j].x - points[i].x) * (point.y - points[i].y) / (points[j].y - points[i].y) + points[i].x))
{
inside = !inside;
}
}
}

return collision;
return inside;
}

// Check collision between two rectangles
Expand Down

0 comments on commit ef92ced

Please sign in to comment.