Esempio n. 1
0
  private void updateVertices() {
    verticesMustBeUpdated = false;

    Array<Vector2> vertices = new Array<Vector2>();

    float step = MathUtils.PI2 / (float) vertexCount;

    for (float i = 0; i < vertexCount; i++) {
      Vector2 v = new Vector2(radius, 0);
      v.rotateRad(step * i);
      vertices.add(v);
    }

    for (OutlinePolygon outlinePolygon : basic.outlinePolygons) {
      outlinePolygon.setVertices(vertices);
    }

    if (basic.texturePolygon != null) {
      basic.texturePolygon.setVertices(vertices);
    }

    if (basic.physicsThing != null) {
      ((Circle) basic.physicsThing).setRadius(radius);
    }
  }
Esempio n. 2
0
  private void drawTriangleStrips(ShapeRenderer shapeRenderer, Color color, Color color1) {
    for (int i = 0; i < vertexDataArray.size; i++) {
      StripVertex bb = vertexDataArray.items[i];

      Array<Float> data = bb.insideVertexData;
      for (int j = 0; j < data.size - 3; ) {

        shapeRenderer.setColor(j == 0 ? color : color1);

        tmp.x = data.items[j];
        tmp.y = data.items[j + 1];
        tmp.rotateRad(angleRad);
        tmp.scl(scale);
        tmp.add(position);

        tmp1.x = data.items[j + 3];
        tmp1.y = data.items[j + 4];
        tmp1.rotateRad(angleRad);
        tmp1.scl(scale);
        tmp1.add(position);
        j += 3;

        shapeRenderer.line(tmp, tmp1);
      }
      data = bb.outsideVertexData;
      for (int j = 0; j < data.size - 3; ) {

        shapeRenderer.setColor(j == 0 ? Color.ORANGE : Color.RED);

        tmp.x = data.items[j];
        tmp.y = data.items[j + 1];
        tmp.rotateRad(angleRad);
        tmp.scl(scale);
        tmp.add(position);

        tmp1.x = data.items[j + 3];
        tmp1.y = data.items[j + 4];
        tmp1.rotateRad(angleRad);
        tmp1.scl(scale);
        tmp1.add(position);
        j += 3;

        shapeRenderer.line(tmp, tmp1);
      }
    }
  }
Esempio n. 3
0
  private void drawLineFromFirstToLast(ShapeRenderer shapeRenderer, Color color) {
    shapeRenderer.setColor(color);
    for (BoundingBox br : boundingBoxes) {

      tmp.set(vertices.items[br.begin]);
      tmp.rotateRad(angleRad);
      tmp.scl(scale);
      tmp.add(position);

      tmp1.set(vertices.items[(br.begin + br.count) % vertices.size]);
      tmp1.rotateRad(angleRad);
      tmp1.scl(scale);
      tmp1.add(position);

      shapeRenderer.line(tmp, tmp1);
    }
  }
Esempio n. 4
0
  @Override
  public Array<Vector2> getVerticesRotatedScaledAndTranslated(
      float rotation, float scale, float transX, float transY) {

    for (int i = 0; i < vertices.size; i++) {
      Vector2 w = verticesRotatedAndTranslated.items[i];
      w.set(vertices.items[i]);
      w.rotateRad(rotation);
      w.scl(scale);
      w.add(transX, transY);
    }
    return verticesRotatedAndTranslated;
  }
Esempio n. 5
0
    /** When the polygon is not closed we need auxiliary vertices to round the beginning. */
    private Vector2 getAuxEnding(Array<Vector2> vertices, int i, float extraAngleRad) {
      Util.getEdge(vertices, (i - 1 + vertices.size) % vertices.size, m1, m2);
      nor1.set(m2).sub(m1).nor().scl(halfWidth);

      int dir = clockWisePolygon ? 1 : -1;

      if (insideStrip) dir *= -1;

      nor1.rotate90(dir);
      nor1.rotateRad(extraAngleRad * (-dir));

      return new Vector2(m2).add(nor1);
    }