DarkPlaces
Game engine based on the Quake 1 engine by id Software, developed by LadyHavoc
 
curves.h File Reference
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  patchinfo_t
 

Macros

#define PATCH_LOD_COLLISION   0
 
#define PATCH_LOD_VISUAL   1
 
#define PATCH_LODS_NUM   2
 

Functions

int Q3PatchAdjustTesselation (int numcomponents, patchinfo_t *patch1, float *patchvertices1, patchinfo_t *patch2, float *patchvertices2)
 
int Q3PatchDimForTess (int size, int tess)
 
void Q3PatchTesselateFloat (int numcomponents, int outputstride, float *outputvertices, int patchwidth, int patchheight, int inputstride, float *patchvertices, int tesselationwidth, int tesselationheight)
 
int Q3PatchTesselationOnX (int patchwidth, int patchheight, int components, const float *in, float tolerance)
 
int Q3PatchTesselationOnY (int patchwidth, int patchheight, int components, const float *in, float tolerance)
 
void Q3PatchTriangleElements (int *elements, int width, int height, int firstvertex)
 

Macro Definition Documentation

◆ PATCH_LOD_COLLISION

#define PATCH_LOD_COLLISION   0

Definition at line 5 of file curves.h.

Referenced by Mod_Q3BSP_LoadFaces().

◆ PATCH_LOD_VISUAL

#define PATCH_LOD_VISUAL   1

Definition at line 6 of file curves.h.

Referenced by Mod_Q3BSP_LoadFaces().

◆ PATCH_LODS_NUM

#define PATCH_LODS_NUM   2

Definition at line 4 of file curves.h.

Referenced by Q3PatchAdjustTesselation().

Function Documentation

◆ Q3PatchAdjustTesselation()

int Q3PatchAdjustTesselation ( int numcomponents,
patchinfo_t * patch1,
float * patchvertices1,
patchinfo_t * patch2,
float * patchvertices2 )

Definition at line 329 of file curves.c.

330{
331 // what we are doing here is:
332 // we take for each corner of one patch
333 // and check if the other patch contains that corner
334 // once we have a pair of such matches
335
336 struct {int id1,id2;} commonverts[8];
337 int i, j, k, side1, side2, *tess1, *tess2;
338 int dist1 = 0, dist2 = 0;
339 qbool modified = false;
340
341 // Potential paired vertices (corners of the first patch)
342 commonverts[0].id1 = 0;
343 commonverts[1].id1 = patch1->xsize-1;
344 commonverts[2].id1 = patch1->xsize*(patch1->ysize-1);
345 commonverts[3].id1 = patch1->xsize*patch1->ysize-1;
346 for (i=0;i<4;++i)
347 commonverts[i].id2 = FindEqualOddVertexInArray(numcomponents, patchvertices1+numcomponents*commonverts[i].id1, patchvertices2, patch2->xsize, patch2->ysize);
348
349 // Corners of the second patch
350 commonverts[4].id2 = 0;
351 commonverts[5].id2 = patch2->xsize-1;
352 commonverts[6].id2 = patch2->xsize*(patch2->ysize-1);
353 commonverts[7].id2 = patch2->xsize*patch2->ysize-1;
354 for (i=4;i<8;++i)
355 commonverts[i].id1 = FindEqualOddVertexInArray(numcomponents, patchvertices2+numcomponents*commonverts[i].id2, patchvertices1, patch1->xsize, patch1->ysize);
356
357 for (i=0;i<8;++i)
358 for (j=i+1;j<8;++j)
359 {
360 side1 = GetSide(commonverts[i].id1,commonverts[j].id1,patch1->xsize,patch1->ysize,&dist1);
361 side2 = GetSide(commonverts[i].id2,commonverts[j].id2,patch2->xsize,patch2->ysize,&dist2);
362
363 if (side1 == SIDE_INVALID || side2 == SIDE_INVALID)
364 continue;
365
366 if(dist1 != dist2)
367 {
368 // no patch welding if the resolutions mismatch
369 continue;
370 }
371
372 // Update every lod level
373 for (k=0;k<PATCH_LODS_NUM;++k)
374 {
375 tess1 = side1 == SIDE_X ? &patch1->lods[k].xtess : &patch1->lods[k].ytess;
376 tess2 = side2 == SIDE_X ? &patch2->lods[k].xtess : &patch2->lods[k].ytess;
377 if (*tess1 != *tess2)
378 {
379 if (*tess1 < *tess2)
380 *tess1 = *tess2;
381 else
382 *tess2 = *tess1;
383 modified = true;
384 }
385 }
386 }
387
388 return modified;
389}
static int FindEqualOddVertexInArray(int numcomponents, float *vertex, float *vertices, int width, int height)
Definition curves.c:272
#define SIDE_INVALID
Definition curves.c:298
#define SIDE_X
Definition curves.c:299
static int GetSide(int p1, int p2, int width, int height, int *pointdist)
Definition curves.c:302
#define PATCH_LODS_NUM
Definition curves.h:4
int i
bool qbool
Definition qtypes.h:9
struct patchinfo_t::@10 lods[PATCH_LODS_NUM]
int ytess
Definition curves.h:12
int xtess
Definition curves.h:12
int xsize
Definition curves.h:10
int ysize
Definition curves.h:10

References FindEqualOddVertexInArray(), GetSide(), i, patchinfo_t::lods, PATCH_LODS_NUM, SIDE_INVALID, SIDE_X, patchinfo_t::xsize, patchinfo_t::xtess, patchinfo_t::ysize, and patchinfo_t::ytess.

Referenced by Mod_Q3BSP_LoadFaces().

◆ Q3PatchDimForTess()

int Q3PatchDimForTess ( int size,
int tess )

Definition at line 51 of file curves.c.

52{
53 if (tess > 0)
54 return (size - 1) * tess + 1;
55 else if (tess == 0)
56 return (size - 1) / 2 + 1;
57 else
58 return 0; // Maybe warn about wrong tess here?
59}
vector size

References size.

Referenced by Mod_Q3BSP_LoadFaces(), and Q3PatchTesselateFloat().

◆ Q3PatchTesselateFloat()

void Q3PatchTesselateFloat ( int numcomponents,
int outputstride,
float * outputvertices,
int patchwidth,
int patchheight,
int inputstride,
float * patchvertices,
int tesselationwidth,
int tesselationheight )

Definition at line 64 of file curves.c.

65{
66 int k, l, x, y, component, outputwidth = Q3PatchDimForTess(patchwidth, tesselationwidth);
67 float px, py, *v, a, b, c, *cp[3][3], temp[3][64];
68 int xmax = max(1, 2*tesselationwidth);
69 int ymax = max(1, 2*tesselationheight);
70
71 // iterate over the individual 3x3 quadratic spline surfaces one at a time
72 // expanding them to fill the output array (with some overlap to ensure
73 // the edges are filled)
74 for (k = 0;k < patchheight-1;k += 2)
75 {
76 for (l = 0;l < patchwidth-1;l += 2)
77 {
78 // set up control point pointers for quicker lookup later
79 for (y = 0;y < 3;y++)
80 for (x = 0;x < 3;x++)
81 cp[y][x] = (float *)((unsigned char *)patchvertices + ((k+y)*patchwidth+(l+x)) * inputstride);
82 // for each row...
83 for (y = 0;y <= ymax;y++)
84 {
85 // calculate control points for this row by collapsing the 3
86 // rows of control points to one row using py
87 py = (float)y / (float)ymax;
88 // calculate quadratic spline weights for py
89 a = ((1.0f - py) * (1.0f - py));
90 b = ((1.0f - py) * (2.0f * py));
91 c = (( py) * ( py));
92 for (component = 0;component < numcomponents;component++)
93 {
94 temp[0][component] = cp[0][0][component] * a + cp[1][0][component] * b + cp[2][0][component] * c;
95 temp[1][component] = cp[0][1][component] * a + cp[1][1][component] * b + cp[2][1][component] * c;
96 temp[2][component] = cp[0][2][component] * a + cp[1][2][component] * b + cp[2][2][component] * c;
97 }
98 // fetch a pointer to the beginning of the output vertex row
99 v = (float *)((unsigned char *)outputvertices + ((k * ymax / 2 + y) * outputwidth + l * xmax / 2) * outputstride);
100 // for each column of the row...
101 for (x = 0;x <= xmax;x++)
102 {
103 // calculate point based on the row control points
104 px = (float)x / (float)xmax;
105 // calculate quadratic spline weights for px
106 // (could be precalculated)
107 a = ((1.0f - px) * (1.0f - px));
108 b = ((1.0f - px) * (2.0f * px));
109 c = (( px) * ( px));
110 for (component = 0;component < numcomponents;component++)
111 v[component] = temp[0][component] * a + temp[1][component] * b + temp[2][component] * c;
112 // advance to next output vertex using outputstride
113 // (the next vertex may not be directly following this
114 // one, as this may be part of a larger structure)
115 v = (float *)((unsigned char *)v + outputstride);
116 }
117 }
118 }
119 }
120#if 0
121 // enable this if you want results printed out
122 printf("vertices[%i][%i] =\n{\n", (patchheight-1)*tesselationheight+1, (patchwidth-1)*tesselationwidth+1);
123 for (y = 0;y < (patchheight-1)*tesselationheight+1;y++)
124 {
125 for (x = 0;x < (patchwidth-1)*tesselationwidth+1;x++)
126 {
127 printf("(");
128 for (component = 0;component < numcomponents;component++)
129 printf("%f ", outputvertices[(y*((patchwidth-1)*tesselationwidth+1)+x)*numcomponents+component]);
130 printf(") ");
131 }
132 printf("\n");
133 }
134 printf("}\n");
135#endif
136}
int Q3PatchDimForTess(int size, int tess)
Definition curves.c:51
const GLdouble * v
Definition glquake.h:762
GLint GLenum GLint GLint y
Definition glquake.h:651
GLint GLenum GLint x
Definition glquake.h:651
#define max(A, B)
Definition mathlib.h:38
precision highp float
Definition shader_glsl.h:53
dp_FragColor b
ret a
vec2 px

