| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
#include "tr_local.h" |
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
static void LerpDrawVert( srfVert_t *a, srfVert_t *b, srfVert_t *out ) { |
| 47 |
out->xyz[0] = 0.5f * (a->xyz[0] + b->xyz[0]); |
| 48 |
out->xyz[1] = 0.5f * (a->xyz[1] + b->xyz[1]); |
| 49 |
out->xyz[2] = 0.5f * (a->xyz[2] + b->xyz[2]); |
| 50 |
|
| 51 |
out->st[0] = 0.5f * (a->st[0] + b->st[0]); |
| 52 |
out->st[1] = 0.5f * (a->st[1] + b->st[1]); |
| 53 |
|
| 54 |
out->lightmap[0] = 0.5f * (a->lightmap[0] + b->lightmap[0]); |
| 55 |
out->lightmap[1] = 0.5f * (a->lightmap[1] + b->lightmap[1]); |
| 56 |
|
| 57 |
out->color[0] = ((int)a->color[0] + (int)b->color[0]) >> 1; |
| 58 |
out->color[1] = ((int)a->color[1] + (int)b->color[1]) >> 1; |
| 59 |
out->color[2] = ((int)a->color[2] + (int)b->color[2]) >> 1; |
| 60 |
out->color[3] = ((int)a->color[3] + (int)b->color[3]) >> 1; |
| 61 |
} |
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
static void Transpose( int width, int height, srfVert_t ctrl[MAX_GRID_SIZE][MAX_GRID_SIZE] ) { |
| 69 |
int i, j; |
| 70 |
srfVert_t temp; |
| 71 |
|
| 72 |
if ( width > height ) { |
| 73 |
for ( i = 0 ; i < height ; i++ ) { |
| 74 |
for ( j = i + 1 ; j < width ; j++ ) { |
| 75 |
if ( j < height ) { |
| 76 |
|
| 77 |
temp = ctrl[j][i]; |
| 78 |
ctrl[j][i] = ctrl[i][j]; |
| 79 |
ctrl[i][j] = temp; |
| 80 |
} else { |
| 81 |
|
| 82 |
ctrl[j][i] = ctrl[i][j]; |
| 83 |
} |
| 84 |
} |
| 85 |
} |
| 86 |
} else { |
| 87 |
for ( i = 0 ; i < width ; i++ ) { |
| 88 |
for ( j = i + 1 ; j < height ; j++ ) { |
| 89 |
if ( j < width ) { |
| 90 |
|
| 91 |
temp = ctrl[i][j]; |
| 92 |
ctrl[i][j] = ctrl[j][i]; |
| 93 |
ctrl[j][i] = temp; |
| 94 |
} else { |
| 95 |
|
| 96 |
ctrl[i][j] = ctrl[j][i]; |
| 97 |
} |
| 98 |
} |
| 99 |
} |
| 100 |
} |
| 101 |
|
| 102 |
} |
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
static void MakeMeshNormals( int width, int height, srfVert_t ctrl[MAX_GRID_SIZE][MAX_GRID_SIZE] ) { |
| 113 |
int i, j, k, dist; |
| 114 |
vec3_t normal; |
| 115 |
vec3_t sum; |
| 116 |
vec3_t base; |
| 117 |
vec3_t delta; |
| 118 |
int x, y; |
| 119 |
srfVert_t *dv; |
| 120 |
vec3_t around[8], temp; |
| 121 |
qboolean good[8]; |
| 122 |
qboolean wrapWidth, wrapHeight; |
| 123 |
float len; |
| 124 |
static int neighbors[8][2] = { |
| 125 |
{0,1}, {1,1}, {1,0}, {1,-1}, {0,-1}, {-1,-1}, {-1,0}, {-1,1} |
| 126 |
}; |
| 127 |
|
| 128 |
wrapWidth = qfalse; |
| 129 |
for ( i = 0 ; i < height ; i++ ) { |
| 130 |
VectorSubtract( ctrl[i][0].xyz, ctrl[i][width-1].xyz, delta ); |
| 131 |
len = VectorLengthSquared( delta ); |
| 132 |
if ( len > 1.0 ) { |
| 133 |
break; |
| 134 |
} |
| 135 |
} |
| 136 |
if ( i == height ) { |
| 137 |
wrapWidth = qtrue; |
| 138 |
} |
| 139 |
|
| 140 |
wrapHeight = qfalse; |
| 141 |
for ( i = 0 ; i < width ; i++ ) { |
| 142 |
VectorSubtract( ctrl[0][i].xyz, ctrl[height-1][i].xyz, delta ); |
| 143 |
len = VectorLengthSquared( delta ); |
| 144 |
if ( len > 1.0 ) { |
| 145 |
break; |
| 146 |
} |
| 147 |
} |
| 148 |
if ( i == width) { |
| 149 |
wrapHeight = qtrue; |
| 150 |
} |
| 151 |
|
| 152 |
|
| 153 |
for ( i = 0 ; i < width ; i++ ) { |
| 154 |
for ( j = 0 ; j < height ; j++ ) { |
| 155 |
dv = &ctrl[j][i]; |
| 156 |
VectorCopy( dv->xyz, base ); |
| 157 |
for ( k = 0 ; k < 8 ; k++ ) { |
| 158 |
VectorClear( around[k] ); |
| 159 |
good[k] = qfalse; |
| 160 |
|
| 161 |
for ( dist = 1 ; dist <= 3 ; dist++ ) { |
| 162 |
x = i + neighbors[k][0] * dist; |
| 163 |
y = j + neighbors[k][1] * dist; |
| 164 |
if ( wrapWidth ) { |
| 165 |
if ( x < 0 ) { |
| 166 |
x = width - 1 + x; |
| 167 |
} else if ( x >= width ) { |
| 168 |
x = 1 + x - width; |
| 169 |
} |
| 170 |
} |
| 171 |
if ( wrapHeight ) { |
| 172 |
if ( y < 0 ) { |
| 173 |
y = height - 1 + y; |
| 174 |
} else if ( y >= height ) { |
| 175 |
y = 1 + y - height; |
| 176 |
} |
| 177 |
} |
| 178 |
|
| 179 |
if ( x < 0 || x >= width || y < 0 || y >= height ) { |
| 180 |
break; |
| 181 |
} |
| 182 |
VectorSubtract( ctrl[y][x].xyz, base, temp ); |
| 183 |
if ( VectorNormalize( temp ) < 0.001f ) { |
| 184 |
continue; |
| 185 |
} else { |
| 186 |
good[k] = qtrue; |
| 187 |
VectorCopy( temp, around[k] ); |
| 188 |
break; |
| 189 |
} |
| 190 |
} |
| 191 |
} |
| 192 |
|
| 193 |
VectorClear( sum ); |
| 194 |
for ( k = 0 ; k < 8 ; k++ ) { |
| 195 |
if ( !good[k] || !good[(k+1)&7] ) { |
| 196 |
continue; |
| 197 |
} |
| 198 |
CrossProduct( around[(k+1)&7], around[k], normal ); |
| 199 |
if ( VectorNormalize( normal ) < 0.001f ) { |
| 200 |
continue; |
| 201 |
} |
| 202 |
VectorAdd( normal, sum, sum ); |
| 203 |
} |
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
{ |
| 208 |
vec3_t fNormal; |
| 209 |
VectorNormalize2(sum, fNormal); |
| 210 |
R_VaoPackNormal(dv->normal, fNormal); |
| 211 |
} |
| 212 |
} |
| 213 |
} |
| 214 |
} |
| 215 |
|
| 216 |
static void MakeMeshTangentVectors(int width, int height, srfVert_t ctrl[MAX_GRID_SIZE][MAX_GRID_SIZE], int numIndexes, |
| 217 |
glIndex_t indexes[(MAX_GRID_SIZE-1)*(MAX_GRID_SIZE-1)*2*3]) |
| 218 |
{ |
| 219 |
int i, j; |
| 220 |
srfVert_t *dv[3]; |
| 221 |
static srfVert_t ctrl2[MAX_GRID_SIZE * MAX_GRID_SIZE]; |
| 222 |
glIndex_t *tri; |
| 223 |
|
| 224 |
|
| 225 |
for(i = 0; i < width; i++) |
| 226 |
{ |
| 227 |
for(j = 0; j < height; j++) |
| 228 |
{ |
| 229 |
dv[0] = &ctrl2[j * width + i]; |
| 230 |
*dv[0] = ctrl[j][i]; |
| 231 |
} |
| 232 |
} |
| 233 |
|
| 234 |
for(i = 0, tri = indexes; i < numIndexes; i += 3, tri += 3) |
| 235 |
{ |
| 236 |
dv[0] = &ctrl2[tri[0]]; |
| 237 |
dv[1] = &ctrl2[tri[1]]; |
| 238 |
dv[2] = &ctrl2[tri[2]]; |
| 239 |
|
| 240 |
R_CalcTangentVectors(dv); |
| 241 |
} |
| 242 |
|
| 243 |
for(i = 0; i < width; i++) |
| 244 |
{ |
| 245 |
for(j = 0; j < height; j++) |
| 246 |
{ |
| 247 |
dv[0] = &ctrl2[j * width + i]; |
| 248 |
dv[1] = &ctrl[j][i]; |
| 249 |
|
| 250 |
VectorCopy4(dv[0]->tangent, dv[1]->tangent); |
| 251 |
} |
| 252 |
} |
| 253 |
} |
| 254 |
|
| 255 |
|
| 256 |
static int MakeMeshIndexes(int width, int height, glIndex_t indexes[(MAX_GRID_SIZE-1)*(MAX_GRID_SIZE-1)*2*3]) |
| 257 |
{ |
| 258 |
int i, j; |
| 259 |
int numIndexes; |
| 260 |
int w, h; |
| 261 |
|
| 262 |
h = height - 1; |
| 263 |
w = width - 1; |
| 264 |
numIndexes = 0; |
| 265 |
for(i = 0; i < h; i++) |
| 266 |
{ |
| 267 |
for(j = 0; j < w; j++) |
| 268 |
{ |
| 269 |
int v1, v2, v3, v4; |
| 270 |
|
| 271 |
|
| 272 |
v1 = i * width + j + 1; |
| 273 |
v2 = v1 - 1; |
| 274 |
v3 = v2 + width; |
| 275 |
v4 = v3 + 1; |
| 276 |
|
| 277 |
indexes[numIndexes++] = v2; |
| 278 |
indexes[numIndexes++] = v3; |
| 279 |
indexes[numIndexes++] = v1; |
| 280 |
|
| 281 |
indexes[numIndexes++] = v1; |
| 282 |
indexes[numIndexes++] = v3; |
| 283 |
indexes[numIndexes++] = v4; |
| 284 |
} |
| 285 |
} |
| 286 |
|
| 287 |
return numIndexes; |
| 288 |
} |
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
|
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
static void InvertCtrl( int width, int height, srfVert_t ctrl[MAX_GRID_SIZE][MAX_GRID_SIZE] ) { |
| 297 |
int i, j; |
| 298 |
srfVert_t temp; |
| 299 |
|
| 300 |
for ( i = 0 ; i < height ; i++ ) { |
| 301 |
for ( j = 0 ; j < width/2 ; j++ ) { |
| 302 |
temp = ctrl[i][j]; |
| 303 |
ctrl[i][j] = ctrl[i][width-1-j]; |
| 304 |
ctrl[i][width-1-j] = temp; |
| 305 |
} |
| 306 |
} |
| 307 |
} |
| 308 |
|
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
|
| 315 |
static void InvertErrorTable( float errorTable[2][MAX_GRID_SIZE], int width, int height ) { |
| 316 |
int i; |
| 317 |
float copy[2][MAX_GRID_SIZE]; |
| 318 |
|
| 319 |
Com_Memcpy( copy, errorTable, sizeof( copy ) ); |
| 320 |
|
| 321 |
for ( i = 0 ; i < width ; i++ ) { |
| 322 |
errorTable[1][i] = copy[0][i]; |
| 323 |
} |
| 324 |
|
| 325 |
for ( i = 0 ; i < height ; i++ ) { |
| 326 |
errorTable[0][i] = copy[1][height-1-i]; |
| 327 |
} |
| 328 |
|
| 329 |
} |
| 330 |
|
| 331 |
|
| 332 |
|
| 333 |
|
| 334 |
|
| 335 |
|
| 336 |
static void PutPointsOnCurve( srfVert_t ctrl[MAX_GRID_SIZE][MAX_GRID_SIZE], |
| 337 |
int width, int height ) { |
| 338 |
int i, j; |
| 339 |
srfVert_t prev, next; |
| 340 |
|
| 341 |
for ( i = 0 ; i < width ; i++ ) { |
| 342 |
for ( j = 1 ; j < height ; j += 2 ) { |
| 343 |
LerpDrawVert( &ctrl[j][i], &ctrl[j+1][i], &prev ); |
| 344 |
LerpDrawVert( &ctrl[j][i], &ctrl[j-1][i], &next ); |
| 345 |
LerpDrawVert( &prev, &next, &ctrl[j][i] ); |
| 346 |
} |
| 347 |
} |
| 348 |
|
| 349 |
|
| 350 |
for ( j = 0 ; j < height ; j++ ) { |
| 351 |
for ( i = 1 ; i < width ; i += 2 ) { |
| 352 |
LerpDrawVert( &ctrl[j][i], &ctrl[j][i+1], &prev ); |
| 353 |
LerpDrawVert( &ctrl[j][i], &ctrl[j][i-1], &next ); |
| 354 |
LerpDrawVert( &prev, &next, &ctrl[j][i] ); |
| 355 |
} |
| 356 |
} |
| 357 |
} |
| 358 |
|
| 359 |
|
| 360 |
|
| 361 |
|
| 362 |
|
| 363 |
|
| 364 |
void R_CreateSurfaceGridMesh(srfBspSurface_t *grid, int width, int height, |
| 365 |
srfVert_t ctrl[MAX_GRID_SIZE][MAX_GRID_SIZE], float errorTable[2][MAX_GRID_SIZE], |
| 366 |
int numIndexes, glIndex_t indexes[(MAX_GRID_SIZE-1)*(MAX_GRID_SIZE-1)*2*3]) { |
| 367 |
int i, j; |
| 368 |
srfVert_t *vert; |
| 369 |
vec3_t tmpVec; |
| 370 |
|
| 371 |
|
| 372 |
Com_Memset(grid, 0, sizeof(*grid)); |
| 373 |
|
| 374 |
#ifdef PATCH_STITCHING |
| 375 |
grid->widthLodError = ri.Malloc( width * 4 ); |
| 376 |
Com_Memcpy( grid->widthLodError, errorTable[0], width * 4 ); |
| 377 |
|
| 378 |
grid->heightLodError = ri.Malloc( height * 4 ); |
| 379 |
Com_Memcpy( grid->heightLodError, errorTable[1], height * 4 ); |
| 380 |
|
| 381 |
grid->numIndexes = numIndexes; |
| 382 |
grid->indexes = ri.Malloc(grid->numIndexes * sizeof(glIndex_t)); |
| 383 |
Com_Memcpy(grid->indexes, indexes, numIndexes * sizeof(glIndex_t)); |
| 384 |
|
| 385 |
grid->numVerts = (width * height); |
| 386 |
grid->verts = ri.Malloc(grid->numVerts * sizeof(srfVert_t)); |
| 387 |
#else |
| 388 |
grid->widthLodError = ri.Hunk_Alloc( width * 4, h_low ); |
| 389 |
Com_Memcpy( grid->widthLodError, errorTable[0], width * 4 ); |
| 390 |
|
| 391 |
grid->heightLodError = ri.Hunk_Alloc( height * 4, h_low ); |
| 392 |
Com_Memcpy( grid->heightLodError, errorTable[1], height * 4 ); |
| 393 |
|
| 394 |
grid->numIndexes = numIndexes; |
| 395 |
grid->indexes = ri.Hunk_Alloc(grid->numIndexes * sizeof(glIndex_t), h_low); |
| 396 |
Com_Memcpy(grid->indexes, indexes, numIndexes * sizeof(glIndex_t)); |
| 397 |
|
| 398 |
grid->numVerts = (width * height); |
| 399 |
grid->verts = ri.Hunk_Alloc(grid->numVerts * sizeof(srfVert_t), h_low); |
| 400 |
#endif |
| 401 |
|
| 402 |
grid->width = width; |
| 403 |
grid->height = height; |
| 404 |
grid->surfaceType = SF_GRID; |
| 405 |
ClearBounds( grid->cullBounds[0], grid->cullBounds[1] ); |
| 406 |
for ( i = 0 ; i < width ; i++ ) { |
| 407 |
for ( j = 0 ; j < height ; j++ ) { |
| 408 |
vert = &grid->verts[j*width+i]; |
| 409 |
*vert = ctrl[j][i]; |
| 410 |
AddPointToBounds( vert->xyz, grid->cullBounds[0], grid->cullBounds[1] ); |
| 411 |
} |
| 412 |
} |
| 413 |
|
| 414 |
|
| 415 |
VectorAdd( grid->cullBounds[0], grid->cullBounds[1], grid->cullOrigin ); |
| 416 |
VectorScale( grid->cullOrigin, 0.5f, grid->cullOrigin ); |
| 417 |
VectorSubtract( grid->cullBounds[0], grid->cullOrigin, tmpVec ); |
| 418 |
grid->cullRadius = VectorLength( tmpVec ); |
| 419 |
|
| 420 |
VectorCopy( grid->cullOrigin, grid->lodOrigin ); |
| 421 |
grid->lodRadius = grid->cullRadius; |
| 422 |
|
| 423 |
} |
| 424 |
|
| 425 |
|
| 426 |
|
| 427 |
|
| 428 |
|
| 429 |
|
| 430 |
static void R_FreeSurfaceGridMeshData( srfBspSurface_t *grid ) { |
| 431 |
ri.Free(grid->widthLodError); |
| 432 |
ri.Free(grid->heightLodError); |
| 433 |
ri.Free(grid->indexes); |
| 434 |
ri.Free(grid->verts); |
| 435 |
} |
| 436 |
|
| 437 |
|
| 438 |
|
| 439 |
|
| 440 |
|
| 441 |
|
| 442 |
void R_SubdividePatchToGrid( srfBspSurface_t *grid, int width, int height, |
| 443 |
srfVert_t points[MAX_PATCH_SIZE*MAX_PATCH_SIZE] ) { |
| 444 |
int i, j, k, l; |
| 445 |
srfVert_t_cleared( prev ); |
| 446 |
srfVert_t_cleared( next ); |
| 447 |
srfVert_t_cleared( mid ); |
| 448 |
float len, maxLen; |
| 449 |
int dir; |
| 450 |
int t; |
| 451 |
srfVert_t ctrl[MAX_GRID_SIZE][MAX_GRID_SIZE]; |
| 452 |
float errorTable[2][MAX_GRID_SIZE]; |
| 453 |
int numIndexes; |
| 454 |
static glIndex_t indexes[(MAX_GRID_SIZE-1)*(MAX_GRID_SIZE-1)*2*3]; |
| 455 |
int consecutiveComplete; |
| 456 |
|
| 457 |
for ( i = 0 ; i < width ; i++ ) { |
| 458 |
for ( j = 0 ; j < height ; j++ ) { |
| 459 |
ctrl[j][i] = points[j*width+i]; |
| 460 |
} |
| 461 |
} |
| 462 |
|
| 463 |
for ( dir = 0 ; dir < 2 ; dir++ ) { |
| 464 |
|
| 465 |
for ( j = 0 ; j < MAX_GRID_SIZE ; j++ ) { |
| 466 |
errorTable[dir][j] = 0; |
| 467 |
} |
| 468 |
|
| 469 |
consecutiveComplete = 0; |
| 470 |
|
| 471 |
|
| 472 |
for ( j = 0 ; ; j = (j + 2) % (width - 1) ) { |
| 473 |
|
| 474 |
|
| 475 |
|
| 476 |
|
| 477 |
|
| 478 |
maxLen = 0; |
| 479 |
for ( i = 0 ; i < height ; i++ ) { |
| 480 |
vec3_t midxyz; |
| 481 |
vec3_t midxyz2; |
| 482 |
vec3_t dirVector; |
| 483 |
vec3_t projected; |
| 484 |
float d; |
| 485 |
|
| 486 |
|
| 487 |
for ( l = 0 ; l < 3 ; l++ ) { |
| 488 |
midxyz[l] = (ctrl[i][j].xyz[l] + ctrl[i][j+1].xyz[l] * 2 |
| 489 |
+ ctrl[i][j+2].xyz[l] ) * 0.25f; |
| 490 |
} |
| 491 |
|
| 492 |
|
| 493 |
|
| 494 |
|
| 495 |
|
| 496 |
VectorSubtract( midxyz, ctrl[i][j].xyz, midxyz ); |
| 497 |
VectorSubtract( ctrl[i][j+2].xyz, ctrl[i][j].xyz, dirVector ); |
| 498 |
VectorNormalize( dirVector ); |
| 499 |
|
| 500 |
d = DotProduct( midxyz, dirVector ); |
| 501 |
VectorScale( dirVector, d, projected ); |
| 502 |
VectorSubtract( midxyz, projected, midxyz2); |
| 503 |
len = VectorLengthSquared( midxyz2 ); |
| 504 |
if ( len > maxLen ) { |
| 505 |
maxLen = len; |
| 506 |
} |
| 507 |
} |
| 508 |
|
| 509 |
maxLen = sqrt(maxLen); |
| 510 |
|
| 511 |
|
| 512 |
if ( maxLen < 0.1f ) { |
| 513 |
errorTable[dir][j+1] = 999; |
| 514 |
|
| 515 |
if (++consecutiveComplete >= width) |
| 516 |
break; |
| 517 |
continue; |
| 518 |
} |
| 519 |
|
| 520 |
|
| 521 |
if ( width + 2 > MAX_GRID_SIZE ) { |
| 522 |
errorTable[dir][j+1] = 1.0f/maxLen; |
| 523 |
break; |
| 524 |
} |
| 525 |
|
| 526 |
if ( maxLen <= r_subdivisions->value ) { |
| 527 |
errorTable[dir][j+1] = 1.0f/maxLen; |
| 528 |
|
| 529 |
if (++consecutiveComplete >= width) |
| 530 |
break; |
| 531 |
continue; |
| 532 |
} |
| 533 |
|
| 534 |
errorTable[dir][j+2] = 1.0f/maxLen; |
| 535 |
|
| 536 |
consecutiveComplete = 0; |
| 537 |
|
| 538 |
|
| 539 |
width += 2; |
| 540 |
for ( i = 0 ; i < height ; i++ ) { |
| 541 |
LerpDrawVert( &ctrl[i][j], &ctrl[i][j+1], &prev ); |
| 542 |
LerpDrawVert( &ctrl[i][j+1], &ctrl[i][j+2], &next ); |
| 543 |
LerpDrawVert( &prev, &next, &mid ); |
| 544 |
|
| 545 |
for ( k = width - 1 ; k > j + 3 ; k-- ) { |
| 546 |
ctrl[i][k] = ctrl[i][k-2]; |
| 547 |
} |
| 548 |
ctrl[i][j + 1] = prev; |
| 549 |
ctrl[i][j + 2] = mid; |
| 550 |
ctrl[i][j + 3] = next; |
| 551 |
} |
| 552 |
|
| 553 |
|
| 554 |
j += 2; |
| 555 |
} |
| 556 |
|
| 557 |
Transpose( width, height, ctrl ); |
| 558 |
t = width; |
| 559 |
width = height; |
| 560 |
height = t; |
| 561 |
} |
| 562 |
|
| 563 |
|
| 564 |
|
| 565 |
PutPointsOnCurve( ctrl, width, height ); |
| 566 |
|
| 567 |
|
| 568 |
for ( i = 1 ; i < width-1 ; i++ ) { |
| 569 |
if ( errorTable[0][i] != 999 ) { |
| 570 |
continue; |
| 571 |
} |
| 572 |
for ( j = i+1 ; j < width ; j++ ) { |
| 573 |
for ( k = 0 ; k < height ; k++ ) { |
| 574 |
ctrl[k][j-1] = ctrl[k][j]; |
| 575 |
} |
| 576 |
errorTable[0][j-1] = errorTable[0][j]; |
| 577 |
} |
| 578 |
width--; |
| 579 |
} |
| 580 |
|
| 581 |
for ( i = 1 ; i < height-1 ; i++ ) { |
| 582 |
if ( errorTable[1][i] != 999 ) { |
| 583 |
continue; |
| 584 |
} |
| 585 |
for ( j = i+1 ; j < height ; j++ ) { |
| 586 |
for ( k = 0 ; k < width ; k++ ) { |
| 587 |
ctrl[j-1][k] = ctrl[j][k]; |
| 588 |
} |
| 589 |
errorTable[1][j-1] = errorTable[1][j]; |
| 590 |
} |
| 591 |
height--; |
| 592 |
} |
| 593 |
|
| 594 |
#if 1 |
| 595 |
|
| 596 |
|
| 597 |
|
| 598 |
if ( height > width ) { |
| 599 |
Transpose( width, height, ctrl ); |
| 600 |
InvertErrorTable( errorTable, width, height ); |
| 601 |
t = width; |
| 602 |
width = height; |
| 603 |
height = t; |
| 604 |
InvertCtrl( width, height, ctrl ); |
| 605 |
} |
| 606 |
#endif |
| 607 |
|
| 608 |
|
| 609 |
numIndexes = MakeMeshIndexes(width, height, indexes); |
| 610 |
|
| 611 |
|
| 612 |
MakeMeshNormals( width, height, ctrl ); |
| 613 |
MakeMeshTangentVectors(width, height, ctrl, numIndexes, indexes); |
| 614 |
|
| 615 |
R_CreateSurfaceGridMesh(grid, width, height, ctrl, errorTable, numIndexes, indexes); |
| 616 |
} |
| 617 |
|
| 618 |
|
| 619 |
|
| 620 |
|
| 621 |
|
| 622 |
|
| 623 |
void R_GridInsertColumn( srfBspSurface_t *grid, int column, int row, vec3_t point, float loderror ) { |
| 624 |
int i, j; |
| 625 |
int width, height, oldwidth; |
| 626 |
srfVert_t ctrl[MAX_GRID_SIZE][MAX_GRID_SIZE]; |
| 627 |
float errorTable[2][MAX_GRID_SIZE]; |
| 628 |
float lodRadius; |
| 629 |
vec3_t lodOrigin; |
| 630 |
int numIndexes; |
| 631 |
static glIndex_t indexes[(MAX_GRID_SIZE-1)*(MAX_GRID_SIZE-1)*2*3]; |
| 632 |
|
| 633 |
oldwidth = 0; |
| 634 |
width = grid->width + 1; |
| 635 |
if (width > MAX_GRID_SIZE) |
| 636 |
return; |
| 637 |
height = grid->height; |
| 638 |
for (i = 0; i < width; i++) { |
| 639 |
if (i == column) { |
| 640 |
|
| 641 |
for (j = 0; j < grid->height; j++) { |
| 642 |
LerpDrawVert( &grid->verts[j * grid->width + i-1], &grid->verts[j * grid->width + i], &ctrl[j][i] ); |
| 643 |
if (j == row) |
| 644 |
VectorCopy(point, ctrl[j][i].xyz); |
| 645 |
} |
| 646 |
errorTable[0][i] = loderror; |
| 647 |
continue; |
| 648 |
} |
| 649 |
errorTable[0][i] = grid->widthLodError[oldwidth]; |
| 650 |
for (j = 0; j < grid->height; j++) { |
| 651 |
ctrl[j][i] = grid->verts[j * grid->width + oldwidth]; |
| 652 |
} |
| 653 |
oldwidth++; |
| 654 |
} |
| 655 |
for (j = 0; j < grid->height; j++) { |
| 656 |
errorTable[1][j] = grid->heightLodError[j]; |
| 657 |
} |
| 658 |
|
| 659 |
|
| 660 |
|
| 661 |
|
| 662 |
numIndexes = MakeMeshIndexes(width, height, indexes); |
| 663 |
|
| 664 |
|
| 665 |
MakeMeshNormals( width, height, ctrl ); |
| 666 |
MakeMeshTangentVectors(width, height, ctrl, numIndexes, indexes); |
| 667 |
|
| 668 |
VectorCopy(grid->lodOrigin, lodOrigin); |
| 669 |
lodRadius = grid->lodRadius; |
| 670 |
|
| 671 |
R_FreeSurfaceGridMeshData(grid); |
| 672 |
|
| 673 |
R_CreateSurfaceGridMesh(grid, width, height, ctrl, errorTable, numIndexes, indexes); |
| 674 |
grid->lodRadius = lodRadius; |
| 675 |
VectorCopy(lodOrigin, grid->lodOrigin); |
| 676 |
} |
| 677 |
|
| 678 |
|
| 679 |
|
| 680 |
|
| 681 |
|
| 682 |
|
| 683 |
void R_GridInsertRow( srfBspSurface_t *grid, int row, int column, vec3_t point, float loderror ) { |
| 684 |
int i, j; |
| 685 |
int width, height, oldheight; |
| 686 |
srfVert_t ctrl[MAX_GRID_SIZE][MAX_GRID_SIZE]; |
| 687 |
float errorTable[2][MAX_GRID_SIZE]; |
| 688 |
float lodRadius; |
| 689 |
vec3_t lodOrigin; |
| 690 |
int numIndexes; |
| 691 |
static glIndex_t indexes[(MAX_GRID_SIZE-1)*(MAX_GRID_SIZE-1)*2*3]; |
| 692 |
|
| 693 |
oldheight = 0; |
| 694 |
width = grid->width; |
| 695 |
height = grid->height + 1; |
| 696 |
if (height > MAX_GRID_SIZE) |
| 697 |
return; |
| 698 |
for (i = 0; i < height; i++) { |
| 699 |
if (i == row) { |
| 700 |
|
| 701 |
for (j = 0; j < grid->width; j++) { |
| 702 |
LerpDrawVert( &grid->verts[(i-1) * grid->width + j], &grid->verts[i * grid->width + j], &ctrl[i][j] ); |
| 703 |
if (j == column) |
| 704 |
VectorCopy(point, ctrl[i][j].xyz); |
| 705 |
} |
| 706 |
errorTable[1][i] = loderror; |
| 707 |
continue; |
| 708 |
} |
| 709 |
errorTable[1][i] = grid->heightLodError[oldheight]; |
| 710 |
for (j = 0; j < grid->width; j++) { |
| 711 |
ctrl[i][j] = grid->verts[oldheight * grid->width + j]; |
| 712 |
} |
| 713 |
oldheight++; |
| 714 |
} |
| 715 |
for (j = 0; j < grid->width; j++) { |
| 716 |
errorTable[0][j] = grid->widthLodError[j]; |
| 717 |
} |
| 718 |
|
| 719 |
|
| 720 |
|
| 721 |
|
| 722 |
numIndexes = MakeMeshIndexes(width, height, indexes); |
| 723 |
|
| 724 |
|
| 725 |
MakeMeshNormals( width, height, ctrl ); |
| 726 |
MakeMeshTangentVectors(width, height, ctrl, numIndexes, indexes); |
| 727 |
|
| 728 |
VectorCopy(grid->lodOrigin, lodOrigin); |
| 729 |
lodRadius = grid->lodRadius; |
| 730 |
|
| 731 |
R_FreeSurfaceGridMeshData(grid); |
| 732 |
|
| 733 |
R_CreateSurfaceGridMesh(grid, width, height, ctrl, errorTable, numIndexes, indexes); |
| 734 |
grid->lodRadius = lodRadius; |
| 735 |
VectorCopy(lodOrigin, grid->lodOrigin); |
| 736 |
} |