Helper method for path creation
This commit is contained in:
@@ -1024,4 +1024,39 @@ public enum BuildingManager {
|
|||||||
building.parentZone.navNodes.add(new PathingUtilities.Node(new Vector2f(region.center.x, region.center.z), region, building));
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user