/* ================ idClip::ClipModelsTouchingBounds ================ */ int idClip::ClipModelsTouchingBounds( const idBounds& bounds, int contentMask, idClipModel** clipModelList, int maxCount ) const { listParms_t parms; if( bounds[0][0] > bounds[1][0] || bounds[0][1] > bounds[1][1] || bounds[0][2] > bounds[1][2] ) { // we should not go through the tree for degenerate or backwards bounds assert( false ); return 0; } parms.bounds[0] = bounds[0] - vec3_boxEpsilon; parms.bounds[1] = bounds[1] + vec3_boxEpsilon; parms.contentMask = contentMask; parms.list = clipModelList; parms.count = 0; parms.maxCount = maxCount; touchCount++; ClipModelsTouchingBounds_r( clipSectors, parms ); return parms.count; }
void idClip::ClipModelsTouchingBounds_r( const struct clipSector_s *node, listParms_t &parms ) const { while( node->axis != -1 ) { if ( parms.bounds[0][node->axis] > node->dist ) { node = node->children[0]; } else if ( parms.bounds[1][node->axis] < node->dist ) { node = node->children[1]; } else { ClipModelsTouchingBounds_r( node->children[0], parms ); node = node->children[1]; } } for ( clipLink_t *link = node->clipLinks; link; link = link->nextInSector ) { idClipModel *check = link->clipModel; // if the clip model is enabled if ( !check->enabled ) { continue; } // avoid duplicates in the list if ( check->touchCount == touchCount ) { continue; } // if the clip model does not have any contents we are looking for if ( !( check->contents & parms.contentMask ) ) { continue; } // if the bounds really do overlap if ( check->absBounds[0][0] > parms.bounds[1][0] || check->absBounds[1][0] < parms.bounds[0][0] || check->absBounds[0][1] > parms.bounds[1][1] || check->absBounds[1][1] < parms.bounds[0][1] || check->absBounds[0][2] > parms.bounds[1][2] || check->absBounds[1][2] < parms.bounds[0][2] ) { continue; } if ( parms.count >= parms.maxCount ) { gameLocal.Warning( "idClip::ClipModelsTouchingBounds_r: max count" ); return; } check->touchCount = touchCount; parms.list[parms.count] = check; parms.count++; } }