Merge pull request #622 from Joefish/rectcollision-optim
Shapes: Simplifies CheckCollisionRecs
This commit is contained in:
commit
20ff9dc663
1 changed files with 5 additions and 8 deletions
13
src/shapes.c
13
src/shapes.c
|
@ -646,14 +646,11 @@ bool CheckCollisionPointTriangle(Vector2 point, Vector2 p1, Vector2 p2, Vector2
|
||||||
// Check collision between two rectangles
|
// Check collision between two rectangles
|
||||||
bool CheckCollisionRecs(Rectangle rec1, Rectangle rec2)
|
bool CheckCollisionRecs(Rectangle rec1, Rectangle rec2)
|
||||||
{
|
{
|
||||||
bool collision = false;
|
if ((rec1.x <= (rec2.x + rec2.width) && (rec1.x + rec1.width) >= rec2.x) &&
|
||||||
|
(rec1.y <= (rec2.y + rec2.height) && (rec1.y + rec1.height) >= rec2.y))
|
||||||
float dx = (float)fabs((rec1.x + rec1.width/2) - (rec2.x + rec2.width/2));
|
return true;
|
||||||
float dy = (float)fabs((rec1.y + rec1.height/2) - (rec2.y + rec2.height/2));
|
else
|
||||||
|
return false;
|
||||||
if ((dx <= (rec1.width/2 + rec2.width/2)) && ((dy <= (rec1.height/2 + rec2.height/2)))) collision = true;
|
|
||||||
|
|
||||||
return collision;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check collision between two circles
|
// Check collision between two circles
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue