MCPcopy Create free account
hub / github.com/JACoders/OpenJK / CM_SubdivideGridColumns

Function CM_SubdivideGridColumns

code/qcommon/cm_patch.cpp:316–376  ·  view source on GitHub ↗

================= CM_SubdivideGridColumns Adds columns as necessary to the grid until all the aproximating points are within SUBDIVIDE_DISTANCE from the true curve ================= */

Source from the content-addressed store, hash-verified

314=================
315*/
316static void CM_SubdivideGridColumns( cGrid_t *grid ) {
317 int i, j, k;
318
319 for ( i = 0 ; i < grid->width - 2 ; ) {
320 // grid->points[i][x] is an interpolating control point
321 // grid->points[i+1][x] is an aproximating control point
322 // grid->points[i+2][x] is an interpolating control point
323
324 //
325 // first see if we can collapse the aproximating collumn away
326 //
327 for ( j = 0 ; j < grid->height ; j++ ) {
328 if ( CM_NeedsSubdivision( grid->points[i][j], grid->points[i+1][j], grid->points[i+2][j] ) ) {
329 break;
330 }
331 }
332 if ( j == grid->height ) {
333 // all of the points were close enough to the linear midpoints
334 // that we can collapse the entire column away
335 for ( j = 0 ; j < grid->height ; j++ ) {
336 // remove the column
337 for ( k = i + 2 ; k < grid->width ; k++ ) {
338 VectorCopy( grid->points[k][j], grid->points[k-1][j] );
339 }
340 }
341
342 grid->width--;
343
344 // go to the next curve segment
345 i++;
346 continue;
347 }
348
349 //
350 // we need to subdivide the curve
351 //
352 for ( j = 0 ; j < grid->height ; j++ ) {
353 vec3_t prev, mid, next;
354
355 // save the control points now
356 VectorCopy( grid->points[i][j], prev );
357 VectorCopy( grid->points[i+1][j], mid );
358 VectorCopy( grid->points[i+2][j], next );
359
360 // make room for two additional columns in the grid
361 // columns i+1 will be replaced, column i+2 will become i+4
362 // i+1, i+2, and i+3 will be generated
363 for ( k = grid->width - 1 ; k > i + 1 ; k-- ) {
364 VectorCopy( grid->points[k][j], grid->points[k+2][j] );
365 }
366
367 // generate the subdivided points
368 CM_Subdivide( prev, mid, next, grid->points[i+1][j], grid->points[i+2][j], grid->points[i+3][j] );
369 }
370
371 grid->width += 2;
372
373 // the new aproximating point at i+1 may need to be removed

Callers 1

CM_GeneratePatchCollideFunction · 0.70

Calls 3

VectorCopyFunction · 0.85
CM_NeedsSubdivisionFunction · 0.70
CM_SubdivideFunction · 0.70

Tested by

no test coverage detected