私は作成中のゲームの物理演算に Box2D を使用しています。Box2D を使用して長方形を取り、実際の物理演算を行わずに別の長方形と衝突するかどうかを確認する方法があるかどうかを確認したかったのです。例:
bool RectInRect(rect p1, rect p2)
{
bool result = Box2D_do_rect_stuff();
return result;
}
前もって感謝します!
と仮定するとrect{x1,y1,x2,y2}
、次のようにx1<x2
なり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);
}