Browse Source

utilize min and max Y values for meshes

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

10
src/engine/CollisionEngine/Mesh.java

@ -9,7 +9,8 @@ public class Mesh { @@ -9,7 +9,8 @@ public class Mesh {
public ArrayList<Triangle> triangles;
public ArrayList<Line2D> BoundingLines;
public Rectangle2D boundsRect;
public float meshHeight;
public float maxY;
public float minY;
public boolean BoundsCollides(Line2D line){
for(Line2D side : BoundingLines)
@ -19,14 +20,15 @@ public class Mesh { @@ -19,14 +20,15 @@ public class Mesh {
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
if(line.intersects(boundsRect) == false)
//if(line.intersects(boundsRect) == false)
if(!this.BoundsCollides(line))
return false;
//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;
for(Triangle tri : triangles)

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

@ -923,7 +923,8 @@ public class dbBuildingHandler extends dbHandlerBase { @@ -923,7 +923,8 @@ public class dbBuildingHandler extends dbHandlerBase {
while (rs.next()) {
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 { @@ -50,7 +50,7 @@ public class RegionCmd extends AbstractDevCmd {
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.meshHeight) {
if(((AbstractCharacter) target).loc.y < mesh.maxY) {
this.throwbackInfo(pc, "Inside Mesh Bounds");
return;
}

6
src/engine/gameManager/BuildingManager.java

@ -20,6 +20,7 @@ import engine.job.JobContainer; @@ -20,6 +20,7 @@ import engine.job.JobContainer;
import engine.job.JobScheduler;
import engine.jobs.UpgradeBuildingJob;
import engine.math.Bounds;
import engine.math.Vector2f;
import engine.math.Vector3f;
import engine.math.Vector3fImmutable;
import engine.net.client.ClientConnection;
@ -45,7 +46,7 @@ public enum BuildingManager { @@ -45,7 +46,7 @@ public enum BuildingManager {
BUILDINGMANAGER;
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, Rectangle2D> mesh_bounding_boxes = new HashMap<>();
@ -993,7 +994,8 @@ public enum BuildingManager { @@ -993,7 +994,8 @@ public enum BuildingManager {
return; //no data for this 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);
if (mesh_bounding_boxes.containsKey(mesh)) {

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

@ -47,7 +47,7 @@ public class MoveToPointHandler extends AbstractClientMsgHandler { @@ -47,7 +47,7 @@ public class MoveToPointHandler extends AbstractClientMsgHandler {
HashSet<AbstractWorldObject> awoList = WorldGrid.getObjectsInRangePartial(pc.loc, movementDistance, MBServerStatics.MASK_BUILDING);
for(AbstractWorldObject awo : awoList){
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");
//msg.setEndCoord();
MovementManager.movement(msg, pc);

Loading…
Cancel
Save