Browse Source

collision work

server-collision
FatBoy-DOTC 10 months ago
parent
commit
c65a713bae
  1. 8
      src/engine/db/handlers/dbBuildingHandler.java
  2. 24
      src/engine/gameManager/BuildingManager.java

8
src/engine/db/handlers/dbBuildingHandler.java

@ -15,6 +15,7 @@ import engine.Enum.ProtectionState; @@ -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 { @@ -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);
}
}

24
src/engine/gameManager/BuildingManager.java

@ -998,16 +998,22 @@ public enum BuildingManager { @@ -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));

Loading…
Cancel
Save