OSDN Git Service

[changed] Added null checks for 'intersection' variable in all intersection tests...
authordavedx@gmail.com <davedx@gmail.com@6c4fd544-2939-11df-bb46-9574ba5d0bfa>
Wed, 8 Dec 2010 16:38:30 +0000 (16:38 +0000)
committerdavedx@gmail.com <davedx@gmail.com@6c4fd544-2939-11df-bb46-9574ba5d0bfa>
Wed, 8 Dec 2010 16:38:30 +0000 (16:38 +0000)
gdx/src/com/badlogic/gdx/math/Intersector.java

index b11edd9..e13db9d 100644 (file)
@@ -235,8 +235,8 @@ public final class Intersector {
         * @param plane\r
         *            The plane\r
         * @param intersection\r
-        *            The vector the intersection point is written to\r
-        * @return Wheter an intersection is present.\r
+        *            The vector the intersection point is written to (optional)\r
+        * @return Whether an intersection is present.\r
         */\r
        public static boolean intersectRayPlane(Ray ray, Plane plane,\r
                        Vector3 intersection) {\r
@@ -247,10 +247,12 @@ public final class Intersector {
                        if (t < 0)\r
                                return false;\r
 \r
-                       intersection.set(ray.origin).add(ray.direction.tmp().mul(t));\r
+                       if (intersection != null)\r
+                               intersection.set(ray.origin).add(ray.direction.tmp().mul(t));\r
                        return true;\r
                } else if (plane.testPoint(ray.origin) == Plane.PlaneSide.OnPlane) {\r
-                       intersection.set(ray.origin);\r
+                       if (intersection != null)\r
+                               intersection.set(ray.origin);\r
                        return true;\r
                } else\r
                        return false;\r
@@ -272,7 +274,7 @@ public final class Intersector {
         * @param t3\r
         *            The third vertex of the triangle\r
         * @param intersection\r
-        *            The intersection point\r
+        *            The intersection point (optional)\r
         * @return True in case an intersection is present.\r
         */\r
        public static boolean intersectRayTriangle(Ray ray, Vector3 t1, Vector3 t2,\r
@@ -299,7 +301,8 @@ public final class Intersector {
                float v = (dot00 * dot12 - dot01 * dot02) / denom;\r
 \r
                if (u >= 0 && v >= 0 && u + v <= 1) {\r
-                       intersection.set(i);\r
+                       if(intersection != null)\r
+                               intersection.set(i);\r
                        return true;\r
                } else {\r
                        return false;\r
@@ -320,8 +323,8 @@ public final class Intersector {
         * @param radius\r
         *            The radius of the sphere\r
         * @param intersection\r
-        *            The intersection point\r
-        * @return Wheter an interesection is present.\r
+        *            The intersection point (optional)\r
+        * @return Whether an intersection is present.\r
         */\r
        public static boolean intersectRaySphere(Ray ray, Vector3 center,\r
                        float radius, Vector3 intersection) {\r
@@ -448,10 +451,10 @@ public final class Intersector {
         * @param ray\r
         *            The ray\r
         * @param triangles\r
-        *            The triangles, each succesive 3 elements from a vertex\r
+        *            The triangles, each successive 3 elements from a vertex\r
         * @param intersection\r
-        *            The nearest intersection point\r
-        * @return Wheter the ray and the triangles intersect.\r
+        *            The nearest intersection point (optional)\r
+        * @return Whether the ray and the triangles intersect.\r
         */\r
        public static boolean intersectRayTriangles(Ray ray, float[] triangles,\r
                        Vector3 intersection) {\r
@@ -502,8 +505,8 @@ public final class Intersector {
         * @param vertexSize\r
         *            the size of a vertex in floats\r
         * @param intersection\r
-        *            The nearest intersection point\r
-        * @return Wheter the ray and the triangles intersect.\r
+        *            The nearest intersection point (optional)\r
+        * @return Whether the ray and the triangles intersect.\r
         */\r
        public static boolean intersectRayTriangles(Ray ray, float[] vertices,\r
                        short[] indices, int vertexSize, Vector3 intersection) {\r
@@ -553,8 +556,8 @@ public final class Intersector {
         * @param triangles\r
         *            The triangles\r
         * @param intersection\r
-        *            The nearest intersection point\r
-        * @return Wheter the ray and the triangles intersect.\r
+        *            The nearest intersection point (optional)\r
+        * @return Whether the ray and the triangles intersect.\r
         */\r
        public static boolean intersectRayTriangles(Ray ray,\r
                        List<Vector3> triangles, Vector3 intersection) {\r
@@ -616,7 +619,7 @@ public final class Intersector {
         *            The second point of the second line\r
         * @param intersection\r
         *            The intersection point\r
-        * @return Wheter the two lines intersect\r
+        * @return Whether the two lines intersect\r
         */\r
        public static boolean intersectLines(Vector2 p1, Vector2 p2, Vector2 p3,\r
                        Vector2 p4, Vector2 intersection) {\r
@@ -648,8 +651,8 @@ public final class Intersector {
         * @param p4\r
         *            The second point of the second line segment\r
         * @param intersection\r
-        *            The intersection point\r
-        * @return Wheter the two line segments intersect\r
+        *            The intersection point (optional)\r
+        * @return Whether the two line segments intersect\r
         */\r
        public static boolean intersectSegments(Vector2 p1, Vector2 p2, Vector2 p3,\r
                        Vector2 p4, Vector2 intersection) {\r
@@ -667,7 +670,8 @@ public final class Intersector {
                if (ub < 0 || ub > 1)\r
                        return false;\r
 \r
-               intersection.set(x1 + (x2 - x1) * ua, y1 + (y2 - y1) * ua);\r
+               if (intersection != null)\r
+                       intersection.set(x1 + (x2 - x1) * ua, y1 + (y2 - y1) * ua);\r
                return true;\r
        }\r
 \r