2013-03-06 144 views
1

在我的libgdx游戏中,我为地图和玩家对象设置了3D BoundingBoxes。我想知道他们是否在3D空间中碰撞。我怎样才能做到这一点?libgdx中两个BoundingBoxes之间的碰撞检测

+0

这是为什么“不是一个真正的问题”,这是在这里? http://stackoverflow.com/questions/15247347/collision-detection-between-a-boundingbox-and-a-sphere-in-libgdx – nerdinand 2013-03-08 17:52:54

回答

2

您可以使用下面的方法:

public static boolean intersectsWith(BoundingBox boundingBox1, BoundingBox boundingBox2) { 
     Vector3 otherMin = boundingBox1.getMin(); 
     Vector3 otherMax = boundingBox1.getMax(); 
     Vector3 min = boundingBox2.getMin(); 
     Vector3 max = boundingBox2.getMax(); 

     return (min.x < otherMax.x) && (max.x > otherMin.x) 
      && (min.y < otherMax.y) && (max.y > otherMin.y) 
      && (min.z < otherMax.z) && (max.z > otherMin.z); 
    } 

它的这种方法模仿:https://github.com/MasDennis/Rajawali/blob/master/src/rajawali/bounds/BoundingBox.java#L186