예제 #1
0
  /**
   * Calculates the culling area of the bounding box after it has scaled, rotated and translates.
   * This bounding box contains a bunch of vertices. This way i don't have to merge hundreds of
   * vertices to get a reasonable culling area, just the four of the bounding box.
   */
  private Rectangle getCullingArea(
      Rectangle cullingArea,
      Rectangle boundingBox,
      float rotation,
      Vector2 translation,
      float scale) {

    tmp.set(boundingBox.x, boundingBox.y).scl(scale).rotateRad(rotation).add(translation);
    cullingArea.set(tmp.x, tmp.y, 0, 0);

    tmp.set(boundingBox.x + boundingBox.width, boundingBox.y)
        .scl(scale)
        .rotateRad(rotation)
        .add(translation);
    cullingArea.merge(tmp);

    tmp.set(boundingBox.x + boundingBox.width, boundingBox.y + boundingBox.height)
        .scl(scale)
        .rotateRad(rotation)
        .add(translation);
    cullingArea.merge(tmp);

    tmp.set(boundingBox.x, boundingBox.y + boundingBox.height)
        .scl(scale)
        .rotateRad(rotation)
        .add(translation);
    cullingArea.merge(tmp);

    return cullingArea;
  }
예제 #2
0
  public Rectangle getBoundingRectangle() {
    Rectangle rectangle = new Rectangle();
    boolean initialized = false;

    for (BoundingBox boundingBox : boundingBoxes) {
      updateBoxCulling(boundingBox);

      Rectangle cullingArea =
          getCullingArea(tmpRectangle, boundingBox.rectangle, angleRad, position, scale);

      if (!initialized) {
        rectangle.set(cullingArea);
        initialized = true;
      } else rectangle.merge(cullingArea);
    }

    return rectangle;
  }
예제 #3
0
  // TODO Comment
  private void updateBoxCulling(BoundingBox box) {
    Rectangle rectangle = box.rectangle;

    box.dataCount = 0;

    boolean initialized = false;
    for (int n = box.begin; n < box.begin + box.count; n++) {

      Array<Float> inside = vertexDataArray.items[n].insideVertexData;
      Array<Float> outside = vertexDataArray.items[n].outsideVertexData;

      if (!initialized) {
        if (inside.size > 0 && drawInside) {
          rectangle.set(inside.items[0], inside.items[1], 0, 0);
        } else if (outside.size > 0 && drawOutside) {
          rectangle.set(outside.items[0], outside.items[1], 0, 0);
        }

        if (closedPolygon || n > 0) {
          int k = (box.begin - 1 + vertices.size) % vertices.size;

          if (drawInside) {
            Array<Float> _inside = vertexDataArray.items[k].insideVertexData;
            for (int i = 0; i < _inside.size; i += 3) {
              rectangle.merge(_inside.items[i], _inside.items[i + 1]);
              box.dataCount++;
            }
          }

          if (drawOutside) {
            Array<Float> _outside = vertexDataArray.items[k].outsideVertexData;
            for (int i = 0; i < _outside.size; i += 3) {
              rectangle.merge(_outside.items[i], _outside.items[i + 1]);
              box.dataCount++;
            }
          }
        }

        if (closedPolygon || n < vertices.size) {
          int k = (box.begin + box.count + vertices.size) % vertices.size;

          if (drawInside) {
            Array<Float> _inside = vertexDataArray.items[k].insideVertexData;
            for (int i = 0; i < _inside.size; i += 3) {
              rectangle.merge(_inside.items[i], _inside.items[i + 1]);
              box.dataCount++;
            }
          }

          if (drawOutside) {
            Array<Float> _outside = vertexDataArray.items[k].outsideVertexData;
            for (int i = 0; i < _outside.size; i += 3) {
              rectangle.merge(_outside.items[i], _outside.items[i + 1]);
              box.dataCount++;
            }
          }
        }

        initialized = true;
      }

      if (drawInside)
        for (int i = 0; i < inside.size; i += 3) {
          rectangle.merge(inside.items[i], inside.items[i + 1]);
          box.dataCount++;
        }

      if (drawOutside)
        for (int i = 0; i < outside.size; i += 3) {
          rectangle.merge(outside.items[i], outside.items[i + 1]);
          box.dataCount++;
        }
    }
  }