29 #include "../precompiled.h"
39 if ( patchWidth < 1 || patchWidth >
maxWidth ) {
42 if ( patchHeight < 1 || patchHeight >
maxHeight ) {
63 for ( i = 0; i <
width; i++ ) {
64 for ( j = 1; j <
height; j += 2 ) {
71 for ( j = 0; j <
height; j++ ) {
72 for ( i = 1; i <
width; i += 2 ) {
88 pVec = point - vStart;
92 vProj = vStart + (pVec * vec) * vec;
108 for ( j = 1; j <
width - 1; j++ ) {
110 for ( i = 0; i <
height; i++ ) {
115 if ( len > maxLength ) {
119 if ( maxLength <
Square( 0.2
f ) ) {
121 for ( i = 0; i <
height; i++ ) {
122 for ( k = j; k <
width; k++ ) {
129 for ( j = 1; j <
height - 1; j++ ) {
131 for ( i = 0; i <
width; i++ ) {
136 if ( len > maxLength ) {
140 if ( maxLength <
Square( 0.2
f ) ) {
142 for ( i = 0; i <
width; i++ ) {
143 for ( k = j; k <
height; k++ ) {
169 for ( i = maxWidth-1; i >= 0; i-- ) {
190 for ( j = 0; j <
height; j++ ) {
191 for ( i = 0; i <
width; i++ ) {
213 for ( j =
height-1; j >= 0; j-- ) {
214 for ( i =
width-1; i >= 0; i-- ) {
227 out.
xyz[0] = 0.5f * ( a.
xyz[0] + b.
xyz[0] );
228 out.
xyz[1] = 0.5f * ( a.
xyz[1] + b.
xyz[1] );
229 out.
xyz[2] = 0.5f * ( a.
xyz[2] + b.
xyz[2] );
233 out.
st[0] = 0.5f * ( a.
st[0] + b.
st[0] );
234 out.
st[1] = 0.5f * ( a.
st[1] + b.
st[1] );
245 #define COPLANAR_EPSILON 0.1f
257 bool wrapWidth, wrapHeight;
258 static int neighbors[8][2] = {
259 {0,1}, {1,1}, {1,0}, {1,-1}, {0,-1}, {-1,-1}, {-1,0}, {-1,1}
274 norm = extent[0].
Cross( extent[1] );
275 if ( norm.LengthSqr() == 0.0f ) {
276 norm = extent[0].
Cross( extent[2] );
277 if ( norm.LengthSqr() == 0.0f ) {
278 norm = extent[1].
Cross( extent[2] );
283 if ( norm.Normalize() != 0.0f ) {
285 offset =
verts[0].xyz * norm;
287 float d =
verts[
i].xyz * norm;
293 if ( i ==
width * height ) {
304 for ( i = 0; i <
height; i++ ) {
315 for ( i = 0; i <
width; i++ ) {
316 delta =
verts[
i].xyz -
verts[(height-1) * width + i].xyz;
325 for ( i = 0; i <
width; i++ ) {
326 for ( j = 0; j <
height; j++ ) {
328 base =
verts[j * width +
i].xyz;
329 for ( k = 0; k < 8; k++ ) {
333 for ( dist = 1; dist <= 3; dist++ ) {
334 x = i + neighbors[k][0] * dist;
335 y = j + neighbors[k][1] * dist;
339 }
else if ( x >= width ) {
346 }
else if ( y >= height ) {
354 temp =
verts[y * width +
x].xyz - base;
366 for ( k = 0; k < 8; k++ ) {
367 if ( !good[k] || !good[(k+1)&7] ) {
370 norm = around[(k+1)&7].Cross( around[k] );
371 if ( norm.Normalize() == 0.0f ) {
381 verts[j * width +
i].normal = sum;
382 verts[j * width +
i].normal.Normalize();
397 for ( i = 0; i <
width - 1; i++ ) {
398 for ( j = 0; j <
height - 1; j++ ) {
426 for ( vPoint = 0; vPoint < 3; vPoint++ ) {
427 for ( axis = 0; axis < 8; axis++ ) {
431 a = ctrl[0][vPoint].
xyz[axis];
432 b = ctrl[1][vPoint].
xyz[axis];
433 c = ctrl[2][vPoint].
xyz[axis];
434 }
else if ( axis < 6 ) {
435 a = ctrl[0][vPoint].
normal[axis-3];
436 b = ctrl[1][vPoint].
normal[axis-3];
437 c = ctrl[2][vPoint].
normal[axis-3];
439 a = ctrl[0][vPoint].
st[axis-6];
440 b = ctrl[1][vPoint].
st[axis-6];
441 c = ctrl[2][vPoint].
st[axis-6];
443 qA = a - 2.0f * b +
c;
444 qB = 2.0f * b - 2.0f *
a;
446 vCtrl[vPoint][axis] = qA * u * u + qB * u + qC;
451 for ( axis = 0; axis < 8; axis++ ) {
458 qA = a - 2.0f * b +
c;
459 qB = 2.0f * b - 2.0f *
a;
463 out->
xyz[axis] = qA * v * v + qB * v + qC;
464 }
else if ( axis < 6 ) {
465 out->
normal[axis-3] = qA * v * v + qB * v + qC;
467 out->
st[axis-6] = qA * v * v + qB * v + qC;
483 for ( i = 0; i < horzSub; i++ ) {
484 for ( j = 0; j < vertSub; j++ ) {
485 u = (
float) i / ( horzSub - 1 );
486 v = (
float) j / ( vertSub - 1 );
500 int outWidth = ((
width - 1) / 2 * horzSubdivisions) + 1;
501 int outHeight = ((
height - 1) / 2 * vertSubdivisions) + 1;
510 for ( i = 0; i + 2 <
width; i += 2 ) {
512 for ( j = 0; j + 2 <
height; j += 2 ) {
513 for ( k = 0; k < 3; k++ ) {
514 for ( l = 0; l < 3; l++ ) {
515 sample[k][
l] =
verts[ ((j +
l) * width) + i + k ];
518 SampleSinglePatch( sample, baseCol, baseRow, outWidth, horzSubdivisions, vertSubdivisions, dv );
519 baseRow += vertSubdivisions;
521 baseCol += horzSubdivisions;
524 for ( i = 0; i < outWidth * outHeight; i++ ) {
534 if ( removeLinear ) {
542 for ( i = 0; i < width *
height; i++ ) {
543 verts[
i].normal.Normalize();
558 idVec3 prevxyz, nextxyz, midxyz;
560 float maxHorizontalErrorSqr, maxVerticalErrorSqr, maxLengthSqr;
567 maxHorizontalErrorSqr =
Square( maxHorizontalError );
568 maxVerticalErrorSqr =
Square( maxVerticalError );
569 maxLengthSqr =
Square( maxLength );
574 for ( j = 0; j + 2 <
width; j += 2 ) {
576 for ( i = 0; i <
height; i++ ) {
577 for ( l = 0; l < 3; l++ ) {
584 if ( maxLength > 0.0
f ) {
592 if ( delta.
LengthSqr() > maxHorizontalErrorSqr ) {
608 for ( i = 0; i <
height; i++ ) {
613 for ( k = width - 1; k > j + 3; k-- ) {
626 for ( j = 0; j + 2 <
height; j += 2 ) {
628 for ( i = 0; i <
width; i++ ) {
629 for ( l = 0; l < 3; l++ ) {
636 if ( maxLength > 0.0
f ) {
644 if ( delta.
LengthSqr() > maxVerticalErrorSqr ) {
660 for ( i = 0; i <
width; i++ ) {
665 for ( k = height - 1; k > j + 3; k-- ) {
685 for ( i = 0; i < width *
height; i++ ) {
686 verts[
i].normal.Normalize();
idList< idDrawVert > verts
assert(prefInfo.fullscreenBtn)
void ResizeExpanded(int height, int width)
void SetNum(int newnum, bool resize=true)
idVec3 Cross(const idVec3 &a) const
void LerpVert(const idDrawVert &a, const idDrawVert &b, idDrawVert &out) const
void SubdivideExplicit(int horzSubdivisions, int vertSubdivisions, bool genNormals, bool removeLinear=false)
GLfloat GLfloat GLfloat v2
GLuint GLuint GLsizei count
void Subdivide(float maxHorizontalError, float maxVerticalError, float maxLength, bool genNormals=false)
idVec3 vec3_origin(0.0f, 0.0f, 0.0f)
static float Fabs(float f)
void GenerateIndexes(void)
void GenerateNormals(void)
virtual void virtual void FatalError(const char *fmt,...) id_attribute((format(printf
void RemoveLinearColumnsRows(void)
float LengthSqr(void) const
GLubyte GLubyte GLubyte a
GLenum GLsizei GLsizei height
GLfloat GLfloat GLfloat GLfloat v3
void GenerateEdgeIndexes(void)
void ProjectPointOntoVector(const idVec3 &point, const idVec3 &vStart, const idVec3 &vEnd, idVec3 &vProj)
void SampleSinglePatchPoint(const idDrawVert ctrl[3][3], float u, float v, idDrawVert *out) const
void SetSize(int patchWidth, int patchHeight)
void SampleSinglePatch(const idDrawVert ctrl[3][3], int baseCol, int baseRow, int width, int horzSub, int vertSub, idDrawVert *outVerts) const
static class idCommon * common