|
|
|
package engine.CollisionEngine;
|
|
|
|
|
|
|
|
import engine.gameManager.BuildingManager;
|
|
|
|
import engine.math.Vector2f;
|
|
|
|
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.Path2D;
|
|
|
|
import java.awt.geom.Point2D;
|
|
|
|
import java.awt.geom.Rectangle2D;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
|
|
|
public class Mesh {
|
|
|
|
public ArrayList<Triangle> 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 MeshData meshData;
|
|
|
|
|
|
|
|
public void update(){
|
|
|
|
this.BakeTriangles();
|
|
|
|
}
|
|
|
|
public Vector3f getLocation(){
|
|
|
|
Building parentBuilding = BuildingManager.getBuilding(this.parentUUID);
|
|
|
|
int degrees = (int)Math.toDegrees(parentBuilding.getBounds().getQuaternion().angleY);
|
|
|
|
Vector3f parentLoc = new Vector3f(parentBuilding.loc.x,parentBuilding.loc.y,parentBuilding.loc.z);
|
|
|
|
Vector3f offsetLoc = parentLoc.add(this.meshData.loc);
|
|
|
|
Vector3f rotatedPoint = Vector3f.rotateAroundPoint(offsetLoc,parentLoc,degrees);
|
|
|
|
return rotatedPoint;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void BakeTriangles(){
|
|
|
|
|
|
|
|
if(CollisionManager.mesh_triangles.containsKey(this.meshData.meshID) == false){
|
|
|
|
Logger.error("Failed To Bake Triangles For Mesh: " + this.meshData.meshID);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Building parentBuilding = BuildingManager.getBuilding(this.parentUUID);
|
|
|
|
int degrees = (int)Math.toDegrees(parentBuilding.getBounds().getQuaternion().angleY);
|
|
|
|
Vector3f parentLoc = new Vector3f(parentBuilding.loc.x,parentBuilding.loc.y,parentBuilding.loc.z);
|
|
|
|
Vector3f offsetLoc = parentLoc.add(this.meshData.loc);
|
|
|
|
|
|
|
|
for(Triangle tri : CollisionManager.mesh_triangles.get(this.meshData.meshID)) {
|
|
|
|
|
|
|
|
Triangle newTri = new Triangle();
|
|
|
|
|
|
|
|
Vector3f Point1 = offsetLoc.add(new Vector3f(tri.point1.x,offsetLoc.y,tri.point1.y));
|
|
|
|
Vector3f Point2 = offsetLoc.add(new Vector3f(tri.point2.x,offsetLoc.y,tri.point2.y));
|
|
|
|
Vector3f Point3 = offsetLoc.add(new Vector3f(tri.point3.x,offsetLoc.y,tri.point3.y));
|
|
|
|
|
|
|
|
Vector3f rotatedPoint1 = Vector3f.rotateAroundPoint(Point1,offsetLoc,degrees);
|
|
|
|
Vector3f rotatedPoint2 = Vector3f.rotateAroundPoint(Point2,offsetLoc,degrees);
|
|
|
|
Vector3f rotatedPoint3 = Vector3f.rotateAroundPoint(Point3,offsetLoc,degrees);
|
|
|
|
|
|
|
|
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));
|
|
|
|
|
|
|
|
this.triangles.add(newTri);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public Boolean collides(Line2D line){
|
|
|
|
for(Triangle tri : this.triangles)
|
|
|
|
if(tri.collides(line))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|