ADDED: CheckCollisionLines()
Removed function from raymath
This commit is contained in:
parent
2bdb45f280
commit
b78ee13791
3 changed files with 26 additions and 40 deletions
24
src/shapes.c
24
src/shapes.c
|
@ -1471,6 +1471,30 @@ bool CheckCollisionCircleRec(Vector2 center, float radius, Rectangle rec)
|
|||
return (cornerDistanceSq <= (radius*radius));
|
||||
}
|
||||
|
||||
// Check the collision between two lines defined by two points each, returns collision point by reference
|
||||
bool CheckCollisionLines(Vector2 startPos1, Vector2 endPos1, Vector2 startPos2, Vector2 endPos2, Vector2 *collisionPoint)
|
||||
{
|
||||
const float div = (endPos2.y - startPos2.y)*(endPos1.x - startPos1.x) - (endPos2.x - startPos2.x)*(endPos1.y - startPos1.y);
|
||||
|
||||
if (div == 0.0f) return false; // WARNING: This check could not work due to float precission rounding issues...
|
||||
|
||||
const float xi = ((startPos2.x - startPos2.x)*(startPos1.x*endPos1.y - startPos1.y*endPos1.x) - (startPos1.x - endPos1.x)*(startPos2.x*endPos2.y - startPos2.y*endPos2.x))/div;
|
||||
const float yi = ((startPos2.y - endPos2.y)*(startPos1.x*endPos1.y - startPos1.y*endPos1.x) - (startPos1.y - endPos1.y)*(startPos2.x*endPos2.y - startPos2.y*endPos2.x))/div;
|
||||
|
||||
if (xi < fminf(startPos1.x, endPos1.x) || xi > fmaxf(startPos1.x, endPos1.x)) return false;
|
||||
if (xi < fminf(startPos2.x, endPos2.x) || xi > fmaxf(startPos2.x, endPos2.x)) return false;
|
||||
if (yi < fminf(startPos1.y, endPos1.y) || yi > fmaxf(startPos1.y, endPos1.y)) return false;
|
||||
if (yi < fminf(startPos2.y, endPos2.y) || yi > fmaxf(startPos2.y, endPos2.y)) return false;
|
||||
|
||||
if (collisionPoint != NULL)
|
||||
{
|
||||
collisionPoint->x = xi;
|
||||
collisionPoint->y = yi;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Get collision rectangle for two rectangles collision
|
||||
Rectangle GetCollisionRec(Rectangle rec1, Rectangle rec2)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue