mirror of
https://github.com/raysan5/raylib.git
synced 2025-09-14 07:18:14 +00:00
REVIEWED: CheckCollisionPointPoly()
This commit is contained in:
@@ -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;
|
||||
|
Reference in New Issue
Block a user