Browse Source

Helper method for path creation

hull7
MagicBot 12 months ago
parent
commit
aad37055d0
  1. 35
      src/engine/gameManager/BuildingManager.java

35
src/engine/gameManager/BuildingManager.java

@ -1024,4 +1024,39 @@ public enum BuildingManager { @@ -1024,4 +1024,39 @@ public enum BuildingManager {
building.parentZone.navNodes.add(new PathingUtilities.Node(new Vector2f(region.center.x, region.center.z), region, building));
}
}
public static Path2D.Float hullToPath2d(String[] hullString) {
ArrayList<Vector2f> vertices = new ArrayList<>();
ArrayList<Float> floats = new ArrayList<>();
Path2D.Float outPath = new Path2D.Float();
// Build Arraylist of vertices
for (String floatString : hullString) {
floats.add(Float.parseFloat(floatString));
if (floats.size() == 2) {
vertices.add(new Vector2f(floats.get(0), floats.get(1)));
floats.clear();
}
}
// Build Path from vertices
outPath.moveTo(vertices.get(0).x, vertices.get(0).y);
for (Vector2f vertex : vertices) {
if (outPath.getCurrentPoint() == null)
outPath.moveTo(vertex.x, vertex.y);
else
outPath.lineTo(vertex.x, vertex.y);
outPath.closePath();
}
return outPath;
}
}

Loading…
Cancel
Save