Exemplo n.º 1
0
  public boolean collidesWith(Polygon poly2) {
    Vector2D[] poly1Axes = SeparatingAxisTheorem.getSepAxes(this.mPolyVecs);
    Vector2D[] poly2Axes = SeparatingAxisTheorem.getSepAxes(poly2.mPolyVecs);
    ;

    for (int a = 0; a < poly1Axes.length; a++) {
      Vector2D proj1 = SeparatingAxisTheorem.getShapeProjection(poly1Axes[a], this.mPolyVecs);
      Vector2D proj2 = SeparatingAxisTheorem.getShapeProjection(poly1Axes[a], poly2.mPolyVecs);

      if (SeparatingAxisTheorem.projOverlap(proj1, proj2)) {
        return false;
      }
    }

    for (int b = 0; b < poly2Axes.length; b++) {
      Vector2D proj1 = SeparatingAxisTheorem.getShapeProjection(poly2Axes[b], this.mPolyVecs);
      Vector2D proj2 = SeparatingAxisTheorem.getShapeProjection(poly2Axes[b], poly2.mPolyVecs);

      if (SeparatingAxisTheorem.projOverlap(proj1, proj2)) {
        return false;
      }
    }

    return true;
  }
Exemplo n.º 2
0
  public MTV getMTV(Polygon poly2) {
    float mainOverlap = Float.MAX_VALUE;
    Vector2D smallest = null;

    Vector2D[] poly1Axes = SeparatingAxisTheorem.getSepAxes(this.mPolyVecs);
    Vector2D[] poly2Axes = SeparatingAxisTheorem.getSepAxes(poly2.mPolyVecs);

    for (int a = 0; a < poly1Axes.length; a++) {
      Vector2D proj1 = SeparatingAxisTheorem.getShapeProjection(poly1Axes[a], this.mPolyVecs);
      Vector2D proj2 = SeparatingAxisTheorem.getShapeProjection(poly1Axes[a], poly2.mPolyVecs);

      if (SeparatingAxisTheorem.projOverlap(proj1, proj2)) {
        return null;
      } else {
        float tempOverlap1 = SeparatingAxisTheorem.getOverlap(proj1, proj2);

        if (tempOverlap1 < mainOverlap) {
          mainOverlap = tempOverlap1;
          smallest = poly1Axes[a];
        }
      }
    }

    for (int b = 0; b < poly2Axes.length; b++) {
      Vector2D proj1 = SeparatingAxisTheorem.getShapeProjection(poly2Axes[b], this.mPolyVecs);
      Vector2D proj2 = SeparatingAxisTheorem.getShapeProjection(poly2Axes[b], poly2.mPolyVecs);

      if (SeparatingAxisTheorem.projOverlap(proj1, proj2)) {
        return null;
      } else {
        float tempOverlap2 = SeparatingAxisTheorem.getOverlap(proj1, proj2);

        if (tempOverlap2 < mainOverlap) {
          mainOverlap = tempOverlap2;
          smallest = poly2Axes[b];
        }
      }
    }

    return new MTV(smallest, mainOverlap);
  }