|
|
@ -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) { |
|
|
|