X-Git-Url: http://git.xonotic.org/?p=xonotic%2Fdarkplaces.git;a=blobdiff_plain;f=curves.c;h=1d9b2941934ebcc0ecb947f6dfce267a01dd3654;hp=ad5bb63f74f51f50c9e92d025c19d90b48c571be;hb=2b065b3efdf9a5aced95aa93aed4db1caf8191bb;hpb=b2987354f10ef5e5f495b9b9b36849749bcebec0 diff --git a/curves.c b/curves.c index ad5bb63f..1d9b2941 100644 --- a/curves.c +++ b/curves.c @@ -1,6 +1,5 @@ - /* -this code written by Forest Hale, on 2004-10-17, and placed into public domain +this code written by Ashley Rose Hale (LadyHavoc), on 2004-10-17, and placed into public domain this implements Quadratic BSpline surfaces as seen in Quake3 by id Software a small rant on misuse of the name 'bezier': many people seem to think that @@ -136,18 +135,18 @@ void Q3PatchTesselateFloat(int numcomponents, int outputstride, float *outputver #endif } -static int Q3PatchTesselation(float largestsquared2xcurvearea, float tolerance) +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(largestsquared2xcurvearea / 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) @@ -156,7 +155,7 @@ static int Q3PatchTesselation(float largestsquared2xcurvearea, float tolerance) // maps [4..8[ to 4 } -float Squared3xCurveArea(const float *a, const float *control, const float *b, int components) +static float Squared3xCurveArea(const float *a, const float *control, const float *b, int components) { #if 0 // mimicing the old behaviour with the new code... @@ -234,19 +233,19 @@ int Q3PatchTesselationOnX(int patchwidth, int patchheight, int components, const { int x, y; const float *patch; - float squared2xcurvearea, largestsquared2xcurvearea; - largestsquared2xcurvearea = 0; + float squared3xcurvearea, largestsquared3xcurvearea; + largestsquared3xcurvearea = 0; for (y = 0;y < patchheight;y++) { for (x = 0;x < patchwidth-1;x += 2) { patch = in + ((y * patchwidth) + x) * components; - squared2xcurvearea = Squared3xCurveArea(&patch[0], &patch[components], &patch[2*components], components); - if (largestsquared2xcurvearea < squared2xcurvearea) - largestsquared2xcurvearea = squared2xcurvearea; + squared3xcurvearea = Squared3xCurveArea(&patch[0], &patch[components], &patch[2*components], components); + if (largestsquared3xcurvearea < squared3xcurvearea) + largestsquared3xcurvearea = squared3xcurvearea; } } - return Q3PatchTesselation(largestsquared2xcurvearea, tolerance); + return Q3PatchTesselation(largestsquared3xcurvearea, tolerance); } // returns how much tesselation of each segment is needed to remain under tolerance @@ -254,19 +253,19 @@ int Q3PatchTesselationOnY(int patchwidth, int patchheight, int components, const { int x, y; const float *patch; - float squared2xcurvearea, largestsquared2xcurvearea; - largestsquared2xcurvearea = 0; + float squared3xcurvearea, largestsquared3xcurvearea; + largestsquared3xcurvearea = 0; for (y = 0;y < patchheight-1;y += 2) { for (x = 0;x < patchwidth;x++) { patch = in + ((y * patchwidth) + x) * components; - squared2xcurvearea = Squared3xCurveArea(&patch[0], &patch[patchwidth*components], &patch[2*patchwidth*components], components); - if (largestsquared2xcurvearea < squared2xcurvearea) - largestsquared2xcurvearea = squared2xcurvearea; + squared3xcurvearea = Squared3xCurveArea(&patch[0], &patch[patchwidth*components], &patch[2*patchwidth*components], components); + if (largestsquared3xcurvearea < squared3xcurvearea) + largestsquared3xcurvearea = squared3xcurvearea; } } - return Q3PatchTesselation(largestsquared2xcurvearea, tolerance); + return Q3PatchTesselation(largestsquared3xcurvearea, tolerance); } // Find an equal vertex in array. Check only vertices with odd X and Y @@ -277,7 +276,7 @@ static int FindEqualOddVertexInArray(int numcomponents, float *vertex, float *ve { for (x=0; x 0.05) // div0: this is notably smaller than the smallest radiant grid @@ -336,8 +335,8 @@ 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; - qboolean modified = false; + int dist1 = 0, dist2 = 0; + qbool modified = false; // Potential paired vertices (corners of the first patch) commonverts[0].id1 = 0; @@ -402,18 +401,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) + { + // 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 { - *elements++ = row0; - *elements++ = row1; - *elements++ = row0 + 1; - *elements++ = row1; - *elements++ = row1 + 1; - *elements++ = row0 + 1; - row0++; - row1++; + 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++; + } } } }