Advertisement
lewapkon

AABB collision

Jul 28th, 2013
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.78 KB | None | 0 0
  1. public class AABB
  2. {
  3.    protected Vector2 center, halfSize;
  4.    
  5.    public AABB(Vector2 center, Vector2 halfSize)
  6.    {
  7.       this.center = center;
  8.       this.halfSize = halfSize;
  9.    }
  10.    
  11.    public static boolean collides(AABB a, AABB b)
  12.    {
  13.       if(Math.abs(a.center.x - b.center.x) < a.halfSize.x + b.halfSize.x)
  14.       {
  15.          if(Math.abs(a.center.y - b.center.y) < a.halfSize.y + b.halfSize.y)
  16.          {
  17.             return true;
  18.          }
  19.       }
  20.      
  21.       return false;
  22.    }
  23.    
  24.    public static boolean inside(AABB a, Vector2Float b)
  25.    {
  26.       if(Math.abs(a.center.x - b.center.x) < a.halfSize.x)
  27.       {
  28.          if(Math.abs(a.center.y - b.center.y) < a.halfSize.y)
  29.          {
  30.             return true;
  31.          }
  32.       }
  33.       return false;
  34.    }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement