1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
|
bool BoundingBox(Rect & Object1, vector<Rect> & Object2)
{
OrientedBoundingBox OBB1(Object1); // <- The definitions for the constructors are above.
OrientedBoundingBox OBB2(Object2);
sf::Vector2f Axis[4] =
{
sf::Vector2f(OBB1.Points[1].x - OBB1.Points[0].x, OBB1.Points[1].y - OBB1.Points[0].y),
sf::Vector2f(OBB1.Points[1].x - OBB1.Points[2].x, OBB1.Points[1].y - OBB1.Points[2].y),
sf::Vector2f(OBB2.Points[0].x - OBB2.Points[3].x, OBB2.Points[0].y - OBB2.Points[3].y),
sf::Vector2f(OBB2.Points[0].x - OBB2.Points[1].x, OBB2.Points[0].y - OBB2.Points[1].y)
};
for(int i = 0; i < 4; i++)
{
float MinOBB1, MaxOBB1, MinOBB2, MaxOBB2;
OBB1.ProjectOntoAxis(Axis[i], MinOBB1, MaxOBB1);
OBB2.ProjectOntoAxis(Axis[i], MinOBB2, MaxOBB2);
if(!((MinOBB2 <= MaxOBB1) && (MaxOBB2 >= MinOBB1)))
return false;
}
return true;
}
|