Exemple #1
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 #2
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 #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
 /** Calculates and returns the height of this AABB. */
 public float height() {
   return v11.y() - v00.y();
 }
Exemple #6
0
 /** Gets the y-coordinate of the top-right vertex of this AABB. */
 public float getMaxY() {
   return v11.y();
 }
Exemple #7
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 #8
0
 @Override
 ShapeProjection getVerticalProjection() {
   return new ShapeProjection(v00.y(), v11.y());
 }
Exemple #9
0
 @Override
 public boolean containsPoint(float x, float y) {
   return x >= v00.x() && x <= v11.x() && y >= v00.y() && y <= v11.y();
 }
Exemple #10
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 #11
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();
 }