fix CheckCollisionPointPoly (#3750)
This commit is contained in:
parent
68c32a4184
commit
ef92ced370
1 changed files with 8 additions and 8 deletions
|
@ -2196,21 +2196,21 @@ bool CheckCollisionPointTriangle(Vector2 point, Vector2 p1, Vector2 p2, Vector2
|
||||||
// NOTE: Based on http://jeffreythompson.org/collision-detection/poly-point.php
|
// NOTE: Based on http://jeffreythompson.org/collision-detection/poly-point.php
|
||||||
bool CheckCollisionPointPoly(Vector2 point, Vector2 *points, int pointCount)
|
bool CheckCollisionPointPoly(Vector2 point, Vector2 *points, int pointCount)
|
||||||
{
|
{
|
||||||
bool collision = false;
|
bool inside = false;
|
||||||
|
|
||||||
if (pointCount > 2)
|
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];
|
if ((points[i].y > point.y) != (points[j].y > point.y) &&
|
||||||
Vector2 vn = points[i + 1];
|
(point.x < (points[j].x - points[i].x) * (point.y - points[i].y) / (points[j].y - points[i].y) + points[i].x))
|
||||||
|
{
|
||||||
if ((((vc.y >= point.y) && (vn.y < point.y)) || ((vc.y < point.y) && (vn.y >= point.y))) &&
|
inside = !inside;
|
||||||
(point.x < ((vn.x - vc.x)*(point.y - vc.y)/(vn.y - vc.y) + vc.x))) collision = !collision;
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return collision;
|
return inside;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check collision between two rectangles
|
// Check collision between two rectangles
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue