]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - curves.c
use dynamic eye position-centered bouncegrid when rendering in dynamic
[xonotic/darkplaces.git] / curves.c
index 910201ad791444b8ce77e503df6026a39e193be2..17d1b9424d0c24c97f2610f180190875d9e2b3f2 100644 (file)
--- a/curves.c
+++ b/curves.c
@@ -140,14 +140,14 @@ static int Q3PatchTesselation(float largestsquared3xcurvearea, float tolerance)
 {
        float f;
        // f is actually a squared 2x curve area... so the formula had to be adjusted to give roughly the same subdivisions
-       f = pow(largestsquared3xcurvearea / 64.0, 0.25) / tolerance;
+       f = pow(largestsquared3xcurvearea / 64.0f, 0.25f) / tolerance;
        //if(f < 0.25) // VERY flat patches
        if(f < 0.0001) // TOTALLY flat patches
                return 0;
        else if(f < 2)
                return 1;
        else
-               return (int) floor(log(f) / log(2)) + 1;
+               return (int) floor(log(f) / log(2.0f)) + 1;
                // this is always at least 2
                // maps [0.25..0.5[ to -1 (actually, 1 is returned)
                // maps [0.5..1[ to 0 (actually, 1 is returned)
@@ -336,7 +336,7 @@ int Q3PatchAdjustTesselation(int numcomponents, patchinfo_t *patch1, float *patc
 
        struct {int id1,id2;} commonverts[8];
        int i, j, k, side1, side2, *tess1, *tess2;
-       int dist1, dist2;
+       int dist1 = 0, dist2 = 0;
        qboolean modified = false;
 
        // Potential paired vertices (corners of the first patch)
@@ -402,18 +402,38 @@ void Q3PatchTriangleElements(int *elements, int width, int height, int firstvert
        int x, y, row0, row1;
        for (y = 0;y < height - 1;y++)
        {
-               row0 = firstvertex + (y + 0) * width;
-               row1 = firstvertex + (y + 1) * width;
-               for (x = 0;x < width - 1;x++)
+               if(y % 2)
                {
-                       *elements++ = row0;
-                       *elements++ = row1;
-                       *elements++ = row0 + 1;
-                       *elements++ = row1;
-                       *elements++ = row1 + 1;
-                       *elements++ = row0 + 1;
-                       row0++;
-                       row1++;
+                       // swap the triangle order in odd rows as optimization for collision stride
+                       row0 = firstvertex + (y + 0) * width + width - 2;
+                       row1 = firstvertex + (y + 1) * width + width - 2;
+                       for (x = 0;x < width - 1;x++)
+                       {
+                               *elements++ = row1;
+                               *elements++ = row1 + 1;
+                               *elements++ = row0 + 1;
+                               *elements++ = row0;
+                               *elements++ = row1;
+                               *elements++ = row0 + 1;
+                               row0--;
+                               row1--;
+                       }
+               }
+               else
+               {
+                       row0 = firstvertex + (y + 0) * width;
+                       row1 = firstvertex + (y + 1) * width;
+                       for (x = 0;x < width - 1;x++)
+                       {
+                               *elements++ = row0;
+                               *elements++ = row1;
+                               *elements++ = row0 + 1;
+                               *elements++ = row1;
+                               *elements++ = row1 + 1;
+                               *elements++ = row0 + 1;
+                               row0++;
+                               row1++;
+                       }
                }
        }
 }