Browse Source

load mesh data and structure meshes

server-collision
FatBoy-DOTC 10 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 { @@ -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;
}

23
src/engine/CollisionEngine/Mesh.java

@ -31,7 +31,6 @@ public class Mesh { @@ -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 { @@ -78,21 +77,11 @@ public class Mesh {
}
}
public void BakeBoundsRect(){
ArrayList<Rectangle2D> 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;
}
}

Loading…
Cancel
Save