Browse Source

Helper method for path creation

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

43
src/engine/gameManager/BuildingManager.java

@ -1014,14 +1014,49 @@ public enum BuildingManager {
cornersAndFaces.add(new Vector2f(building.loc.x,building.loc.z - Y)); cornersAndFaces.add(new Vector2f(building.loc.x,building.loc.z - Y));
cornersAndFaces.add(new Vector2f(building.loc.x,building.loc.z + Y)); cornersAndFaces.add(new Vector2f(building.loc.x,building.loc.z + Y));
for(Vector2f point : cornersAndFaces){ for(Vector2f point : cornersAndFaces){
if(!NavigationManager.pointIsBlocked(new Vector3fImmutable(point.x,building.loc.y,point.y))){ if (!NavigationManager.pointIsBlocked(new Vector3fImmutable(point.x, building.loc.y, point.y))) {
building.parentZone.navNodes.add(new PathingUtilities.Node(point,null,building)); building.parentZone.navNodes.add(new PathingUtilities.Node(point, null, building));
} }
} }
//add region centers to the zones navNodes list //add region centers to the zones navNodes list
for(Regions region : building.getBounds().getRegions()){ for (Regions region : building.getBounds().getRegions()) {
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;
} }
} }

Loading…
Cancel
Save