Browse Source

load mesh data and structure meshes

server-collision
FatBoy-DOTC 10 months ago
parent
commit
9d8f800c2a
  1. 5
      src/engine/CollisionEngine/CollisionManager.java
  2. 7
      src/engine/devcmd/cmds/InfoCmd.java
  3. 4
      src/engine/devcmd/cmds/RegionCmd.java
  4. 6
      src/engine/gameManager/BuildingManager.java
  5. 22
      src/engine/net/client/handlers/MoveToPointHandler.java

5
src/engine/CollisionEngine/CollisionManager.java

@ -10,8 +10,9 @@ import java.awt.geom.Rectangle2D;
public class CollisionManager { public class CollisionManager {
public static boolean CollisionDetected(Building building, Line2D travelLine, float charHeight, float charY){ public static boolean CollisionDetected(Building building, Line2D travelLine, float charHeight, float charY){
if(building.buildingRect != null && !travelLine.intersects(building.buildingRect) && !building.buildingRect.contains(travelLine.getP1()) && !building.buildingRect.contains(travelLine.getP2())) if(building.buildingRect != null)
return false; if(!travelLine.intersects(building.buildingRect) && !building.buildingRect.contains(travelLine.getP1()) && !building.buildingRect.contains(travelLine.getP2()))
return false;
for (Mesh mesh : building.buildingMeshes) for (Mesh mesh : building.buildingMeshes)
if(mesh.MeshCollides(travelLine,charHeight,charY)) if(mesh.MeshCollides(travelLine,charHeight,charY))

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

@ -9,6 +9,7 @@
package engine.devcmd.cmds; package engine.devcmd.cmds;
import engine.CollisionEngine.Mesh;
import engine.Enum; import engine.Enum;
import engine.Enum.BuildingGroup; import engine.Enum.BuildingGroup;
import engine.Enum.GameObjectType; import engine.Enum.GameObjectType;
@ -244,7 +245,11 @@ 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 += "-------Mesh Data-------" + newline;
output += "Mesh Count: " + targetBuilding.buildingMeshes.size() + newline;
for(Mesh mesh : targetBuilding.buildingMeshes){
output += "Mesh Rect: " + mesh.boundsRect + newline;
}
break; break;
case PlayerCharacter: case PlayerCharacter:
output += newline; output += newline;

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

@ -48,10 +48,12 @@ public class RegionCmd extends AbstractDevCmd {
this.throwbackInfo(pc, output); this.throwbackInfo(pc, output);
} }
if(building != null){ if(building != null){
this.throwbackInfo(pc, "Building Rect: " + building.buildingRect);
for (Mesh mesh : building.buildingMeshes){ for (Mesh mesh : building.buildingMeshes){
this.throwbackInfo(pc, "Mesh Rect: " + mesh.boundsRect); //this.throwbackInfo(pc, "Mesh Rect: " + mesh.boundsRect);
if(mesh.boundsRect.contains(pc.loc.x,pc.loc.z)) { if(mesh.boundsRect.contains(pc.loc.x,pc.loc.z)) {
this.throwbackInfo(pc, "Inside A Mesh's Bounds"); this.throwbackInfo(pc, "Inside A Mesh's Bounds");
this.throwbackInfo(pc, "Rect: " + mesh.boundsRect);
return; return;
} }
} }

6
src/engine/gameManager/BuildingManager.java

@ -986,7 +986,9 @@ public enum BuildingManager {
int i = 0; // stop point for testing int i = 0; // stop point for testing
} }
building.buildingMeshes = new ArrayList<>(); building.buildingMeshes = new ArrayList<>();
float rotation = building.getRot().getRotation(); //float rotation = building.getRot().getRotation();
double radian = building.getBounds().getQuaternion().angleY;
int degrees = (int) Math.toDegrees(radian);
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) == false) if(prop_meshes.containsKey(building.meshUUID) == false)
return;//no meshes to load for this prop return;//no meshes to load for this prop
@ -1039,7 +1041,7 @@ public enum BuildingManager {
ArrayList<Vector3f> rotatedPoints = new ArrayList<>(); ArrayList<Vector3f> rotatedPoints = new ArrayList<>();
for (Vector3f point : pointList) { for (Vector3f point : pointList) {
Vector3f calculatedOffsetPoint = buildingLoc.add(point); Vector3f calculatedOffsetPoint = buildingLoc.add(point);
rotatedPoints.add(Vector3f.rotateAroundPoint(buildingLoc, calculatedOffsetPoint, rotation)); rotatedPoints.add(Vector3f.rotateAroundPoint(buildingLoc, calculatedOffsetPoint, radian));
} }
Point2D.Float p1 = new Point2D.Float(rotatedPoints.get(0).x, rotatedPoints.get(0).z); Point2D.Float p1 = new Point2D.Float(rotatedPoints.get(0).x, rotatedPoints.get(0).z);

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

@ -11,6 +11,7 @@ package engine.net.client.handlers;
import engine.InterestManagement.WorldGrid; import engine.InterestManagement.WorldGrid;
import engine.exception.MsgSendException; import engine.exception.MsgSendException;
import engine.gameManager.BuildingManager;
import engine.gameManager.ChatManager; import engine.gameManager.ChatManager;
import engine.CollisionEngine.CollisionManager; import engine.CollisionEngine.CollisionManager;
import engine.gameManager.MovementManager; import engine.gameManager.MovementManager;
@ -43,16 +44,27 @@ public class MoveToPointHandler extends AbstractClientMsgHandler {
Line2D travelLine = new Line2D.Float(); Line2D travelLine = new Line2D.Float();
Vector3fImmutable endLoc = new Vector3fImmutable(msg.getEndLat(),msg.getEndAlt(),msg.getEndLon()); Vector3fImmutable endLoc = new Vector3fImmutable(msg.getEndLat(),msg.getEndAlt(),msg.getEndLon());
travelLine.setLine(pc.loc.x,pc.loc.z,endLoc.x,endLoc.z); travelLine.setLine(pc.loc.x,pc.loc.z,endLoc.x,endLoc.z);
HashSet<AbstractWorldObject> awoList = WorldGrid.getObjectsInRangePartial(pc.loc, 1000, MBServerStatics.MASK_BUILDING); if(BuildingManager.getBuildingAtLocation(pc.loc) != null){
for(AbstractWorldObject awo : awoList){ Building current = BuildingManager.getBuildingAtLocation(pc.loc);
Building building = (Building)awo; if (CollisionManager.CollisionDetected(current, travelLine, pc.getCharacterHeight(), pc.loc.y)) {
if(CollisionManager.CollisionDetected(building, travelLine,pc.getCharacterHeight(),pc.loc.y)){ ChatManager.chatSystemInfo(pc, "Collision Detected With : " + current.getName() + " Rect: " + current.buildingRect);
ChatManager.chatSystemInfo(pc, "Collision Detected");
//msg.setEndCoord(); //msg.setEndCoord();
MovementManager.movement(msg, pc); MovementManager.movement(msg, pc);
return true; return true;
} }
} }
HashSet<AbstractWorldObject> awoList = WorldGrid.getObjectsInRangePartial(pc.loc, 1000, MBServerStatics.MASK_BUILDING);
for(AbstractWorldObject awo : awoList){
Building building = (Building)awo;
if(travelLine.intersects(building.buildingRect) || building.buildingRect.contains(travelLine.getP1()) || building.buildingRect.contains(travelLine.getP2())) {
if (CollisionManager.CollisionDetected(building, travelLine, pc.getCharacterHeight(), pc.loc.y)) {
ChatManager.chatSystemInfo(pc, "Collision Detected With : " + building.getName() + " Rect: " + building.buildingRect);
//msg.setEndCoord();
MovementManager.movement(msg, pc);
return true;
}
}
}
//ChatManager.chatSystemInfo(pc, "No Collision Detected"); //ChatManager.chatSystemInfo(pc, "No Collision Detected");
MovementManager.movement(msg, pc); MovementManager.movement(msg, pc);
return true; return true;

Loading…
Cancel
Save