/* =================== R_ClipTriangleToLight Returns false if nothing is left after clipping =================== */ ID_STATIC_TEMPLATE ID_INLINE bool R_ClipTriangleToLight( stencilRef_t *st, const idVec3 &a, const idVec3 &b, const idVec3 &c, int planeBits, const idPlane frustum[6] ) { int i; int base; clipTri_t pingPong[2], *ct; int p; pingPong[0].numVerts = 3; pingPong[0].edgeFlags[0] = 0; pingPong[0].edgeFlags[1] = 0; pingPong[0].edgeFlags[2] = 0; pingPong[0].verts[0] = a; pingPong[0].verts[1] = b; pingPong[0].verts[2] = c; p = 0; for( i = 0; i < 6; i++ ) { if( planeBits & ( 1 << i ) ) { p = R_ChopWinding( pingPong, p, frustum[i] ); if( pingPong[p].numVerts < 1 ) { return false; } } } ct = &pingPong[p]; // copy the clipped points out to shadowVerts if( st->numShadowVerts + ct->numVerts * 2 > MAX_SHADOW_VERTS ) { st->overflowed = true; return false; } base = st->numShadowVerts; for( i = 0; i < ct->numVerts; i++ ) { st->shadowVerts[base + i * 2].ToVec3() = ct->verts[i]; } st->numShadowVerts += ct->numVerts * 2; if( st->numShadowIndexes + 3 * ( ct->numVerts - 2 ) > MAX_SHADOW_INDEXES ) { st->overflowed = true; return false; } for( i = 2; i < ct->numVerts; i++ ) { st->shadowIndexes[st->numShadowIndexes++] = base + i * 2; st->shadowIndexes[st->numShadowIndexes++] = base + ( i - 1 ) * 2; st->shadowIndexes[st->numShadowIndexes++] = base; } // any edges that were created by the clipping process will // have a silhouette quad created for it, because it is one // of the exterior bounds of the shadow volume for( i = 0; i < ct->numVerts; i++ ) { if( ct->edgeFlags[i] ) { if( st->numClipSilEdges == MAX_CLIP_SIL_EDGES ) { break; } st->clipSilEdges[st->numClipSilEdges][0] = base + i * 2; if( i == ct->numVerts - 1 ) { st->clipSilEdges[st->numClipSilEdges][1] = base; } else { st->clipSilEdges[st->numClipSilEdges][1] = base + ( i + 1 ) * 2; } st->numClipSilEdges++; } } return true; }
/* =================== R_ClipTriangleToLight Returns false if nothing is left after clipping =================== */ static bool R_ClipTriangleToLight( const idVec3 &a, const idVec3 &b, const idVec3 &c, int planeBits, const idPlane frustum[6] ) { int i; clipTri_t pingPong[2]; int p; pingPong[0].numVerts = 3; pingPong[0].verts[0] = a; pingPong[0].verts[1] = b; pingPong[0].verts[2] = c; p = 0; for ( i = 0 ; i < 6 ; i++ ) { if ( planeBits & ( 1 << i ) ) { p = R_ChopWinding( pingPong, p, frustum[i] ); if ( pingPong[p].numVerts < 1 ) { return false; } } } return true; }