Java Code Examples for com.badlogic.gdx.graphics.glutils.ShapeRenderer#line()

The following examples show how to use com.badlogic.gdx.graphics.glutils.ShapeRenderer#line() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Animation.java    From riiablo with Apache License 2.0 6 votes vote down vote up
protected void drawDebug(ShapeRenderer shapeRenderer, int d, int f, float x, float y) {
  boolean reset = !shapeRenderer.isDrawing();
  if (reset) {
    shapeRenderer.begin(ShapeRenderer.ShapeType.Line);
  } else {
    shapeRenderer.set(ShapeRenderer.ShapeType.Line);
  }

  shapeRenderer.setColor(Color.RED);
  shapeRenderer.line(x, y, x + 40, y);
  shapeRenderer.setColor(Color.GREEN);
  shapeRenderer.line(x, y, x, y + 20);
  shapeRenderer.setColor(Color.BLUE);
  shapeRenderer.line(x, y, x + 20, y - 10);

  BBox box = dc.getBox(d, f);
  shapeRenderer.setColor(DEBUG_COLOR);
  shapeRenderer.rect(x + box.xMin, y - box.yMax, box.width, box.height);
  if (reset) shapeRenderer.end();
}
 
Example 2
Source File: DirectionActor.java    From riiablo with Apache License 2.0 5 votes vote down vote up
@Override
public void drawDebug(ShapeRenderer shapes) {
  //super.drawDebug(shapes);
  if (!isVisible()) return;

  float cx = getX() + r;
  float cy = getY() + r;

  shapes.setColor(Color.WHITE);
  shapes.set(ShapeRenderer.ShapeType.Filled);
  shapes.circle(cx, cy, r, 64);
  shapes.set(ShapeRenderer.ShapeType.Line);

  float snap = Direction.snapToDirection(angle, dirs);
  float dx = r * MathUtils.cos(snap);
  float dy = r * MathUtils.sin(snap);

  shapes.setColor(Color.BLUE);
  shapes.line(cx, cy, cx + dx, cy + dy);

  if (DEBUG_ANGLE) {
    dx = r * MathUtils.cos(angle);
    dy = r * MathUtils.sin(angle);

    shapes.setColor(Color.BLACK);
    shapes.line(cx, cy, cx + dx, cy + dy);
  }
}
 
Example 3
Source File: DirectionTool.java    From riiablo with Apache License 2.0 5 votes vote down vote up
static void drawDiamond(ShapeRenderer shapes, float x, float y, int width, int height) {
  int hw = width >>> 1;
  int hh = height >>> 1;
  shapes.line(x, y + hh, x + hw, y + height);
  shapes.line(x + hw, y + height, x + width, y + hh);
  shapes.line(x + width, y + hh, x + hw, y);
  shapes.line(x + hw, y, x, y + hh);
}
 
Example 4
Source File: FontMetricsTool.java    From riiablo with Apache License 2.0 5 votes vote down vote up
public void drawDebug(BitmapFont font, GlyphLayout layout, int y) {
  ShapeRenderer shapes = Riiablo.shapes;
  for (GlyphLayout.GlyphRun run : layout.runs) {
    shapes.setColor(Color.GREEN);
    shapes.line(run.x, y + run.y, run.x + run.width, y + run.y);
    shapes.setColor(Color.RED);
    shapes.line(
        run.x, y + run.y - font.getLineHeight(),
        run.x + run.width, y + run.y - font.getLineHeight());
  }
}
 
Example 5
Source File: DirectionTool.java    From riiablo with Apache License 2.0 5 votes vote down vote up
static void drawDiamond(ShapeRenderer shapes, float x, float y, int width, int height) {
  int hw = width >>> 1;
  int hh = height >>> 1;
  shapes.line(x, y + hh, x + hw, y + height);
  shapes.line(x + hw, y + height, x + width, y + hh);
  shapes.line(x + width, y + hh, x + hw, y);
  shapes.line(x + hw, y, x, y + hh);
}
 
Example 6
Source File: SystemProfilerGUI.java    From riiablo with Apache License 2.0 5 votes vote down vote up
private void drawGraphAxis(ShapeRenderer renderer, float x, float y, float width, float height, float alpha) {
  float sep = height / 7;
  y += sep / 2;
  renderer.setColor(GRAPH_V_LINE.r, GRAPH_V_LINE.g, GRAPH_V_LINE.b, alpha);
  renderer.line(x, y, x, y + height - sep);
  renderer.line(x + width, y, x + width, y + height - sep);

  renderer.setColor(GRAPH_H_LINE.r, GRAPH_H_LINE.g, GRAPH_H_LINE.b, alpha);
  for (int i = 0; i < 7; i++) {
    renderer.line(x, y + i * sep, x + width, y + i * sep);
  }
}
 
