Browse Source

collision handler

server-collision
FatBoy-DOTC 12 months ago
parent
commit
3ad97a7ce3
  1. 34
      src/engine/net/client/handlers/MoveToPointHandler.java

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

@ -10,13 +10,23 @@
package engine.net.client.handlers; package engine.net.client.handlers;
import engine.Enum; import engine.Enum;
import engine.InterestManagement.WorldGrid;
import engine.collision.Mesh;
import engine.collision.Triangle;
import engine.exception.MsgSendException; import engine.exception.MsgSendException;
import engine.gameManager.BuildingManager; import engine.gameManager.BuildingManager;
import engine.gameManager.ChatManager;
import engine.gameManager.MovementManager; import engine.gameManager.MovementManager;
import engine.math.Vector3f;
import engine.math.Vector3fImmutable;
import engine.net.client.ClientConnection; import engine.net.client.ClientConnection;
import engine.net.client.msg.ClientNetMsg; import engine.net.client.msg.ClientNetMsg;
import engine.net.client.msg.MoveToPointMsg; import engine.net.client.msg.MoveToPointMsg;
import engine.objects.*; import engine.objects.*;
import engine.server.MBServerStatics;
import java.awt.*;
import java.awt.geom.Line2D;
public class MoveToPointHandler extends AbstractClientMsgHandler { public class MoveToPointHandler extends AbstractClientMsgHandler {
@ -32,6 +42,30 @@ public class MoveToPointHandler extends AbstractClientMsgHandler {
if(pc == null) if(pc == null)
return true; return true;
//check for collisions
Line2D travelLine = new Line2D.Float();
Vector3fImmutable endLoc = new Vector3fImmutable(msg.getEndLat(),msg.getEndAlt(),msg.getEndLon());
travelLine.setLine(pc.loc.x,pc.loc.z,endLoc.x,endLoc.z);
for(AbstractWorldObject awo : WorldGrid.getObjectsInRangePartial(pc.loc, pc.loc.distance(endLoc), MBServerStatics.MASK_BUILDING)){
Building building = (Building)awo;
Rectangle.Float boundsRect = new Rectangle.Float();
boundsRect.setRect(building.getBounds().getHalfExtents().x, building.getBounds().getHalfExtents().y, 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)){
ChatManager.chatSystemInfo(pc, "Collision Detected");
return true;
}
}
}
}
}
MovementManager.movement(msg, pc); MovementManager.movement(msg, pc);
return true; return true;
} }

Loading…
Cancel
Save