Update GetCollisionRec
Replace macros with ternary operators
This commit is contained in:
parent
cb2239f2f3
commit
81185bf85a
|
|
@ -1757,31 +1757,30 @@ bool CheckCollisionPointLine(Vector2 point, Vector2 p1, Vector2 p2, int threshol
|
|||
}
|
||||
|
||||
// Get collision rectangle for two rectangles collision
|
||||
#define MIN_MACRO(X,Y) ((X) < (Y) ? (X) : (Y)) //Define ugly macros to get both gcc and clang
|
||||
#define MAX_MACRO(X,Y) ((X) > (Y) ? (X) : (Y)) //to reduce min and max to single instructions
|
||||
Rectangle GetCollisionRec(Rectangle rec1, Rectangle rec2){
|
||||
Rectangle overlap;
|
||||
|
||||
float left = MAX_MACRO(rec1.x, rec2.x);
|
||||
float right = MIN_MACRO(rec1.x + rec1.width, rec2.x + rec2.width);
|
||||
float top = MAX_MACRO(rec1.y, rec2.y);
|
||||
float bottom = MIN_MACRO(rec1.y + rec1.height, rec2.y + rec2.height);
|
||||
float left = ((rec1.x) > (rec2.x) ? (rec1.x) : (rec2.x));
|
||||
float right1 = rec1.x + rec1.width;
|
||||
float right2 = rec2.x + rec2.width;
|
||||
float right = ((right1) < (right2) ? (right1) : (right2));
|
||||
float top = ((rec1.y) > (rec2.y) ? (rec1.y) : (rec2.y));
|
||||
float bottom1 = rec1.y + rec1.height;
|
||||
float bottom2 = rec2.y + rec2.height;
|
||||
float bottom = ((bottom1) < (bottom2) ? (bottom1) : (bottom2));
|
||||
if (left < right && top < bottom){
|
||||
overlap.x = left;
|
||||
overlap.y = top;
|
||||
overlap.width = right - left;
|
||||
overlap.height = bottom - top;
|
||||
} else {
|
||||
overlap.x = (left);
|
||||
overlap.y = (top);
|
||||
overlap.width = (right - left );
|
||||
overlap.height = (bottom - top);
|
||||
}
|
||||
else{
|
||||
overlap.x = 0;
|
||||
overlap.y = 0;
|
||||
overlap.width = 0;
|
||||
overlap.height = 0;
|
||||
}
|
||||
|
||||
return overlap;
|
||||
}
|
||||
#undef MIN_MACRO //Undefine macros again
|
||||
#undef MAX_MACRO
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Module specific Functions Definition
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user