Browse Source

load mesh data and structure meshes

server-collision
FatBoy-DOTC 10 months ago
parent
commit
76a71b5984
  1. 34
      src/engine/CollisionEngine/Mesh.java

34
src/engine/CollisionEngine/Mesh.java

@ -9,6 +9,7 @@ import org.pmw.tinylog.Logger; @@ -9,6 +9,7 @@ import org.pmw.tinylog.Logger;
import java.awt.geom.Line2D;
import java.awt.geom.Path2D;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
import java.util.ArrayList;
@ -62,27 +63,24 @@ public class Mesh { @@ -62,27 +63,24 @@ public class Mesh {
public void MakeBounds(){
float minX = 0;
float minZ = 0;
ArrayList<Rectangle2D> rects = new ArrayList<>();
for(Triangle tri : this.triangles){
if(tri.point1.x < minX)
minX = tri.point1.x;
if(tri.point2.x < minX)
minX = tri.point1.x;
if(tri.point3.x < minX)
minX = tri.point1.x;
if(tri.point1.y < minZ)
minZ = tri.point1.x;
if(tri.point2.y < minZ)
minZ = tri.point1.x;
if(tri.point3.y < minZ)
minZ = tri.point1.x;
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 = new Rectangle2D.Float();
float width = (this.mesh_location.x) - minX * 2;
float height = Math.abs((this.mesh_location.z) + minZ) * 2;
this.mesh_bounds.setRect(minX,minZ,width, height);
float width = (float)boundsRect.getWidth();
float height = (float)boundsRect.getHeight();
this.mesh_bounds.setRect(boundsRect);
}
}

Loading…
Cancel
Save