diff --git a/src/engine/db/handlers/dbBuildingHandler.java b/src/engine/db/handlers/dbBuildingHandler.java index fd74e63c..75698bf5 100644 --- a/src/engine/db/handlers/dbBuildingHandler.java +++ b/src/engine/db/handlers/dbBuildingHandler.java @@ -15,6 +15,7 @@ import engine.Enum.ProtectionState; import engine.Enum.TaxType; import engine.gameManager.BuildingManager; import engine.gameManager.DbManager; +import engine.math.Vector2f; import engine.math.Vector3f; import engine.math.Vector3fImmutable; import engine.objects.*; @@ -932,8 +933,13 @@ public class dbBuildingHandler extends dbHandlerBase { float endZ = Float.parseFloat(rs.getString("end").split(";")[1]); float refX = Float.parseFloat(rs.getString("ref").split(";")[0]); float refZ = Float.parseFloat(rs.getString("ref").split(";")[1]); + + + Vector2f topLeft = new Vector2f(centerX - refX,centerZ - refZ); + float width = Math.abs(endX-refX); + float height = Math.abs(endZ-refZ); Rectangle2D boundRect = new Rectangle2D.Float(); - boundRect.setRect(centerX,centerZ,Math.abs(endX-refX),Math.abs(endZ-refZ)); + boundRect.setRect(topLeft.x,topLeft.y,width,height); BuildingManager.mesh_bounding_boxes.put(rs.getInt("meshId"),boundRect); } } diff --git a/src/engine/gameManager/BuildingManager.java b/src/engine/gameManager/BuildingManager.java index d7280e44..12a0c904 100644 --- a/src/engine/gameManager/BuildingManager.java +++ b/src/engine/gameManager/BuildingManager.java @@ -998,16 +998,22 @@ public enum BuildingManager { if (mesh_bounding_boxes.containsKey(mesh)) { Rectangle2D boundingBox = mesh_bounding_boxes.get(mesh); + //Bounds buildingBounds = building.getBounds(); + float halfX = (float) boundingBox.getWidth() * 0.5f; + float halfZ = (float)boundingBox.getHeight() * 0.5f; + Vector3f bottomRight = new Vector3f(building.loc.x + halfX,building.loc.y,building.loc.z + halfZ); + Vector3f topLeft = new Vector3f(building.loc.x - halfX,building.loc.y,building.loc.z - halfZ); + Vector3f topRight = new Vector3f(building.loc.x + halfX,building.loc.y,building.loc.z - halfZ); + Vector3f bottomLeft = new Vector3f(building.loc.x - halfX,building.loc.y,building.loc.z + halfZ); + 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); - boundingBox.setRect(p1.x,p1.y,Math.abs(maxX - minX), Math.abs(maxY - minY)); + Point2D.Float p1 = new Point2D.Float(topLeft.x, topLeft.z); + Point2D.Float p2 = new Point2D.Float(topRight.x, topRight.z); + Point2D.Float p3 = new Point2D.Float(bottomRight.x, bottomRight.z); + Point2D.Float p4 = new Point2D.Float(bottomLeft.x, bottomLeft.z); + float rectWidth = topLeft.distance(topRight); + float rectHeight = topLeft.distance(bottomLeft); + boundingBox.setRect(p1.x,p1.y,rectWidth, rectHeight); generatedMesh.BoundingLines.add(new Line2D.Float(p1, p2)); generatedMesh.BoundingLines.add(new Line2D.Float(p2, p3)); generatedMesh.BoundingLines.add(new Line2D.Float(p3, p4));