// 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)
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);