added GetRectangleOverlap()
This commit is contained in:
parent
2b59e7475f
commit
b94cf4daca
|
|
@ -1318,6 +1318,7 @@ RLAPI bool CheckCollisionPointLine(Vector2 point, Vector2 p1, Vector2 p2, int th
|
||||||
RLAPI bool CheckCollisionPointPoly(Vector2 point, const Vector2 *points, int pointCount); // Check if point is within a polygon described by array of vertices
|
RLAPI bool CheckCollisionPointPoly(Vector2 point, const Vector2 *points, int pointCount); // 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 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
|
||||||
|
RLAPI Rectangle GetRectangleOverlap(Rectangle a, Rectangle b); // Get smallest rectangle entirely overlapping both rectangles
|
||||||
|
|
||||||
//------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------
|
||||||
// Texture Loading and Drawing Functions (Module: textures)
|
// Texture Loading and Drawing Functions (Module: textures)
|
||||||
|
|
|
||||||
|
|
@ -2405,6 +2405,36 @@ Rectangle GetCollisionRec(Rectangle rec1, Rectangle rec2)
|
||||||
return overlap;
|
return overlap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get smallest rectangle entirely overlapping both rectangles
|
||||||
|
Rectangle GetRectangleOverlap(Rectangle a, Rectangle b) {
|
||||||
|
|
||||||
|
Rectangle overlap;
|
||||||
|
Rectangle left, right, top, bottom;
|
||||||
|
|
||||||
|
if (a.x == b.x) {
|
||||||
|
left = (a.width == fmin(a.width, b.width)) ? a : b;
|
||||||
|
right = (a.width == fmax(a.width, b.width)) ? a : b;
|
||||||
|
} else {
|
||||||
|
left = (a.x < b.x) ? a : b;
|
||||||
|
right = (a.x > b.x) ? a : b;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (a.y == b.y) {
|
||||||
|
top = (a.height == fmin(a.height, b.height)) ? a : b;
|
||||||
|
bottom = (a.height == fmax(a.height, b.height)) ? a : b;
|
||||||
|
} else {
|
||||||
|
top = (a.y < b.y) ? a : b;
|
||||||
|
bottom = (a.y > b.y) ? a : b;
|
||||||
|
}
|
||||||
|
|
||||||
|
overlap.x = fmin(a.x, b.x);
|
||||||
|
overlap.y = fmin(a.y, b.y);
|
||||||
|
overlap.width = fmax(left.width + (right.x - (left.x + left.width) + right.width), left.width);
|
||||||
|
overlap.height = fmax(top.height + (bottom.y - (top.y + top.height) + bottom.height), top.height);
|
||||||
|
|
||||||
|
return overlap;
|
||||||
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
// Module specific Functions Definition
|
// Module specific Functions Definition
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user