/* ================ CM_TraceThroughBrush ================ */ void CM_TraceThroughBrush( traceWork_t *tw, trace_t &trace, cbrush_t *brush, bool infoOnly ) { int i; cbrushside_t *side; tw->enterFrac = -1.0f; tw->leaveFrac = 1.0f; tw->clipplane = NULL; if ( !brush->numsides ) { return; } tw->getout = false; tw->startout = false; tw->leadside = NULL; // // compare the trace against all planes of the brush // find the latest time the trace crosses a plane towards the interior // and the earliest time the trace crosses a plane towards the exterior // for (i = 0; i < brush->numsides; i++) { side = brush->sides + i; if(!CM_PlaneCollision(tw, side)) { return; } } // // all planes have been checked, and the trace was not // completely outside the brush // if (!tw->startout) { if(!infoOnly) { // original point was inside brush trace.startsolid = qtrue; if (!tw->getout) { trace.allsolid = qtrue; trace.fraction = 0.0f; } } tw->enterFrac = 0.0f; return; } if (tw->enterFrac < tw->leaveFrac) { if ((tw->enterFrac > -1.0f) && (tw->enterFrac < trace.fraction)) { if (tw->enterFrac < 0.0f) { tw->enterFrac = 0.0f; } if(!infoOnly) { trace.fraction = tw->enterFrac; trace.plane = *tw->clipplane; trace.surfaceFlags = cmg.shaders[tw->leadside->shaderNum].surfaceFlags; // tw->trace.sideNum = tw->leadside - cmg.brushsides; trace.contents = brush->contents; } } } }
/* ================ CM_TraceThroughBrush ================ */ void CM_TraceThroughBrush( traceWork_t *tw, trace_t &trace, cbrush_t *brush, bool infoOnly ) { int i; cbrushside_t *side; tw->enterFrac = -1.0f; tw->leaveFrac = 1.0f; tw->clipplane = NULL; if ( !brush->numsides ) { return; } // I'm not sure if test is strictly correct. Are all // bboxes axis aligned? Do I care? It seems to work // good enough... if ( tw->bounds[0][0] > brush->bounds[1][0] || tw->bounds[0][1] > brush->bounds[1][1] || tw->bounds[0][2] > brush->bounds[1][2] || tw->bounds[1][0] < brush->bounds[0][0] || tw->bounds[1][1] < brush->bounds[0][1] || tw->bounds[1][2] < brush->bounds[0][2] ) { return; } tw->getout = false; tw->startout = false; tw->leadside = NULL; // // compare the trace against all planes of the brush // find the latest time the trace crosses a plane towards the interior // and the earliest time the trace crosses a plane towards the exterior // for (i = 0; i < brush->numsides; i++) { side = brush->sides + i; if(!CM_PlaneCollision(tw, side)) { return; } } // // all planes have been checked, and the trace was not // completely outside the brush // if (!tw->startout) { if(!infoOnly) { // original point was inside brush trace.startsolid = qtrue; if (!tw->getout) { trace.allsolid = qtrue; trace.fraction = 0.0f; } } tw->enterFrac = 0.0f; return; } if (tw->enterFrac < tw->leaveFrac) { if ((tw->enterFrac > -1.0f) && (tw->enterFrac < trace.fraction)) { if (tw->enterFrac < 0.0f) { tw->enterFrac = 0.0f; } if(!infoOnly) { trace.fraction = tw->enterFrac; trace.plane = *tw->clipplane; trace.surfaceFlags = cmg.shaders[tw->leadside->shaderNum].surfaceFlags; trace.contents = brush->contents; } } } }