Exemple #1
0
  /** Renders a blue rectangle showing the field of view of the closeup camera */
  public void render(ShapeRenderer renderer) {
    if (!inCloseupMode) {
      // Figure out the location of the camera corners in the world
      Vector2 bottomLeft = myUnproject(closeupCamera, 0, closeupCamera.viewportHeight);
      Vector2 bottomRight =
          myUnproject(closeupCamera, closeupCamera.viewportWidth, closeupCamera.viewportHeight);
      Vector2 topRight = myUnproject(closeupCamera, closeupCamera.viewportWidth, 0);
      Vector2 topLeft = myUnproject(closeupCamera, 0, 0);

      // Draw a rectangle showing the closeup camera's field of view
      renderer.begin(ShapeType.Line);
      renderer.setColor(Color.BLUE);
      float[] poly = {
        bottomLeft.x,
        bottomLeft.y,
        bottomRight.x,
        bottomRight.y,
        topRight.x,
        topRight.y,
        topLeft.x,
        topLeft.y
      };
      renderer.set(ShapeType.Line);
      renderer.polygon(poly);
      renderer.end();
    }
  }
  public void drawBBoxLines(ShapeRenderer renderer) {
    // renderer.begin(ShapeType.Rectangle);
    renderer.begin(ShapeType.Line);

    for (BaseActor a : actors.values()) {
      Polygon p = a.getBBox();

      if (p == null) {
        EngineLogger.error("ERROR DRAWING BBOX FOR: " + a.getId());
      }

      if (a instanceof ObstacleActor) renderer.setColor(OBSTACLE_COLOR);
      else renderer.setColor(ACTOR_BBOX_COLOR);

      renderer.polygon(p.getTransformedVertices());

      // Rectangle r = a.getBBox().getBoundingRectangle();
      // renderer.rect(r.getX(), r.getY(), r.getWidth(), r.getHeight());
    }

    if (polygonalNavGraph != null) {
      renderer.setColor(WALKZONE_COLOR);
      renderer.polygon(polygonalNavGraph.getWalkZone().getTransformedVertices());

      // DRAW LINEs OF SIGHT
      renderer.setColor(Color.WHITE);
      ArrayList<NavNodePolygonal> nodes = polygonalNavGraph.getGraphNodes();
      for (NavNodePolygonal n : nodes) {
        for (NavNode n2 : n.neighbors) {
          renderer.line(n.x, n.y, ((NavNodePolygonal) n2).x, ((NavNodePolygonal) n2).y);
        }
      }
    }

    renderer.end();
  }
Exemple #3
0
 public static void drawPolygon(ShapeRenderer sr, float[] polygon, float lineWidth) {
   ShapeRenderer.ShapeType type = sr.getCurrentType();
   sr.end();
   if (lineWidth == 0f) {
     sr.begin(ShapeRenderer.ShapeType.Line);
     sr.polygon(polygon);
   } else {
     sr.begin(ShapeRenderer.ShapeType.Filled);
     for (int i = 0; i < polygon.length / 2; i++) {
       sr.rectLine(
           polygon[i * 2],
           polygon[i * 2 + 1],
           polygon[(i * 2 + 2) % polygon.length],
           polygon[(i * 2 + 3) % polygon.length],
           lineWidth);
     }
   }
   sr.end();
   sr.begin(type);
 }
Exemple #4
0
    @Override
    public void renderAffine2(ShapeRenderer renderer, Transform transform) {
      tmp.set(renderer.getColor());
      renderer.setColor(color);
      affine2.set(transform.affine2);

      float x = ox + (centre ? -width / 2f : 0);
      float y = oy + (centre ? -height / 2f : 0);
      affine2.translate(x, y);

      Affine2Utils.rectangle(width, height, affine2, rect);
      if (renderer.getCurrentType() == ShapeRenderer.ShapeType.Filled) {
        // cant do polygon :/
        renderer.triangle(rect[X1], rect[Y1], rect[X2], rect[Y2], rect[X3], rect[Y3]);
        renderer.triangle(rect[X1], rect[Y1], rect[X3], rect[Y3], rect[X4], rect[Y4]);
      } else {
        renderer.polygon(rect);
      }
      renderer.setColor(tmp);
    }
 private void draw(SpriteBatch sb, ShapeRenderer sr, float scale, ShapeType type) {
   if (meshShader == null) createShader();
   float drawx = (float) getDrawX();
   float drawy = (float) getDrawY();
   float[] v = {
     drawx - scale / 3f,
     drawy + scale,
     drawx - scale / 2f,
     drawy + scale / 2f,
     drawx - scale,
     drawy - scale / 2f,
     drawx + scale,
     drawy - scale / 2f,
     drawx + scale / 2f,
     drawy + scale / 2f,
     drawx + scale / 3f,
     drawy + scale,
     drawx + scale / 6f,
     drawy + scale * 1.25f,
     drawx + scale / 6f,
     drawy + scale * 2.25f,
     drawx - scale / 6f,
     drawy + scale * 2.25f,
     drawx - scale / 6f,
     drawy + scale * 1.25f,
   };
   if (h == null) h = new MeshHelper();
   if (type == ShapeType.Line) {
     sr.begin(type);
     sr.polygon(v);
     sr.end();
   } else {
     for (int i = 0; i < v.length; i++) {
       if (i % 2 == 0) v[i] = v[i] * 2 / Gdx.graphics.getWidth() - 1f;
       else v[i] = v[i] * 2 / Gdx.graphics.getHeight() - 1f;
     }
     h.createMesh(v);
     h.drawMesh();
   }
 }
Exemple #6
0
 /** @see #polygon(float[], int, int) */
 public void polygon(float[] vertices) {
   polygon(vertices, 0, vertices.length);
 }