From 59025c25852f474d49a0b4751980a75d6cd3793d Mon Sep 17 00:00:00 2001 From: FatBoy-DOTC Date: Wed, 3 Jan 2024 19:55:12 -0600 Subject: [PATCH] collision handler --- src/engine/gameManager/BuildingManager.java | 107 ++++++++++---------- 1 file changed, 56 insertions(+), 51 deletions(-) diff --git a/src/engine/gameManager/BuildingManager.java b/src/engine/gameManager/BuildingManager.java index 51674173..98ae060c 100644 --- a/src/engine/gameManager/BuildingManager.java +++ b/src/engine/gameManager/BuildingManager.java @@ -978,63 +978,68 @@ public enum BuildingManager { public static void BakeBuildingMeshes(Building building){ - if(building == null) - return; + try { + if (building == null) + return; - building.buildingMeshes = new ArrayList<>(); - float rotation = building.getRot().getRotation(); - Vector3f buildingLoc = new Vector3f(building.loc.x,building.loc.y,building.loc.z); - if(!prop_meshes.containsKey(building.getBlueprint().getMeshForRank(building.getRank()))) - return; //no data for this prop ID - ArrayList meshes = prop_meshes.get(building.getBlueprint().getMeshForRank(building.getRank())); - for(int mesh : meshes){ - - if(!mesh_heights.containsKey(mesh) || !mesh_triangle_points.containsKey(mesh)) - return; //no data for this mesh - - Mesh generatedMesh = new Mesh(); - generatedMesh.meshHeight = mesh_heights.get(mesh); - ArrayList> triPoints = mesh_triangle_points.get(mesh); - - if(mesh_bounding_boxes.containsKey(mesh)){ - Rectangle2D boundingBox = mesh_bounding_boxes.get(mesh); - generatedMesh.BoundingLines = new ArrayList<>(); - float maxX = building.loc.x + (float)boundingBox.getMaxX(); - float minX = building.loc.x + (float)boundingBox.getMinX(); - float maxY = building.loc.z + (float)boundingBox.getMaxY(); - float minY = building.loc.z + (float)boundingBox.getMinY(); - - Point2D.Float p1 = new Point2D.Float(minX,maxY); - Point2D.Float p2 = new Point2D.Float(maxX,maxY); - Point2D.Float p3 = new Point2D.Float(maxX,minY); - Point2D.Float p4 = new Point2D.Float(minX,minY); - generatedMesh.BoundingLines.add(new Line2D.Float(p1,p2)); - generatedMesh.BoundingLines.add(new Line2D.Float(p2,p3)); - generatedMesh.BoundingLines.add(new Line2D.Float(p3,p4)); - generatedMesh.BoundingLines.add(new Line2D.Float(p4,p1)); - } + building.buildingMeshes = new ArrayList<>(); + float rotation = building.getRot().getRotation(); + Vector3f buildingLoc = new Vector3f(building.loc.x, building.loc.y, building.loc.z); + if (!prop_meshes.containsKey(building.getBlueprint().getMeshForRank(building.getRank()))) + return; //no data for this prop ID + ArrayList meshes = prop_meshes.get(building.getBlueprint().getMeshForRank(building.getRank())); + for (int mesh : meshes) { + + if (!mesh_heights.containsKey(mesh) || !mesh_triangle_points.containsKey(mesh)) + return; //no data for this mesh + + Mesh generatedMesh = new Mesh(); + generatedMesh.meshHeight = mesh_heights.get(mesh); + ArrayList> triPoints = mesh_triangle_points.get(mesh); + + if (mesh_bounding_boxes.containsKey(mesh)) { + Rectangle2D boundingBox = mesh_bounding_boxes.get(mesh); + generatedMesh.BoundingLines = new ArrayList<>(); + float maxX = building.loc.x + (float) boundingBox.getMaxX(); + float minX = building.loc.x + (float) boundingBox.getMinX(); + float maxY = building.loc.z + (float) boundingBox.getMaxY(); + float minY = building.loc.z + (float) boundingBox.getMinY(); + + Point2D.Float p1 = new Point2D.Float(minX, maxY); + Point2D.Float p2 = new Point2D.Float(maxX, maxY); + Point2D.Float p3 = new Point2D.Float(maxX, minY); + Point2D.Float p4 = new Point2D.Float(minX, minY); + generatedMesh.BoundingLines.add(new Line2D.Float(p1, p2)); + generatedMesh.BoundingLines.add(new Line2D.Float(p2, p3)); + generatedMesh.BoundingLines.add(new Line2D.Float(p3, p4)); + generatedMesh.BoundingLines.add(new Line2D.Float(p4, p1)); + } - for(ArrayList pointList : triPoints){ + for (ArrayList pointList : triPoints) { - ArrayList rotatedPoints = new ArrayList<>(); - for(Vector3f point : pointList) - rotatedPoints.add(Vector3f.rotateAroundPoint(buildingLoc,point,rotation)); + ArrayList rotatedPoints = new ArrayList<>(); + for (Vector3f point : pointList) + rotatedPoints.add(Vector3f.rotateAroundPoint(buildingLoc, point, rotation)); - Point2D.Float p1 = new Point2D.Float(rotatedPoints.get(0).x,rotatedPoints.get(0).z); - Point2D.Float p2 = new Point2D.Float(rotatedPoints.get(1).x,rotatedPoints.get(1).z); - Point2D.Float p3 = new Point2D.Float(rotatedPoints.get(2).x,rotatedPoints.get(2).z); + Point2D.Float p1 = new Point2D.Float(rotatedPoints.get(0).x, rotatedPoints.get(0).z); + Point2D.Float p2 = new Point2D.Float(rotatedPoints.get(1).x, rotatedPoints.get(1).z); + Point2D.Float p3 = new Point2D.Float(rotatedPoints.get(2).x, rotatedPoints.get(2).z); - Triangle tri = new Triangle(); - tri.sides = new ArrayList<>(); - tri.sides.add(new Line2D.Float(p1,p2)); - tri.sides.add(new Line2D.Float(p2,p3)); - tri.sides.add(new Line2D.Float(p3,p1)); - generatedMesh.triangles.add(tri); - } - if(BuildingManager.mesh_bounding_boxes.containsKey(mesh)){ - generatedMesh.boundsRect = BuildingManager.mesh_bounding_boxes.get(mesh); + Triangle tri = new Triangle(); + tri.sides = new ArrayList<>(); + tri.sides.add(new Line2D.Float(p1, p2)); + tri.sides.add(new Line2D.Float(p2, p3)); + tri.sides.add(new Line2D.Float(p3, p1)); + generatedMesh.triangles.add(tri); + } + if (BuildingManager.mesh_bounding_boxes.containsKey(mesh)) { + generatedMesh.boundsRect = BuildingManager.mesh_bounding_boxes.get(mesh); + } + building.buildingMeshes.add(generatedMesh); } - building.buildingMeshes.add(generatedMesh); + } + catch(Exception e){ + Logger.info("Failed TO Bake Building Mesh Data: " + e.getMessage()); } }