OSDN Git Service

Adding a way to intersect BB.
authorVinceAngel <vinceangel3d@gmail.com>
Wed, 28 Aug 2013 14:36:24 +0000 (16:36 +0200)
committerVinceAngel <vinceangel3d@gmail.com>
Wed, 28 Aug 2013 14:36:24 +0000 (16:36 +0200)
gdx/src/com/badlogic/gdx/math/collision/BoundingBox.java

index 215ed9a..e65c6c5 100644 (file)
@@ -242,6 +242,25 @@ public class BoundingBox implements Serializable {
                        || (min.x <= b.min.x && min.y <= b.min.y && min.z <= b.min.z && max.x >= b.max.x && max.y >= b.max.y && max.z >= b.max.z);\r
        }\r
 \r
+       /** Returns whether the given bounding box is intersecting this bounding box (at least one point in).\r
+        * @param b The bounding box\r
+        * @return Whether the given bounding box is intersected  */\r
+       public boolean intersects (BoundingBox b) {\r
+               if(!isValid())\r
+                       return false;\r
+               \r
+               updateCorners();\r
+               \r
+               return  contains(crn[0]) || \r
+                                       contains(crn[1]) ||\r
+                                       contains(crn[2]) ||\r
+                                       contains(crn[3]) ||\r
+                                       contains(crn[4]) ||\r
+                                       contains(crn[5]) ||\r
+                                       contains(crn[6]) ||\r
+                                       contains(crn[7]);\r
+       }\r
+       \r
        /** Returns whether the given vector is contained in this bounding box.\r
         * @param v The vector\r
         * @return Whether the vector is contained or not. */\r