Example 7
Source File: Animation.java    From riiablo with Apache License 2.0 5 votes vote down vote up
public void drawDebug(ShapeRenderer shapes, float x, float y) {
  if (DEBUG_MODE == 0) {
    return;
  } else if (DEBUG_MODE == 1 || cof == null) {
    boolean reset = !shapes.isDrawing();
    if (reset) {
      shapes.begin(ShapeRenderer.ShapeType.Line);
    } else {
      shapes.set(ShapeRenderer.ShapeType.Line);
    }

    shapes.setColor(Color.RED);
    shapes.line(x, y, x + 50, y);
    shapes.setColor(Color.GREEN);
    shapes.line(x, y, x, y + 50);
    shapes.setColor(Color.BLUE);
    shapes.line(x, y, x + 15, y - 20);
    shapes.setColor(Color.GREEN);
    shapes.rect(x + box.xMin, y - box.yMax, box.width, box.height);
    if (reset) shapes.end();
  } else if (DEBUG_MODE == 2 && frame < numFrames) {
    int d = DC.Direction.toReadDir(direction, cof.getNumDirections());
    int f = frame;
    for (int l = 0; l < cof.getNumLayers(); l++) {
      int component = cof.getLayerOrder(d, f, l);
      Layer layer = layers[component];
      if (layer != null) layer.drawDebug(shapes, d, f, x, y);
    }
  }
}
 
Example 8
Source File: DebugUtils.java    From riiablo with Apache License 2.0 5 votes vote down vote up
public static void drawDiamond2(ShapeRenderer shapes, float x, float y, int width, int height) {
  int hw = width  >>> 1;
  int hh = height >>> 1;
  if (shapes.getCurrentType() == ShapeRenderer.ShapeType.Filled) {
    shapes.triangle(x, y + hh, x + hw, y + height, x + width, y + hh);
    shapes.triangle(x, y + hh, x + hw, y         , x + width, y + hh);
  } else {
    shapes.line(x        , y + hh    , x + hw   , y + height);
    shapes.line(x + hw   , y + height, x + width, y + hh    );
    shapes.line(x + width, y + hh    , x + hw   , y         );
    shapes.line(x + hw   , y         , x        , y + hh    );
  }
}
 
Example 9
Source File: Box2dJumpTest.java    From gdx-ai with Apache License 2.0 5 votes vote down vote up
private void drawPad(ShapeRenderer shapeRenderer, Vector2 centerPoint, float tolerance) {
	int centerX = Box2dSteeringTest.metersToPixels(centerPoint.x);
	int centerY = Box2dSteeringTest.metersToPixels(centerPoint.y);
	tolerance = Box2dSteeringTest.metersToPixels(tolerance);
	shapeRenderer.line(centerX-tolerance, centerY, centerX+tolerance, centerY);
	shapeRenderer.line(centerX, centerY+3, centerX, centerY-3);
}
 
Example 10
Source File: Entity.java    From riiablo with Apache License 2.0 4 votes vote down vote up
public void drawDebugStatus(PaletteIndexedBatch batch, ShapeRenderer shapes) {
  float x = screen.x;
  float y = screen.y;
  if (animation != null && isSelectable()) animation.drawDebug(shapes, x, y);

  shapes.setColor(Color.WHITE);
  DebugUtils.drawDiamond(shapes, x, y, Tile.SUBTILE_WIDTH, Tile.SUBTILE_HEIGHT);
  //shapes.ellipse(x - Tile.SUBTILE_WIDTH50, y - Tile.SUBTILE_HEIGHT50, Tile.SUBTILE_WIDTH, Tile.SUBTILE_HEIGHT);

  final float R = 32;
  shapes.setColor(Color.RED);
  shapes.line(x, y, x + MathUtils.cos(angle) * R, y + MathUtils.sin(angle) * R);

  if (animation != null) {
    int numDirs = animation.getNumDirections();
    float rounded = Direction.snapToDirection(angle, numDirs);
    shapes.setColor(Color.GREEN);
    shapes.line(x, y, x + MathUtils.cos(rounded) * R * 0.5f, y + MathUtils.sin(rounded) * R * 0.5f);
  }

  shapes.end();
  batch.begin();
  batch.setShader(null);
  StringBuilder builder = new StringBuilder(64)
      .append(classname).append('\n')
      .append(token).append(' ').append(type.MODE[mode]).append(' ').append(WCLASS[wclass]).append('\n');
  if (animation != null) {
    builder
        .append(StringUtils.leftPad(Integer.toString(animation.getFrame()), 2))
        .append('/')
        .append(StringUtils.leftPad(Integer.toString(animation.getNumFramesPerDir() - 1), 2))
        .append(' ')
        .append(animation.getFrameDelta())
        .append('\n');
  }
  appendToStatus(builder);
  GlyphLayout layout = Riiablo.fonts.consolas12.draw(batch, builder.toString(), x, y - Tile.SUBTILE_HEIGHT50, 0, Align.center, false);
  Pools.free(layout);
  batch.end();
  batch.setShader(Riiablo.shader);
  shapes.begin(ShapeRenderer.ShapeType.Line);
}
 
