Box2D Rectangle Collision
I am using Box2D for physics for a game I am making, and I wanted to see if there was a way to use Box2D so that a could take a rectangle and see if it collide with开发者_如何学运维 another rectangle without it doing any actual physics. Example:
bool RectInRect(rect p1, rect p2)
{
bool result = Box2D_do_rect_stuff();
return result;
}
Thanks in advance!
Assuming that rect{x1,y1,x2,y2}
, and that x1<x2
and y1<y2
:
bool RectInRect(rect p1, rect p2)
{
pair<const int&, const int&> p1x = minmax(p1.x1, p1.x2);
pair<const int&, const int&> p1y = minmax(p1.y1, p1.y2);
pair<const int&, const int&> p2x = minmax(p2.x1, p2.x2);
pair<const int&, const int&> p2y = minmax(p2.y1, p2.y2);
return max(p1x.first, p2x.first) <= min(p1x.second, p2x.second) &&
max(p1y.first, p2y.first) <= min(p1y.second, p2y.second);
}
精彩评论