Browse Source

load mesh data and structure meshes

server-collision
FatBoy-DOTC 10 months ago
parent
commit
cf09f447bd
  1. 38
      src/engine/CollisionEngine/Mesh.java
  2. 17
      src/engine/gameManager/BuildingManager.java

38
src/engine/CollisionEngine/Mesh.java

@ -1,5 +1,7 @@ @@ -1,5 +1,7 @@
package engine.CollisionEngine;
import engine.gameManager.BuildingManager;
import engine.math.Vector2f;
import engine.math.Vector3f;
import engine.math.Vector3fImmutable;
import engine.objects.Building;
@ -23,10 +25,8 @@ public class Mesh { @@ -23,10 +25,8 @@ public class Mesh {
public int parent_prop_id;
public int parent_structure_id;
public int parentUUID;
public float rectWidth;
public float rectHeight;
public Rectangle2D.Float mesh_bounds;
public MeshData meshData;
public void AdoptTriangles(float rotation){
if(CollisionManager.mesh_triangles.containsKey(this.mesh_id) == false){
@ -34,14 +34,18 @@ public class Mesh { @@ -34,14 +34,18 @@ public class Mesh {
return;
}
Vector3fImmutable parentLoc = BuildingManager.getBuilding(this.parentUUID).loc;
Vector3f offsetLoc = new Vector3f(parentLoc.x,parentLoc.y,parentLoc.z).add(this.meshData.loc);
this.triangles = new ArrayList<>();
int degrees = (int)Math.toDegrees(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,degrees);
Vector3f rotatedPoint2 = Vector3f.rotateAroundPoint(new Vector3f(tri.point2.x,mesh_location.y,tri.point2.y),mesh_location,degrees);
Vector3f rotatedPoint3 = Vector3f.rotateAroundPoint(new Vector3f(tri.point3.x,mesh_location.y,tri.point3.y),mesh_location,degrees);
Vector3f rotatedPoint1 = Vector3f.rotateAroundPoint(offsetLoc.add(new Vector3f(tri.point1.x,mesh_location.y,tri.point1.y)),offsetLoc,degrees);
Vector3f rotatedPoint2 = Vector3f.rotateAroundPoint(offsetLoc.add(new Vector3f(tri.point2.x,mesh_location.y,tri.point2.y)),offsetLoc,degrees);
Vector3f rotatedPoint3 = Vector3f.rotateAroundPoint(offsetLoc.add(new Vector3f(tri.point3.x,mesh_location.y,tri.point3.y)),offsetLoc,degrees);
newTri.point1 = new Point2D.Float(rotatedPoint1.x,rotatedPoint1.z);
newTri.point2 = new Point2D.Float(rotatedPoint2.x,rotatedPoint2.z);
@ -58,7 +62,27 @@ public class Mesh { @@ -58,7 +62,27 @@ public class Mesh {
public void MakeBounds(){
float minX = 0;
float minZ = 0;
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;
}
this.mesh_bounds = new Rectangle2D.Float();
this.mesh_bounds.setRect(this.mesh_ref_point.x,this.mesh_ref_point.z,this.rectWidth, this.rectHeight);
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);
}
}

17
src/engine/gameManager/BuildingManager.java

@ -996,12 +996,19 @@ public enum BuildingManager { @@ -996,12 +996,19 @@ public enum BuildingManager {
int degrees = (int)Math.toDegrees(building.getBounds().getQuaternion().angleY);
Mesh generatedMesh = new Mesh();
generatedMesh.meshData = meshData;
Vector3f buildingLoc = new Vector3f(building.loc.x,building.loc.y,building.loc.z);
generatedMesh.mesh_location = Vector3f.rotateAroundPoint(buildingLoc.add(meshData.loc),buildingLoc,degrees);
generatedMesh.mesh_end_point = Vector3f.rotateAroundPoint(generatedMesh.mesh_location.add(meshData.endPoint),buildingLoc,degrees);
generatedMesh.mesh_ref_point = Vector3f.rotateAroundPoint(generatedMesh.mesh_location.add(meshData.refPoint),buildingLoc,degrees);
generatedMesh.rectWidth = meshData.refPoint.x * 2;
generatedMesh.rectHeight = meshData.refPoint.z * 2;
Vector3f offset_mesh_loc = buildingLoc.add(meshData.loc);
Vector3f offset_mesh_end = buildingLoc.add(meshData.endPoint);
Vector3f offset_mesh_ref = buildingLoc.add(meshData.refPoint);
generatedMesh.mesh_location = Vector3f.rotateAroundPoint(offset_mesh_loc,buildingLoc,degrees);
generatedMesh.mesh_end_point = Vector3f.rotateAroundPoint(offset_mesh_end,buildingLoc,degrees);
generatedMesh.mesh_ref_point = Vector3f.rotateAroundPoint(offset_mesh_ref,buildingLoc,degrees);
generatedMesh.mesh_max_y = building.loc.y + meshData.maxY;
generatedMesh.mesh_min_y = building.loc.y + meshData.minY;
generatedMesh.mesh_scale = meshData.scale;

Loading…
Cancel
Save