package engine.CollisionEngine; import engine.math.Vector3f; import engine.math.Vector3fImmutable; import engine.objects.Building; import org.pmw.tinylog.Logger; import java.awt.geom.Line2D; import java.awt.geom.Point2D; import java.awt.geom.Rectangle2D; import java.util.ArrayList; public class Mesh { public ArrayList triangles; public Vector3f mesh_end_point; public Vector3f mesh_ref_point; public Vector3f mesh_location; public float mesh_max_y; public float mesh_min_y; public Vector3f mesh_scale; public int mesh_id; public int parent_prop_id; public int parent_structure_id; public int parentUUID; public Rectangle2D.Float mesh_bounds; public void AdoptTriangles(float rotation){ if(CollisionManager.mesh_triangles.containsKey(this.mesh_id) == false){ Logger.error("Failed To Bake Triangles For Mesh: " + this.mesh_id); return; } this.triangles = new ArrayList<>(); double radian = (double)rotation; for(Triangle tri : CollisionManager.mesh_triangles.get(this.mesh_id)){ Triangle newTri = new Triangle(); Vector3f rotatedPoint1 = Vector3f.rotateAroundPoint(new Vector3f(tri.point1.x,mesh_location.y,tri.point1.y),mesh_location,radian); Vector3f rotatedPoint2 = Vector3f.rotateAroundPoint(new Vector3f(tri.point2.x,mesh_location.y,tri.point2.y),mesh_location,radian); Vector3f rotatedPoint3 = Vector3f.rotateAroundPoint(new Vector3f(tri.point3.x,mesh_location.y,tri.point3.y),mesh_location,radian); newTri.point1 = new Point2D.Float(rotatedPoint1.x,rotatedPoint1.z); newTri.point2 = new Point2D.Float(rotatedPoint2.x,rotatedPoint2.z); newTri.point3 = new Point2D.Float(rotatedPoint3.x,rotatedPoint3.z); newTri.sides = new ArrayList<>(); newTri.sides.add(new Line2D.Float(newTri.point1,newTri.point2)); newTri.sides.add(new Line2D.Float(newTri.point2,newTri.point3)); newTri.sides.add(new Line2D.Float(newTri.point3,newTri.point1)); } } public void MakeBounds(float rotation){ double radian = (double)rotation; Vector3f rotatedEnd = Vector3f.rotateAroundPoint(new Vector3f(this.mesh_end_point.x,mesh_location.y,this.mesh_end_point.z),mesh_location,radian); Vector3f rotatedRef = Vector3f.rotateAroundPoint(new Vector3f(this.mesh_ref_point.x,mesh_location.y,this.mesh_ref_point.z),mesh_location,radian); this.mesh_bounds = new Rectangle2D.Float(); this.mesh_bounds.setRect(rotatedEnd.x,rotatedEnd.z,Math.abs(rotatedEnd.x) - Math.abs(rotatedRef.x),Math.abs(rotatedEnd.z) - Math.abs(rotatedRef.z)); } }