Example 11
Source File: RenderSystem.java    From riiablo with Apache License 2.0 4 votes vote down vote up
private void drawDebugSpecial(ShapeRenderer shapes) {
  for (int i = Map.WALL_OFFSET, x, y; i < Map.WALL_OFFSET + Map.MAX_WALLS; i++) {
    int startX2 = startX;
    int startY2 = startY;
    float startPx2 = startPx;
    float startPy2 = startPy;
    for (y = 0; y < viewBuffer.length; y++) {
      int tx = startX2;
      int ty = startY2;
      int stx = tx * Tile.SUBTILE_SIZE;
      int sty = ty * Tile.SUBTILE_SIZE;
      float px = startPx2;
      float py = startPy2;
      int size = viewBuffer[y];
      for (x = 0; x < size; x++) {
        Map.Zone zone = map.getZone(stx, sty);
        if (zone != null) {
          DS1.Cell cell = zone.getCell(i, tx, ty);
          if (cell != null) {
            if (Map.ID.POPPADS.contains(cell.id)) {
              shapes.setColor(Map.ID.getColor(cell));
              Map.Preset preset = zone.getGrid(tx, ty);
              Map.Preset.PopPad popPad = preset.popPads.get(cell.id);
              if (popPad.startX == zone.getGridX(tx) && popPad.startY == zone.getGridY(ty)) {
                int width  = popPad.endX - popPad.startX;
                int height = popPad.endY - popPad.startY;
                iso.getPixOffset(tmpVec2);
                float offsetX = tmpVec2.x;
                float offsetY = tmpVec2.y;
                iso.toScreen(tmpVec2.set(stx, sty));
                float topLeftX = tmpVec2.x - offsetX;
                float topLeftY = tmpVec2.y - offsetY;
                iso.toScreen(tmpVec2.set(stx, sty).add(width, 0));
                float topRightX = tmpVec2.x - offsetX;
                float topRightY = tmpVec2.y - offsetY;
                iso.toScreen(tmpVec2.set(stx, sty).add(0, height));
                float bottomLeftX = tmpVec2.x - offsetX;
                float bottomLeftY = tmpVec2.y - offsetY;
                iso.toScreen(tmpVec2.set(stx, sty).add(width, height));
                float bottomRightX = tmpVec2.x - offsetX;
                float bottomRightY = tmpVec2.y - offsetY;
                shapes.line(topLeftX, topLeftY, topRightX, topRightY);
                shapes.line(topRightX, topRightY, bottomRightX, bottomRightY);
                shapes.line(bottomRightX, bottomRightY, bottomLeftX, bottomLeftY);
                shapes.line(bottomLeftX, bottomLeftY, topLeftX, topLeftY);
              }
            } else {
              shapes.setColor(Color.WHITE);
              DebugUtils.drawDiamond2(shapes, px, py, Tile.WIDTH, Tile.HEIGHT);
            }
            shapes.end();

            batch.begin();
            batch.setShader(null);
            BitmapFont font = Riiablo.fonts.consolas12;
            String str = String.format("%s%n%08x", Map.ID.getName(cell.id), cell.value);
            GlyphLayout layout = new GlyphLayout(font, str, 0, str.length(), font.getColor(), 0, Align.center, false, null);
            font.draw(batch, layout,
                px + Tile.WIDTH50,
                py + Tile.HEIGHT50 + font.getLineHeight() / 4);
            batch.end();
            batch.setShader(Riiablo.shader);

            shapes.begin(ShapeRenderer.ShapeType.Line);
          }
        }

        tx++;
        stx += Tile.SUBTILE_SIZE;
        px += Tile.WIDTH50;
        py -= Tile.HEIGHT50;
      }

      startY2++;
      if (y >= tilesX - 1) {
        startX2++;
        startPy2 -= Tile.HEIGHT;
      } else {
        startX2--;
        startPx2 -= Tile.WIDTH;
      }
    }
  }
}
 
Example 12
Source File: Scene.java    From bladecoder-adventure-engine with Apache License 2.0 4 votes vote down vote up
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);
			renderer.polygon(p.getTransformedVertices());
		} else if (a instanceof AnchorActor) {
			renderer.setColor(Scene.ANCHOR_COLOR);
			renderer.line(p.getX() - Scene.ANCHOR_RADIUS, p.getY(), p.getX() + Scene.ANCHOR_RADIUS, p.getY());
			renderer.line(p.getX(), p.getY() - Scene.ANCHOR_RADIUS, p.getX(), p.getY() + Scene.ANCHOR_RADIUS);
		} 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 (walkZone != 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 (NavNodePolygonal n2 : n.neighbors) {
				renderer.line(n.x, n.y, n2.x, n2.y);
			}
		}
	}

	renderer.end();
}