Use vertices instead of points in CheckCollisionPointPoly
This commit is contained in:
parent
144ae120ab
commit
4c583a18b7
|
|
@ -1215,7 +1215,7 @@ RLAPI bool CheckCollisionCircleRec(Vector2 center, float radius, Rectangle rec);
|
||||||
RLAPI bool CheckCollisionPointRec(Vector2 point, Rectangle rec); // Check if point is inside rectangle
|
RLAPI bool CheckCollisionPointRec(Vector2 point, Rectangle rec); // Check if point is inside rectangle
|
||||||
RLAPI bool CheckCollisionPointCircle(Vector2 point, Vector2 center, float radius); // Check if point is inside circle
|
RLAPI bool CheckCollisionPointCircle(Vector2 point, Vector2 center, float radius); // Check if point is inside circle
|
||||||
RLAPI bool CheckCollisionPointTriangle(Vector2 point, Vector2 p1, Vector2 p2, Vector2 p3); // Check if point is inside a triangle
|
RLAPI bool CheckCollisionPointTriangle(Vector2 point, Vector2 p1, Vector2 p2, Vector2 p3); // Check if point is inside a triangle
|
||||||
RLAPI bool CheckCollisionPointPoly(Vector2 point, Vector2 *points, int pointCount); // Check if point is within a polygon described by array of vertices
|
RLAPI bool CheckCollisionPointPoly(Vector2 point, Vector2 *vertices, int verticesCount); // Check if point is within a polygon described by array of vertices
|
||||||
RLAPI bool CheckCollisionLines(Vector2 startPos1, Vector2 endPos1, Vector2 startPos2, Vector2 endPos2, Vector2 *collisionPoint); // Check the collision between two lines defined by two points each, returns collision point by reference
|
RLAPI bool CheckCollisionLines(Vector2 startPos1, Vector2 endPos1, Vector2 startPos2, Vector2 endPos2, Vector2 *collisionPoint); // Check the collision between two lines defined by two points each, returns collision point by reference
|
||||||
RLAPI bool CheckCollisionPointLine(Vector2 point, Vector2 p1, Vector2 p2, int threshold); // Check if point belongs to line created between two points [p1] and [p2] with defined margin in pixels [threshold]
|
RLAPI bool CheckCollisionPointLine(Vector2 point, Vector2 p1, Vector2 p2, int threshold); // Check if point belongs to line created between two points [p1] and [p2] with defined margin in pixels [threshold]
|
||||||
RLAPI Rectangle GetCollisionRec(Rectangle rec1, Rectangle rec2); // Get collision rectangle for two rectangles collision
|
RLAPI Rectangle GetCollisionRec(Rectangle rec1, Rectangle rec2); // Get collision rectangle for two rectangles collision
|
||||||
|
|
|
||||||
|
|
@ -1635,16 +1635,16 @@ bool CheckCollisionPointTriangle(Vector2 point, Vector2 p1, Vector2 p2, Vector2
|
||||||
|
|
||||||
// Check if point is within a polygon described by array of vertices
|
// Check if point is within a polygon described by array of vertices
|
||||||
// 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 *vertices, int verticesCount)
|
||||||
{
|
{
|
||||||
bool collision = false;
|
bool collision = false;
|
||||||
|
|
||||||
if (pointCount > 2)
|
if (verticesCount > 2)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < pointCount - 1; i++)
|
for (int i = 0; i < verticesCount - 1; i++)
|
||||||
{
|
{
|
||||||
Vector2 vc = points[i];
|
Vector2 vc = vertices[i];
|
||||||
Vector2 vn = points[i + 1];
|
Vector2 vn = vertices[i + 1];
|
||||||
|
|
||||||
if ((((vc.y >= point.y) && (vn.y < point.y)) || ((vc.y < point.y) && (vn.y >= point.y))) &&
|
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;
|
(point.x < ((vn.x - vc.x)*(point.y - vc.y)/(vn.y - vc.y) + vc.x))) collision = !collision;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user