Advertisement
Guest User

Untitled

a guest
Aug 19th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.39 KB | None | 0 0
  1. bool AxisAlignedBoundaryBox::Intersects(AxisAlignedBoundaryBox const & aabb1, float2 const & offset1, AxisAlignedBoundaryBox const & aabb2, float2 const & offset2)
  2. {
  3.     float minX1 = aabb1.X + offset1.X;
  4.     float maxX1 = aabb1.X + aabb1.Width + offset1.X;
  5.     float minY1 = aabb1.Y + offset1.Y;
  6.     float maxY1 = aabb1.Y + aabb1.Height + offset1.Y;
  7.  
  8.     float minX2 = aabb2.X + offset2.X;
  9.     float maxX2 = aabb2.X + aabb2.Width + offset2.X;
  10.     float minY2 = aabb2.Y + offset2.Y;
  11.     float maxY2 = aabb2.Y + aabb2.Height + offset2.Y;
  12.  
  13.     return minX1 < maxX2 && maxX1 > minX2 && minY1 < maxY2 && maxY1 > minY2;
  14. }
  15.  
  16. float2 AxisAlignedBoundaryBox::MinimumTranslationDistance(AxisAlignedBoundaryBox const & aabb1, float2 const & offset1, AxisAlignedBoundaryBox const & aabb2, float2 const & offset2)
  17. {
  18.     float2 result;
  19.  
  20.     float minX1 = aabb1.X + offset1.X;
  21.     float maxX1 = aabb1.X + aabb1.Width + offset1.X;
  22.     float minY1 = aabb1.Y + offset1.Y;
  23.     float maxY1 = aabb1.Y + aabb1.Height + offset1.Y;
  24.  
  25.     float minX2 = aabb2.X + offset2.X;
  26.     float maxX2 = aabb2.X + aabb2.Width + offset2.X;
  27.     float minY2 = aabb2.Y + offset2.Y;
  28.     float maxY2 = aabb2.Y + aabb2.Height + offset2.Y;
  29.  
  30.     result.X = maxX1 - minX2 < maxX2 - minX1 ? minX2 - maxX1 : maxX2 - minX1;
  31.     result.Y = maxY1 - minY2 < maxY2 - minY1 ? minY2 - maxY1 : maxY2 - minY1;
  32.     if (result.X < result.Y)
  33.     {
  34.         result.Y = 0;
  35.     }
  36.     else
  37.     {
  38.         result.X = 0;
  39.     }
  40.     return result;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement