From 6fe4f32302c76c32d19131c8822403fc3fe1da96 Mon Sep 17 00:00:00 2001 From: FatBoy-DOTC Date: Thu, 18 Jan 2024 19:50:49 -0600 Subject: [PATCH] load mesh data and structure meshes --- .../CollisionEngine/CollisionManager.java | 3 +++ src/engine/CollisionEngine/Mesh.java | 23 +++++-------------- 2 files changed, 9 insertions(+), 17 deletions(-) diff --git a/src/engine/CollisionEngine/CollisionManager.java b/src/engine/CollisionEngine/CollisionManager.java index cb870c12..863b60e4 100644 --- a/src/engine/CollisionEngine/CollisionManager.java +++ b/src/engine/CollisionEngine/CollisionManager.java @@ -18,6 +18,9 @@ public class CollisionManager { if(!travelLine.intersects(building.buildingRect) && !building.buildingRect.contains(travelLine.getP1()) && !building.buildingRect.contains(travelLine.getP2())) return false; + for(Mesh mesh : building.buildingMeshes) + if(mesh.collides(travelLine)) + return true; return false; } diff --git a/src/engine/CollisionEngine/Mesh.java b/src/engine/CollisionEngine/Mesh.java index ee869a07..855ad7bd 100644 --- a/src/engine/CollisionEngine/Mesh.java +++ b/src/engine/CollisionEngine/Mesh.java @@ -31,7 +31,6 @@ public class Mesh { public void update(){ this.BakeTriangles(); - this.BakeBoundsRect(); } public Vector3f getLocation(){ Building parentBuilding = BuildingManager.getBuilding(this.parentUUID); @@ -78,21 +77,11 @@ public class Mesh { } } - public void BakeBoundsRect(){ - ArrayList rects = new ArrayList<>(); - for(Triangle tri : this.triangles){ - Path2D.Float path = new Path2D.Float(); - path.lineTo(tri.point1.x,tri.point1.y); - path.lineTo(tri.point2.x,tri.point2.y); - path.lineTo(tri.point3.x,tri.point3.y); - path.closePath(); - rects.add(path.getBounds()); - } - Rectangle2D.Float boundsRect = new Rectangle2D.Float(); - boundsRect.setRect(rects.get(0)); - for(Rectangle2D rectangle : rects){ - boundsRect.add(rectangle); - } - this.mesh_bounds = (Rectangle2D.Float)boundsRect.clone(); + public Boolean collides(Line2D line){ + for(Triangle tri : this.triangles) + if(tri.collides(line)) + return true; + + return false; } }