Browse Source

Merge remote-tracking branch 'origin/feature_mesh_collision' into feature_mesh_collision

# Conflicts:
#	src/engine/db/handlers/dbBuildingHandler.java
server-collision
FatBoy-DOTC 10 months ago
parent
commit
a54e8c2176
  1. 6
      src/engine/CollisionEngine/CollisionManager.java
  2. 12
      src/engine/CollisionEngine/Mesh.java
  3. 2
      src/engine/devcmd/cmds/InfoCmd.java
  4. 11
      src/engine/devcmd/cmds/RegionCmd.java
  5. 75
      src/engine/gameManager/BuildingManager.java
  6. 3
      src/engine/objects/Building.java

6
src/engine/CollisionEngine/CollisionManager.java

@ -11,11 +11,11 @@ public class CollisionManager { @@ -11,11 +11,11 @@ public class CollisionManager {
Rectangle.Float boundsRect = new Rectangle.Float();
Vector3f topLeft = new Vector3f(building.loc.x - building.getBounds().getHalfExtents().x,building.loc.y,building.loc.z - building.getBounds().getHalfExtents().y);
boundsRect.setRect(topLeft.x, topLeft.z, building.getBounds().getHalfExtents().x * 2,building.getBounds().getHalfExtents().y * 2);
boundsRect.setRect(topLeft.x, topLeft.z, building.getBounds().getHalfExtents().x * 2,building.getBounds().getHalfExtents().y * 2);
if(travelLine.intersects(boundsRect)){
//collided with building
for(Mesh mesh : building.buildingMeshes) {
if (mesh.MeshCollides(travelLine,charHeight, charY)) {
for(Triangle tri : building.buildingTriangles) {
if (tri.collides(travelLine)) {
//ChatManager.chatSystemInfo(pc, "Collision Detected");
//MovementManager.movement(msg, pc);
return true;

12
src/engine/CollisionEngine/Mesh.java

@ -23,13 +23,15 @@ public class Mesh { @@ -23,13 +23,15 @@ public class Mesh {
public boolean MeshCollides(Line2D line, float charHeight, float charY){
//check if movement path intersects this mesh
if(!this.BoundsCollides(line))
return false;
//if(!this.BoundsCollides(line))
// return false;
//boolean feetcollides = (charY + charHeight) < this.minY;
//boolean headcollides = charY > this.maxY;
//check to see if the mesh collides between the characters feet and head locations
if((charY + charHeight) < this.minY && charY > this.maxY){
return false;
}
//if(feetcollides && headcollides){
// return false;
//}
//check if any triangles intersect the movement path
for(Triangle tri : triangles)

2
src/engine/devcmd/cmds/InfoCmd.java

@ -244,7 +244,7 @@ public class InfoCmd extends AbstractDevCmd { @@ -244,7 +244,7 @@ public class InfoCmd extends AbstractDevCmd {
for (Regions regions : targetBuilding.getBounds().getRegions()) {
//TODO ADD REGION INFO
}
output += "Mesh Count: " + targetBuilding.buildingMeshes.size();
output += "Triangle Count: " + targetBuilding.buildingTriangles.size();
break;
case PlayerCharacter:
output += newline;

11
src/engine/devcmd/cmds/RegionCmd.java

@ -47,17 +47,6 @@ public class RegionCmd extends AbstractDevCmd { @@ -47,17 +47,6 @@ public class RegionCmd extends AbstractDevCmd {
output += "is Outside: " + region.isOutside();
this.throwbackInfo(pc, output);
}
if(building != null){
for(Mesh mesh : building.buildingMeshes){
if(mesh.boundsRect.contains(new Point2D.Float(((AbstractCharacter) target).loc.x,((AbstractCharacter) target).loc.z))){
if(((AbstractCharacter) target).loc.y < mesh.maxY) {
this.throwbackInfo(pc, "Inside Mesh Bounds");
return;
}
}
}
this.throwbackInfo(pc, "Outside Mesh Bounds");
}
}
@Override

75
src/engine/gameManager/BuildingManager.java

@ -982,47 +982,47 @@ public enum BuildingManager { @@ -982,47 +982,47 @@ public enum BuildingManager {
if (building == null)
return;
building.buildingMeshes = new ArrayList<>();
building.buildingTriangles = new ArrayList<>();
float rotation = building.getRot().getRotation();
Vector3f buildingLoc = new Vector3f(building.loc.x, building.loc.y, building.loc.z);
if (!prop_meshes.containsKey(building.meshUUID))
if (!mesh_triangle_points.containsKey(building.meshUUID))
return; //no data for this prop ID
ArrayList<Integer> meshes = prop_meshes.get(building.meshUUID);
for (int mesh : meshes) {
//ArrayList<Integer> meshes = prop_meshes.get(building.meshUUID);
//for (int mesh : meshes) {
if (!mesh_heights.containsKey(mesh) || !mesh_triangle_points.containsKey(mesh))
return; //no data for this mesh
//if (!mesh_heights.containsKey(mesh) || !mesh_triangle_points.containsKey(mesh))
//return; //no data for this mesh
Mesh generatedMesh = new Mesh();
generatedMesh.maxY = building.loc.y + mesh_heights.get(mesh).x;
generatedMesh.minY = building.loc.y + mesh_heights.get(mesh).y;
ArrayList<ArrayList<Vector3f>> triPoints = mesh_triangle_points.get(mesh);
//Mesh generatedMesh = new Mesh();
//generatedMesh.maxY = building.loc.y + mesh_heights.get(mesh).x;
//generatedMesh.minY = building.loc.y + mesh_heights.get(mesh).y;
ArrayList<ArrayList<Vector3f>> triPoints = mesh_triangle_points.get(building.meshUUID);
if (mesh_bounding_boxes.containsKey(mesh)) {
Rectangle2D boundingBox = mesh_bounding_boxes.get(mesh);
//if (mesh_bounding_boxes.containsKey(mesh)) {
//Rectangle2D boundingBox = mesh_bounding_boxes.get(mesh);
//Bounds buildingBounds = building.getBounds();
float halfX = (float) boundingBox.getWidth() * 0.5f;
float halfZ = (float)boundingBox.getHeight() * 0.5f;
Vector3f bottomRight = new Vector3f(building.loc.x + halfX,building.loc.y,building.loc.z + halfZ);
Vector3f topLeft = new Vector3f(building.loc.x - halfX,building.loc.y,building.loc.z - halfZ);
Vector3f topRight = new Vector3f(building.loc.x + halfX,building.loc.y,building.loc.z - halfZ);
Vector3f bottomLeft = new Vector3f(building.loc.x - halfX,building.loc.y,building.loc.z + halfZ);
generatedMesh.BoundingLines = new ArrayList<>();
Point2D.Float p1 = new Point2D.Float(topLeft.x, topLeft.z);
Point2D.Float p2 = new Point2D.Float(topRight.x, topRight.z);
Point2D.Float p3 = new Point2D.Float(bottomRight.x, bottomRight.z);
Point2D.Float p4 = new Point2D.Float(bottomLeft.x, bottomLeft.z);
float rectWidth = topLeft.distance(topRight);
float rectHeight = topLeft.distance(bottomLeft);
boundingBox.setRect(p1.x,p1.y,rectWidth, rectHeight);
generatedMesh.BoundingLines.add(new Line2D.Float(p1, p2));
generatedMesh.BoundingLines.add(new Line2D.Float(p2, p3));
generatedMesh.BoundingLines.add(new Line2D.Float(p3, p4));
generatedMesh.BoundingLines.add(new Line2D.Float(p4, p1));
generatedMesh.boundsRect = boundingBox;
}
generatedMesh.triangles = new ArrayList<>();
//float halfX = (float) boundingBox.getWidth() * 0.5f;
//float halfZ = (float)boundingBox.getHeight() * 0.5f;
//Vector3f bottomRight = new Vector3f(building.loc.x + halfX,building.loc.y,building.loc.z + halfZ);
//Vector3f topLeft = new Vector3f(building.loc.x - halfX,building.loc.y,building.loc.z - halfZ);
//Vector3f topRight = new Vector3f(building.loc.x + halfX,building.loc.y,building.loc.z - halfZ);
//Vector3f bottomLeft = new Vector3f(building.loc.x - halfX,building.loc.y,building.loc.z + halfZ);
//generatedMesh.BoundingLines = new ArrayList<>();
//Point2D.Float p1 = new Point2D.Float(topLeft.x, topLeft.z);
//Point2D.Float p2 = new Point2D.Float(topRight.x, topRight.z);
//Point2D.Float p3 = new Point2D.Float(bottomRight.x, bottomRight.z);
//Point2D.Float p4 = new Point2D.Float(bottomLeft.x, bottomLeft.z);
//float rectWidth = topLeft.distance(topRight);
//float rectHeight = topLeft.distance(bottomLeft);
//boundingBox.setRect(p1.x,p1.y,rectWidth, rectHeight);
//generatedMesh.BoundingLines.add(new Line2D.Float(p1, p2));
//generatedMesh.BoundingLines.add(new Line2D.Float(p2, p3));
//generatedMesh.BoundingLines.add(new Line2D.Float(p3, p4));
//generatedMesh.BoundingLines.add(new Line2D.Float(p4, p1));
//generatedMesh.boundsRect = boundingBox;
//}
//generatedMesh.triangles = new ArrayList<>();
for (ArrayList<Vector3f> pointList : triPoints) {
ArrayList<Vector3f> rotatedPoints = new ArrayList<>();
@ -1040,10 +1040,11 @@ public enum BuildingManager { @@ -1040,10 +1040,11 @@ public enum BuildingManager {
tri.sides.add(new Line2D.Float(p1, p2));
tri.sides.add(new Line2D.Float(p2, p3));
tri.sides.add(new Line2D.Float(p3, p1));
generatedMesh.triangles.add(tri);
//generatedMesh.triangles.add(tri);
building.buildingTriangles.add(tri);
}
building.buildingMeshes.add(generatedMesh);
}
//building.buildingMeshes.add(generatedMesh);
//}
}
catch(Exception e){
Logger.info("Failed To Bake Building Mesh Data For Structure: " + building.meshUUID);

3
src/engine/objects/Building.java

@ -9,6 +9,7 @@ @@ -9,6 +9,7 @@
package engine.objects;
import engine.CollisionEngine.Triangle;
import engine.Enum;
import engine.Enum.*;
import engine.InterestManagement.RealmMap;
@ -100,7 +101,7 @@ public class Building extends AbstractWorldObject { @@ -100,7 +101,7 @@ public class Building extends AbstractWorldObject {
private ConcurrentHashMap<Integer, Condemned> condemned;
private ArrayList<Building> children = null;
public ArrayList<Mesh> buildingMeshes;
public ArrayList<Triangle> buildingTriangles;
/**
* ResultSet Constructor

Loading…
Cancel
Save