2013-03-06 148 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