References a, b, float, max, px, Q3PatchDimForTess(), v, x, and y.

Referenced by Mod_Q3BSP_LoadFaces().

◆ Q3PatchTesselationOnX()

int Q3PatchTesselationOnX ( int patchwidth,
int patchheight,
int components,
const float * in,
float tolerance )

Definition at line 232 of file curves.c.

233{
234 int x, y;
235 const float *patch;
236 float squared3xcurvearea, largestsquared3xcurvearea;
237 largestsquared3xcurvearea = 0;
238 for (y = 0;y < patchheight;y++)
239 {
240 for (x = 0;x < patchwidth-1;x += 2)
241 {
242 patch = in + ((y * patchwidth) + x) * components;
243 squared3xcurvearea = Squared3xCurveArea(&patch[0], &patch[components], &patch[2*components], components);
244 if (largestsquared3xcurvearea < squared3xcurvearea)
245 largestsquared3xcurvearea = squared3xcurvearea;
246 }
247 }
248 return Q3PatchTesselation(largestsquared3xcurvearea, tolerance);
249}
static float Squared3xCurveArea(const float *a, const float *control, const float *b, int components)
Definition curves.c:158
static int Q3PatchTesselation(float largestsquared3xcurvearea, float tolerance)
Definition curves.c:138

References Q3PatchTesselation(), Squared3xCurveArea(), x, and y.

Referenced by Mod_Q3BSP_LoadFaces().

◆ Q3PatchTesselationOnY()

int Q3PatchTesselationOnY ( int patchwidth,
int patchheight,
int components,
const float * in,
float tolerance )

Definition at line 252 of file curves.c.

253{
254 int x, y;
255 const float *patch;
256 float squared3xcurvearea, largestsquared3xcurvearea;
257 largestsquared3xcurvearea = 0;
258 for (y = 0;y < patchheight-1;y += 2)
259 {
260 for (x = 0;x < patchwidth;x++)
261 {
262 patch = in + ((y * patchwidth) + x) * components;
263 squared3xcurvearea = Squared3xCurveArea(&patch[0], &patch[patchwidth*components], &patch[2*patchwidth*components], components);
264 if (largestsquared3xcurvearea < squared3xcurvearea)
265 largestsquared3xcurvearea = squared3xcurvearea;
266 }
267 }
268 return Q3PatchTesselation(largestsquared3xcurvearea, tolerance);
269}

References Q3PatchTesselation(), Squared3xCurveArea(), x, and y.

Referenced by Mod_Q3BSP_LoadFaces().

◆ Q3PatchTriangleElements()

void Q3PatchTriangleElements ( int * elements,
int width,
int height,
int firstvertex )

Definition at line 399 of file curves.c.

400{
401 int x, y, row0, row1;
402 for (y = 0;y < height - 1;y++)
403 {
404 if(y % 2)
405 {
406 // swap the triangle order in odd rows as optimization for collision stride
407 row0 = firstvertex + (y + 0) * width + width - 2;
408 row1 = firstvertex + (y + 1) * width + width - 2;
409 for (x = 0;x < width - 1;x++)
410 {
411 *elements++ = row1;
412 *elements++ = row1 + 1;
413 *elements++ = row0 + 1;
414 *elements++ = row0;
415 *elements++ = row1;
416 *elements++ = row0 + 1;
417 row0--;
418 row1--;
419 }
420 }
421 else
422 {
423 row0 = firstvertex + (y + 0) * width;
424 row1 = firstvertex + (y + 1) * width;
425 for (x = 0;x < width - 1;x++)
426 {
427 *elements++ = row0;
428 *elements++ = row1;
429 *elements++ = row0 + 1;
430 *elements++ = row1;
431 *elements++ = row1 + 1;
432 *elements++ = row0 + 1;
433 row0++;
434 row1++;
435 }
436 }
437 }
438}
GLenum GLsizei width
Definition glquake.h:622
GLenum GLsizei GLsizei height
Definition glquake.h:622

References height, width, x, and y.

Referenced by Mod_Q3BSP_LoadFaces().