]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - mathlib.h
some cleanup of Mod_Alias_GetMesh_Vertex3f
[xonotic/darkplaces.git] / mathlib.h
index 8c5f8243ff3d9453a3df5212e3b286583b42511e..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);
 
@@ -180,8 +185,8 @@ float VectorNormalizeLength2 (vec3_t v, vec3_t dest);               // returns vector length
 #define NUMVERTEXNORMALS       162
 extern float m_bytenormals[NUMVERTEXNORMALS][3];
 
-qbyte NormalToByte(const vec3_t n);
-void ByteToNormal(qbyte num, vec3_t n);
+unsigned char NormalToByte(const vec3_t n);
+void ByteToNormal(unsigned char num, vec3_t n);
 
 void R_ConcatRotations (const float in1[3*3], const float in2[3*3], float out[3*3]);
 void R_ConcatTransforms (const float in1[3*4], const float in2[3*4], float out[3*4]);