Exemple #1
0
 @Override
 protected boolean intersectsOnOwnAxes(Shape s) {
   // return getHorizontalProjection().intersects(s.getHorizontalProjection()) &&
   //        getVerticalProjection().intersects(s.getVerticalProjection());
   return s.getHorizontalProjection().intersects(v00.x(), v11.x())
       && s.getVerticalProjection().intersects(v00.y(), v11.y());
 }
Exemple #2
0
 @Override
 public AABBOld reflect() {
   // We need to manually do this since AABB breaks if v00 is to the right
   // of v11, as we make algorithmic simplifications on the assumption
   // that v00 is always to the left of v11.
   return new AABBOld(Vec2.immutable(-v11.x(), v00.y()), Vec2.immutable(-v00.x(), v11.y()));
 }
Exemple #3
0
 @Override
 protected Vec2[] getVertices() {
   // throw new UnsupportedOperationException("AABB should have no need "
   //        + "for getVertices()!");
   return new Vec2[] {
     v00,
     Vec2.immutable(v11.x(), v00.y()), // v10
     v11,
     Vec2.immutable(v00.x(), v11.y()) // v01
   };
 }
Exemple #4
0
  @Override
  protected ShapeProjection getProjection(Vec2 axis) {
    // This method of computation is preferable to the default impl.,
    // which invokes getVertices().

    float p0 = axis.dot(v00);
    float p1 = axis.dot(v11);
    float p2 = axis.dot(v00.x(), v11.y());
    float p3 = axis.dot(v11.x(), v00.y());

    return new ShapeProjection(
        Maths.min(Maths.min(p0, p1), Maths.min(p2, p3)),
        Maths.max(Maths.max(p0, p1), Maths.max(p2, p3)));
  }
Exemple #5
0
 /**
  * Creates a new AABB. It is implicitly trusted that the given values for {@code width} and {@code
  * height} are non-negative.
  *
  * @param x The x-coordinate of the AABB's bottom-left vertex.
  * @param y The y-coordinate of the AABB's bottom-left vertex.
  * @param width The AABB's width.
  * @param height The AABB's height.
  */
 public AABBOld(float x, float y, float width, float height) {
   v00 = Vec2.immutable(x, y);
   v11 = Vec2.immutable(x + width, y + height);
 }
Exemple #6
0
 /** Calculates and returns the height of this AABB. */
 public float height() {
   return v11.y() - v00.y();
 }
Exemple #7
0
 /** Calculates and returns the width of this AABB. */
 public float width() {
   return v11.x() - v00.x();
 }
Exemple #8
0
 /** Gets the y-coordinate of the top-right vertex of this AABB. */
 public float getMaxY() {
   return v11.y();
 }
Exemple #9
0
 /** Gets the x-coordinate of the top-right vertex of this AABB. */
 public float getMaxX() {
   return v11.x();
 }
Exemple #10
0
 /**
  * Gets the y-coordinate of the bottom-left vertex - or the origin - of this AABB.
  *
  * @return The y-coordinate of this AABB's origin.
  */
 public float getOriginY() {
   return v00.y();
 }
Exemple #11
0
 /**
  * Gets the x-coordinate of the bottom-left vertex - or the origin - of this AABB.
  *
  * @return The x-coordinate of this AABB's origin.
  */
 public float getOriginX() {
   return v00.x();
 }
Exemple #12
0
 @Override
 ShapeProjection getVerticalProjection() {
   return new ShapeProjection(v00.y(), v11.y());
 }
Exemple #13
0
 @Override
 ShapeProjection getHorizontalProjection() {
   return new ShapeProjection(v00.x(), v11.x());
 }
Exemple #14
0
 @Override
 public boolean containsPoint(float x, float y) {
   return x >= v00.x() && x <= v11.x() && y >= v00.y() && y <= v11.y();
 }
Exemple #15
0
 /**
  * Calculates whether or not this AABB contains the specified AABB.
  *
  * @return {@code true} if this AABB contains {@code a}; {@code false} otherwise.
  */
 public boolean containsAABB(AABBOld a) {
   return v00.x() <= a.v00.x()
       && v11.x() >= a.v11.x()
       && v00.y() <= a.v00.y()
       && v11.y() >= a.v11.y();
 }
Exemple #16
0
 /**
  * Calculates whether or not two axis-aligned bounding boxes intersect.
  *
  * @param a The AABB with which to test intersection.
  * @return {@code true} if the two AABBs intersect; {@code false} otherwise.
  */
 public boolean intersectsAABB(AABBOld a) {
   return v00.x() <= a.v11.x()
       && v11.x() >= a.v00.x()
       && v00.y() <= a.v11.y()
       && v11.y() >= a.v00.y();
 }