Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- bool AxisAlignedBoundaryBox::Intersects(AxisAlignedBoundaryBox const & aabb1, float2 const & offset1, AxisAlignedBoundaryBox const & aabb2, float2 const & offset2)
- {
- float minX1 = aabb1.X + offset1.X;
- float maxX1 = aabb1.X + aabb1.Width + offset1.X;
- float minY1 = aabb1.Y + offset1.Y;
- float maxY1 = aabb1.Y + aabb1.Height + offset1.Y;
- float minX2 = aabb2.X + offset2.X;
- float maxX2 = aabb2.X + aabb2.Width + offset2.X;
- float minY2 = aabb2.Y + offset2.Y;
- float maxY2 = aabb2.Y + aabb2.Height + offset2.Y;
- return minX1 < maxX2 && maxX1 > minX2 && minY1 < maxY2 && maxY1 > minY2;
- }
- float2 AxisAlignedBoundaryBox::MinimumTranslationDistance(AxisAlignedBoundaryBox const & aabb1, float2 const & offset1, AxisAlignedBoundaryBox const & aabb2, float2 const & offset2)
- {
- float2 result;
- float minX1 = aabb1.X + offset1.X;
- float maxX1 = aabb1.X + aabb1.Width + offset1.X;
- float minY1 = aabb1.Y + offset1.Y;
- float maxY1 = aabb1.Y + aabb1.Height + offset1.Y;
- float minX2 = aabb2.X + offset2.X;
- float maxX2 = aabb2.X + aabb2.Width + offset2.X;
- float minY2 = aabb2.Y + offset2.Y;
- float maxY2 = aabb2.Y + aabb2.Height + offset2.Y;
- result.X = maxX1 - minX2 < maxX2 - minX1 ? minX2 - maxX1 : maxX2 - minX1;
- result.Y = maxY1 - minY2 < maxY2 - minY1 ? minY2 - maxY1 : maxY2 - minY1;
- if (result.X < result.Y)
- {
- result.Y = 0;
- }
- else
- {
- result.X = 0;
- }
- return result;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement