Browse Source

utilize min and max Y values for meshes

server-collision
FatBoy-DOTC 12 months ago
parent
commit
fd47c90f4f
  1. 4
      src/engine/CollisionEngine/CollisionManager.java
  2. 10
      src/engine/CollisionEngine/Mesh.java
  3. 3
      src/engine/db/handlers/dbBuildingHandler.java
  4. 2
      src/engine/devcmd/cmds/RegionCmd.java
  5. 6
      src/engine/gameManager/BuildingManager.java
  6. 2
      src/engine/net/client/handlers/MoveToPointHandler.java

4
src/engine/CollisionEngine/CollisionManager.java

@ -7,7 +7,7 @@ import java.awt.*;
import java.awt.geom.Line2D; import java.awt.geom.Line2D;
public class CollisionManager { public class CollisionManager {
public static boolean CollisionDetected(Building building, Line2D travelLine, float charHeight){ public static boolean CollisionDetected(Building building, Line2D travelLine, float charHeight, float charY){
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);
@ -15,7 +15,7 @@ public class CollisionManager {
if(travelLine.intersects(boundsRect)){ if(travelLine.intersects(boundsRect)){
//collided with building //collided with building
for(Mesh mesh : building.buildingMeshes) { for(Mesh mesh : building.buildingMeshes) {
if (mesh.MeshCollides(travelLine,charHeight)) { if (mesh.MeshCollides(travelLine,charHeight, charY)) {
//ChatManager.chatSystemInfo(pc, "Collision Detected"); //ChatManager.chatSystemInfo(pc, "Collision Detected");
//MovementManager.movement(msg, pc); //MovementManager.movement(msg, pc);
return true; return true;

10
src/engine/CollisionEngine/Mesh.java

@ -9,7 +9,8 @@ public class Mesh {
public ArrayList<Triangle> triangles; public ArrayList<Triangle> triangles;
public ArrayList<Line2D> BoundingLines; public ArrayList<Line2D> BoundingLines;
public Rectangle2D boundsRect; public Rectangle2D boundsRect;
public float meshHeight; public float maxY;
public float minY;
public boolean BoundsCollides(Line2D line){ public boolean BoundsCollides(Line2D line){
for(Line2D side : BoundingLines) for(Line2D side : BoundingLines)
@ -19,14 +20,15 @@ public class Mesh {
return false; return false;
} }
public boolean MeshCollides(Line2D line, float charHeight){ public boolean MeshCollides(Line2D line, float charHeight, float charY){
//movement path does not intersect this mesh //movement path does not intersect this mesh
if(line.intersects(boundsRect) == false) //if(line.intersects(boundsRect) == false)
if(!this.BoundsCollides(line))
return false; return false;
//character moving is higher than the max Y of this mesh //character moving is higher than the max Y of this mesh
if(charHeight > this.meshHeight) if(charY > this.maxY && charHeight + charY < this.minY)
return false; return false;
for(Triangle tri : triangles) for(Triangle tri : triangles)

3
src/engine/db/handlers/dbBuildingHandler.java

@ -923,7 +923,8 @@ public class dbBuildingHandler extends dbHandlerBase {
while (rs.next()) { while (rs.next()) {
if(BuildingManager.mesh_heights.containsKey(rs.getInt("meshID")) == false){ if(BuildingManager.mesh_heights.containsKey(rs.getInt("meshID")) == false){
BuildingManager.mesh_heights.put(rs.getInt("meshID"),rs.getFloat("maxY")); Vector2f heights = new Vector2f(rs.getFloat("maxY"),rs.getFloat("minY"));
BuildingManager.mesh_heights.put(rs.getInt("meshID"),heights);
} }
} }

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

@ -50,7 +50,7 @@ public class RegionCmd extends AbstractDevCmd {
if(building != null){ if(building != null){
for(Mesh mesh : building.buildingMeshes){ for(Mesh mesh : building.buildingMeshes){
if(mesh.boundsRect.contains(new Point2D.Float(((AbstractCharacter) target).loc.x,((AbstractCharacter) target).loc.z))){ if(mesh.boundsRect.contains(new Point2D.Float(((AbstractCharacter) target).loc.x,((AbstractCharacter) target).loc.z))){
if(((AbstractCharacter) target).loc.y < mesh.meshHeight) { if(((AbstractCharacter) target).loc.y < mesh.maxY) {
this.throwbackInfo(pc, "Inside Mesh Bounds"); this.throwbackInfo(pc, "Inside Mesh Bounds");
return; return;
} }

6
src/engine/gameManager/BuildingManager.java

@ -20,6 +20,7 @@ import engine.job.JobContainer;
import engine.job.JobScheduler; import engine.job.JobScheduler;
import engine.jobs.UpgradeBuildingJob; import engine.jobs.UpgradeBuildingJob;
import engine.math.Bounds; import engine.math.Bounds;
import engine.math.Vector2f;
import engine.math.Vector3f; import engine.math.Vector3f;
import engine.math.Vector3fImmutable; import engine.math.Vector3fImmutable;
import engine.net.client.ClientConnection; import engine.net.client.ClientConnection;
@ -45,7 +46,7 @@ public enum BuildingManager {
BUILDINGMANAGER; BUILDINGMANAGER;
public static HashMap<Integer,ArrayList<Integer>> prop_meshes = new HashMap<>(); public static HashMap<Integer,ArrayList<Integer>> prop_meshes = new HashMap<>();
public static HashMap<Integer,Float> mesh_heights = new HashMap<>(); public static HashMap<Integer, Vector2f> mesh_heights = new HashMap<>();
public static HashMap<Integer,ArrayList<ArrayList<Vector3f>>> mesh_triangle_points = new HashMap<>(); public static HashMap<Integer,ArrayList<ArrayList<Vector3f>>> mesh_triangle_points = new HashMap<>();
public static HashMap<Integer, Rectangle2D> mesh_bounding_boxes = new HashMap<>(); public static HashMap<Integer, Rectangle2D> mesh_bounding_boxes = new HashMap<>();
@ -993,7 +994,8 @@ public enum BuildingManager {
return; //no data for this mesh return; //no data for this mesh
Mesh generatedMesh = new Mesh(); Mesh generatedMesh = new Mesh();
generatedMesh.meshHeight = building.loc.y + mesh_heights.get(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); ArrayList<ArrayList<Vector3f>> triPoints = mesh_triangle_points.get(mesh);
if (mesh_bounding_boxes.containsKey(mesh)) { if (mesh_bounding_boxes.containsKey(mesh)) {

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

@ -47,7 +47,7 @@ public class MoveToPointHandler extends AbstractClientMsgHandler {
HashSet<AbstractWorldObject> awoList = WorldGrid.getObjectsInRangePartial(pc.loc, movementDistance, MBServerStatics.MASK_BUILDING); HashSet<AbstractWorldObject> awoList = WorldGrid.getObjectsInRangePartial(pc.loc, movementDistance, MBServerStatics.MASK_BUILDING);
for(AbstractWorldObject awo : awoList){ for(AbstractWorldObject awo : awoList){
Building building = (Building)awo; Building building = (Building)awo;
if(CollisionManager.CollisionDetected(building, travelLine,pc.getCharacterHeight())){ if(CollisionManager.CollisionDetected(building, travelLine,pc.getCharacterHeight(),pc.loc.y)){
ChatManager.chatSystemInfo(pc, "Collision Detected"); ChatManager.chatSystemInfo(pc, "Collision Detected");
//msg.setEndCoord(); //msg.setEndCoord();
MovementManager.movement(msg, pc); MovementManager.movement(msg, pc);

Loading…
Cancel
Save