Browse Source

added COllisionManager

server-collision
FatBoy-DOTC 11 months ago
parent
commit
c25fdf3823
  1. 4
      src/engine/collision/Mesh.java
  2. 2
      src/engine/gameManager/BuildingManager.java
  3. 27
      src/engine/gameManager/CollisionManager.java
  4. 23
      src/engine/net/client/handlers/MoveToPointHandler.java

4
src/engine/collision/Mesh.java

@ -26,14 +26,14 @@ public class Mesh { @@ -26,14 +26,14 @@ public class Mesh {
return false;
//character moving is higher than the max Y of this mesh
if(charHeight < this.meshHeight)
if(charHeight > this.meshHeight)
return false;
for(Triangle tri : triangles)
if(tri.collides(line))
return true;
//characters movement path did not intersect this triangle
//characters movement path did not intersect this mesh
return false;
}
}

2
src/engine/gameManager/BuildingManager.java

@ -30,7 +30,6 @@ import engine.objects.*; @@ -30,7 +30,6 @@ import engine.objects.*;
import engine.server.MBServerStatics;
import org.pmw.tinylog.Logger;
import java.awt.*;
import java.awt.geom.Line2D;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
@ -1042,5 +1041,4 @@ public enum BuildingManager { @@ -1042,5 +1041,4 @@ public enum BuildingManager {
Logger.info("Failed To Bake Building Mesh Data For Structure: " + building.meshUUID);
}
}
}

27
src/engine/gameManager/CollisionManager.java

@ -0,0 +1,27 @@ @@ -0,0 +1,27 @@
package engine.gameManager;
import engine.collision.Mesh;
import engine.objects.Building;
import java.awt.*;
import java.awt.geom.Line2D;
public class CollisionManager {
public static boolean CollisionDetected(Building building, Line2D travelLine, float charHeight){
Rectangle.Float boundsRect = new Rectangle.Float();
float rectCenterX = building.loc.x + building.getBounds().getHalfExtents().x;
float rectCenterZ = building.loc.z + building.getBounds().getHalfExtents().y;
boundsRect.setRect(rectCenterX, rectCenterZ, 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)) {
//ChatManager.chatSystemInfo(pc, "Collision Detected");
//MovementManager.movement(msg, pc);
return true;
}
}
}
return false;
}
}

23
src/engine/net/client/handlers/MoveToPointHandler.java

@ -9,15 +9,11 @@ @@ -9,15 +9,11 @@
package engine.net.client.handlers;
import engine.Enum;
import engine.InterestManagement.WorldGrid;
import engine.collision.Mesh;
import engine.collision.Triangle;
import engine.exception.MsgSendException;
import engine.gameManager.BuildingManager;
import engine.gameManager.ChatManager;
import engine.gameManager.CollisionManager;
import engine.gameManager.MovementManager;
import engine.math.Vector3f;
import engine.math.Vector3fImmutable;
import engine.net.client.ClientConnection;
import engine.net.client.msg.ClientNetMsg;
@ -25,7 +21,6 @@ import engine.net.client.msg.MoveToPointMsg; @@ -25,7 +21,6 @@ import engine.net.client.msg.MoveToPointMsg;
import engine.objects.*;
import engine.server.MBServerStatics;
import java.awt.*;
import java.awt.geom.Line2D;
import java.util.HashSet;
@ -49,27 +44,15 @@ public class MoveToPointHandler extends AbstractClientMsgHandler { @@ -49,27 +44,15 @@ public class MoveToPointHandler extends AbstractClientMsgHandler {
Vector3fImmutable endLoc = new Vector3fImmutable(msg.getEndLat(),msg.getEndAlt(),msg.getEndLon());
travelLine.setLine(pc.loc.x,pc.loc.z,endLoc.x,endLoc.z);
float movementDistance = 185 + pc.loc.distance(endLoc);
boolean collided = false;
HashSet<AbstractWorldObject> awoList = WorldGrid.getObjectsInRangePartial(pc.loc, movementDistance, MBServerStatics.MASK_BUILDING);
for(AbstractWorldObject awo : awoList){
Building building = (Building)awo;
Rectangle.Float boundsRect = new Rectangle.Float();
float rectCenterX = building.loc.x + building.getBounds().getHalfExtents().x;
float rectCenterZ = building.loc.z + building.getBounds().getHalfExtents().y;
boundsRect.setRect(rectCenterX, rectCenterZ, 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,pc.getCharacterHeight()))
for (Triangle tri : mesh.triangles)
if (tri.collides(travelLine)){
if(CollisionManager.CollisionDetected(building, travelLine,pc.getCharacterHeight())){
ChatManager.chatSystemInfo(pc, "Collision Detected");
//msg.setEndCoord();
MovementManager.movement(msg, pc);
return true;
}
}
}
}
ChatManager.chatSystemInfo(pc, "No Collision Detected");
MovementManager.movement(msg, pc);

Loading…
Cancel
Save