Browse Source

collision work

server-collision
FatBoy-DOTC 11 months ago
parent
commit
67c474dbdf
  1. 7
      src/engine/CollisionEngine/CollisionManager.java
  2. 2
      src/engine/CollisionEngine/Mesh.java
  3. 2
      src/engine/db/handlers/dbBuildingHandler.java

7
src/engine/CollisionEngine/CollisionManager.java

@ -1,5 +1,6 @@
package engine.CollisionEngine; package engine.CollisionEngine;
import engine.math.Vector3f;
import engine.objects.Building; import engine.objects.Building;
import java.awt.*; import java.awt.*;
@ -8,9 +9,9 @@ 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){
Rectangle.Float boundsRect = new Rectangle.Float(); Rectangle.Float boundsRect = new Rectangle.Float();
float rectCenterX = building.loc.x + building.getBounds().getHalfExtents().x; Vector3f topLeft = new Vector3f(building.loc.x - building.getBounds().getHalfExtents().x,building.loc.y,building.loc.z - building.getBounds().getHalfExtents().y);
float rectCenterZ = building.loc.z + building.getBounds().getHalfExtents().y;
boundsRect.setRect(rectCenterX, rectCenterZ, building.getBounds().getHalfExtents().x * 2,building.getBounds().getHalfExtents().y * 2); boundsRect.setRect(topLeft.x, topLeft.z, building.getBounds().getHalfExtents().x * 2,building.getBounds().getHalfExtents().y * 2);
if(travelLine.intersects(boundsRect)){ if(travelLine.intersects(boundsRect)){
//collided with building //collided with building
for(Mesh mesh : building.buildingMeshes) { for(Mesh mesh : building.buildingMeshes) {

2
src/engine/CollisionEngine/Mesh.java

@ -22,7 +22,7 @@ public class Mesh {
public boolean MeshCollides(Line2D line, float charHeight){ public boolean MeshCollides(Line2D line, float charHeight){
//movement path does not intersect this mesh //movement path does not intersect this mesh
if(!this.BoundsCollides(line)) if(line.intersects(boundsRect) == false)
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

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

@ -935,7 +935,7 @@ public class dbBuildingHandler extends dbHandlerBase {
float refZ = Float.parseFloat(rs.getString("ref").split(";")[1]); float refZ = Float.parseFloat(rs.getString("ref").split(";")[1]);
Vector2f topLeft = new Vector2f(centerX - refX,centerZ - refZ); Vector2f topLeft = new Vector2f(centerX - refX,centerZ + refZ);
float width = Math.abs(endX-refX); float width = Math.abs(endX-refX);
float height = Math.abs(endZ-refZ); float height = Math.abs(endZ-refZ);
Rectangle2D boundRect = new Rectangle2D.Float(); Rectangle2D boundRect = new Rectangle2D.Float();

Loading…
Cancel
Save