From: havoc Date: Tue, 21 Mar 2006 09:07:34 +0000 (+0000) Subject: slight readability improvement to PointInfrontOfTriangle X-Git-Tag: xonotic-v0.1.0preview~4160 X-Git-Url: http://de.git.xonotic.org/?p=xonotic%2Fdarkplaces.git;a=commitdiff_plain;h=fdebb9cc4e3c3a88cea57bf74a1207cdd4dfa18d slight readability improvement to PointInfrontOfTriangle git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@6159 d7cf8633-e32d-0410-b094-e92efae38249 --- diff --git a/mathlib.h b/mathlib.h index b40e6f33..2ce09e51 100644 --- 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);