]> de.git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
slight readability improvement to PointInfrontOfTriangle
authorhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Tue, 21 Mar 2006 09:07:34 +0000 (09:07 +0000)
committerhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Tue, 21 Mar 2006 09:07:34 +0000 (09:07 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@6159 d7cf8633-e32d-0410-b094-e92efae38249

mathlib.h

index b40e6f33739271ea23938b779b841c63f917da33..2ce09e514fee393f94a5e8a84ac05b7e3e854a61 100644 (file)
--- a/mathlib.h
+++ b/mathlib.h
@@ -101,9 +101,14 @@ extern vec3_t vec3_origin;
 // finally a comparison to determine if the light is infront of the triangle
 // (the goal of this statement) we do not need to normalize the surface
 // normal because both sides of the comparison use it, therefore they are
-// both multiplied the same amount...  furthermore the subtract can be done
-// on the vectors, saving a little bit of math in the dotproducts
-#define PointInfrontOfTriangle(p,a,b,c) (((p)[0] - (a)[0]) * (((a)[1] - (b)[1]) * ((c)[2] - (b)[2]) - ((a)[2] - (b)[2]) * ((c)[1] - (b)[1])) + ((p)[1] - (a)[1]) * (((a)[2] - (b)[2]) * ((c)[0] - (b)[0]) - ((a)[0] - (b)[0]) * ((c)[2] - (b)[2])) + ((p)[2] - (a)[2]) * (((a)[0] - (b)[0]) * ((c)[1] - (b)[1]) - ((a)[1] - (b)[1]) * ((c)[0] - (b)[0])) > 0)
+// both multiplied the same amount...  furthermore a subtract can be done on
+// the point to eliminate one dotproduct
+// this is ((p - a) * cross(a-b,c-b))
+#define PointInfrontOfTriangle(p,a,b,c) \
+( ((p)[0] - (a)[0]) * (((a)[1] - (b)[1]) * ((c)[2] - (b)[2]) - ((a)[2] - (b)[2]) * ((c)[1] - (b)[1])) \
++ ((p)[1] - (a)[1]) * (((a)[2] - (b)[2]) * ((c)[0] - (b)[0]) - ((a)[0] - (b)[0]) * ((c)[2] - (b)[2])) \
++ ((p)[2] - (a)[2]) * (((a)[0] - (b)[0]) * ((c)[1] - (b)[1]) - ((a)[1] - (b)[1]) * ((c)[0] - (b)[0])) > 0)
+
 #if 0
 // readable version, kept only for explanatory reasons
 int PointInfrontOfTriangle(const float *p, const float *a, const float *b, const float *c)
@@ -115,7 +120,7 @@ int PointInfrontOfTriangle(const float *p, const float *a, const float *b, const
        VectorSubtract(c, b, dir1);
 
        // we have two edge directions, we can calculate a third vector from
-       // them, which is the direction of the surface normal (it's magnitude
+       // them, which is the direction of the surface normal (its magnitude
        // is not 1 however)
        CrossProduct(dir0, dir1, normal);