]> git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
a little more explanation of shadow edge code
authorhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Thu, 24 Jul 2003 07:20:18 +0000 (07:20 +0000)
committerhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Thu, 24 Jul 2003 07:20:18 +0000 (07:20 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@3318 d7cf8633-e32d-0410-b094-e92efae38249

r_shadow.c

index 6362eb05aed6b42f5038e40a6afb2b6ddddd232a..6e8ad30234db6b8c22adf6e7b88bee372ae37962 100644 (file)
@@ -276,6 +276,25 @@ int *R_Shadow_ResizeShadowElements(int numtris)
 
 /*
 // readable version of some code found below
+//if ((t >= trianglerange_start && t < trianglerange_end) ? (t < i && !trianglefacinglight[t]) : (t < 0 || (te = inelement3i + t * 3, v[0] = invertex3f + te[0] * 3, v[1] = invertex3f + te[1] * 3, v[2] = invertex3f + te[2] * 3, !PointInfrontOfTriangle(relativelightorigin, v[0], v[1], v[2]))))
+int PointInfrontOfTriangle(const float *p, const float *a, const float *b, const float *c)
+{
+       float dir0[3], dir1[3], normal[3];
+
+       // calculate two mostly perpendicular edge directions
+       VectorSubtract(a, b, dir0);
+       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
+       // is not 1 however)
+       CrossProduct(dir0, dir1, normal);
+
+       // compare distance of light along normal, with distance of any point
+       // of the triangle along the same normal (the triangle is planar,
+       // I.E. flat, so all points give the same answer)
+       return DotProduct(p, normal) > DotProduct(a, normal);
+}
 int checkcastshadowfromedge(int t, int i)
 {
        int *te;