Browse Source

load mesh data and structure meshes

server-collision
FatBoy-DOTC 11 months ago
parent
commit
6fe4f32302
  1. 3
      src/engine/CollisionEngine/CollisionManager.java
  2. 23
      src/engine/CollisionEngine/Mesh.java

3
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())) if(!travelLine.intersects(building.buildingRect) && !building.buildingRect.contains(travelLine.getP1()) && !building.buildingRect.contains(travelLine.getP2()))
return false; return false;
for(Mesh mesh : building.buildingMeshes)
if(mesh.collides(travelLine))
return true;
return false; return false;
} }

23
src/engine/CollisionEngine/Mesh.java

@ -31,7 +31,6 @@ public class Mesh {
public void update(){ public void update(){
this.BakeTriangles(); this.BakeTriangles();
this.BakeBoundsRect();
} }
public Vector3f getLocation(){ public Vector3f getLocation(){
Building parentBuilding = BuildingManager.getBuilding(this.parentUUID); Building parentBuilding = BuildingManager.getBuilding(this.parentUUID);
@ -78,21 +77,11 @@ public class Mesh {
} }
} }
public void BakeBoundsRect(){ public Boolean collides(Line2D line){
ArrayList<Rectangle2D> rects = new ArrayList<>(); for(Triangle tri : this.triangles)
for(Triangle tri : this.triangles){ if(tri.collides(line))
Path2D.Float path = new Path2D.Float(); return true;
path.lineTo(tri.point1.x,tri.point1.y);
path.lineTo(tri.point2.x,tri.point2.y); return false;
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();
} }
} }

Loading…
Cancel
Save