/// <summary> /// Clips a BSP node, returns a triangle list /// </summary> private static void ClippetyClip( Csg.BspNode node, float x, float y, float mX, float mY, TriBuilder builder ) { if ( node == null ) { return; } ClipNode( node.Quad, x, y, mX, mY, builder ); ClippetyClip( node.InFront, x, y, mX, mY, builder ); ClippetyClip( node.Behind, x, y, mX, mY, builder ); }
private static void ClipNode( Point3[] quad, float x, float y, float mX, float mY, TriBuilder builder ) { // Loop endlessly (will keep clipping until quad is trivially accepted or rejected) while ( true ) { byte startClip = ClipCode( quad[ 0 ], x, y, mX, mY ); byte endClip = ClipCode( quad[ 1 ], x, y, mX, mY ); if ( ( startClip | endClip ) == 0 ) { // Both points in chop rect - trivially accept builder.AddQuad( quad[ 0 ], quad[ 1 ], quad[ 2 ], quad[ 3 ]); return; } else if ( ( startClip & endClip ) != 0 ) { // Both points on the same side outside the chop rect - trivially reject return; } // One or both points outside the chop rect - clip one of them to the chop rect and start again if ( startClip != 0 ) { ClipQuad( true, quad, startClip, x, y, mX, mY ); } else if ( endClip != 0 ) { ClipQuad( false, quad, endClip, x, y, mX, mY ); } } }