Triangle check

This commit is contained in:
2024-01-13 21:27:26 -06:00
parent 0b05e661c7
commit 306c64d236
7 changed files with 22 additions and 31 deletions
@@ -11,11 +11,11 @@ public class CollisionManager {
Rectangle.Float boundsRect = new Rectangle.Float(); 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); 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)){ if(travelLine.intersects(boundsRect)){
//collided with building //collided with building
for(Mesh mesh : building.buildingMeshes) { for(Triangle tri : building.buildingTriangles) {
if (mesh.MeshCollides(travelLine,charHeight, charY)) { if (tri.collides(travelLine)) {
//ChatManager.chatSystemInfo(pc, "Collision Detected"); //ChatManager.chatSystemInfo(pc, "Collision Detected");
//MovementManager.movement(msg, pc); //MovementManager.movement(msg, pc);
return true; return true;
+7 -7
View File
@@ -23,15 +23,15 @@ public class Mesh {
public boolean MeshCollides(Line2D line, float charHeight, float charY){ public boolean MeshCollides(Line2D line, float charHeight, float charY){
//check if movement path intersects this mesh //check if movement path intersects this mesh
if(!this.BoundsCollides(line)) //if(!this.BoundsCollides(line))
return false; // return false;
boolean feetcollides = (charY + charHeight) < this.minY; //boolean feetcollides = (charY + charHeight) < this.minY;
boolean headcollides = charY > this.maxY; //boolean headcollides = charY > this.maxY;
//check to see if the mesh collides between the characters feet and head locations //check to see if the mesh collides between the characters feet and head locations
if(feetcollides && headcollides){ //if(feetcollides && headcollides){
return false; // return false;
} //}
//check if any triangles intersect the movement path //check if any triangles intersect the movement path
for(Triangle tri : triangles) for(Triangle tri : triangles)
@@ -896,18 +896,18 @@ public class dbBuildingHandler extends dbHandlerBase {
triPoints.add(new Vector3f(floatPoints.get(i),floatPoints.get(i+1),floatPoints.get(i+2))); triPoints.add(new Vector3f(floatPoints.get(i),floatPoints.get(i+1),floatPoints.get(i+2)));
} }
if(BuildingManager.mesh_triangle_points.containsKey(rs.getInt("meshID")) == false){ if(BuildingManager.mesh_triangle_points.containsKey(rs.getInt("propId")) == false){
ArrayList<ArrayList<Vector3f>> newPoints = new ArrayList<>(); ArrayList<ArrayList<Vector3f>> newPoints = new ArrayList<>();
newPoints.add(triPoints); newPoints.add(triPoints);
BuildingManager.mesh_triangle_points.put(rs.getInt("meshID"),newPoints); BuildingManager.mesh_triangle_points.put(rs.getInt("propId"),newPoints);
} }
else else
{ {
BuildingManager.mesh_triangle_points.get(rs.getInt("meshID")).add(triPoints); BuildingManager.mesh_triangle_points.get(rs.getInt("propId")).add(triPoints);
} }
if(BuildingManager.mesh_heights.containsKey(rs.getInt("meshID")) == false){ if(BuildingManager.mesh_heights.containsKey(rs.getInt("propId")) == false){
Vector2f heights = new Vector2f(rs.getFloat("maxY"),rs.getFloat("minY")); Vector2f heights = new Vector2f(rs.getFloat("maxY"),rs.getFloat("minY"));
BuildingManager.mesh_heights.put(rs.getInt("meshID"),heights); BuildingManager.mesh_heights.put(rs.getInt("propId"),heights);
} }
} }
+1 -1
View File
@@ -244,7 +244,7 @@ public class InfoCmd extends AbstractDevCmd {
for (Regions regions : targetBuilding.getBounds().getRegions()) { for (Regions regions : targetBuilding.getBounds().getRegions()) {
//TODO ADD REGION INFO //TODO ADD REGION INFO
} }
output += "Mesh Count: " + targetBuilding.buildingMeshes.size(); output += "Triangle Count: " + targetBuilding.buildingTriangles.size();
break; break;
case PlayerCharacter: case PlayerCharacter:
output += newline; output += newline;
-11
View File
@@ -47,17 +47,6 @@ public class RegionCmd extends AbstractDevCmd {
output += "is Outside: " + region.isOutside(); output += "is Outside: " + region.isOutside();
this.throwbackInfo(pc, output); 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 @Override
+4 -3
View File
@@ -982,7 +982,7 @@ public enum BuildingManager {
if (building == null) if (building == null)
return; return;
building.buildingMeshes = new ArrayList<>(); building.buildingTriangles = new ArrayList<>();
float rotation = building.getRot().getRotation(); float rotation = building.getRot().getRotation();
Vector3f buildingLoc = new Vector3f(building.loc.x, building.loc.y, building.loc.z); Vector3f buildingLoc = new Vector3f(building.loc.x, building.loc.y, building.loc.z);
if (!prop_meshes.containsKey(building.meshUUID)) if (!prop_meshes.containsKey(building.meshUUID))
@@ -1040,9 +1040,10 @@ public enum BuildingManager {
tri.sides.add(new Line2D.Float(p1, p2)); tri.sides.add(new Line2D.Float(p1, p2));
tri.sides.add(new Line2D.Float(p2, p3)); tri.sides.add(new Line2D.Float(p2, p3));
tri.sides.add(new Line2D.Float(p3, p1)); 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.buildingTriangles.add(generatedMesh);
} }
} }
catch(Exception e){ catch(Exception e){
+2 -1
View File
@@ -9,6 +9,7 @@
package engine.objects; package engine.objects;
import engine.CollisionEngine.Triangle;
import engine.Enum; import engine.Enum;
import engine.Enum.*; import engine.Enum.*;
import engine.InterestManagement.RealmMap; import engine.InterestManagement.RealmMap;
@@ -100,7 +101,7 @@ public class Building extends AbstractWorldObject {
private ConcurrentHashMap<Integer, Condemned> condemned; private ConcurrentHashMap<Integer, Condemned> condemned;
private ArrayList<Building> children = null; private ArrayList<Building> children = null;
public ArrayList<Mesh> buildingMeshes; public ArrayList<Triangle> buildingTriangles;
/** /**
* ResultSet Constructor * ResultSet Constructor