Ejemplo n.º 1
0
	void ClipLine(int *indices)
	{
		int mask = 0;
		int clip_mask[2] = { 0, 0 };

		for (int i = 0; i < 2; ++i)
		{
			clip_mask[i] = CalcClipMask(Vertices[i]);
			mask |= clip_mask[i];
		}

		if (mask == 0)
			return;

		float t0 = 0;
		float t1 = 0;

		// Mark unused in case of early termination
		// of the macros below. (When fully clipped)
		indices[0] = SKIP_FLAG;
		indices[1] = SKIP_FLAG;

		LINE_CLIP(CLIP_POS_X_BIT, -1,  0,  0, 1);
		LINE_CLIP(CLIP_NEG_X_BIT,  1,  0,  0, 1);
		LINE_CLIP(CLIP_POS_Y_BIT,  0, -1,  0, 1);
		LINE_CLIP(CLIP_NEG_Y_BIT,  0,  1,  0, 1);
		LINE_CLIP(CLIP_POS_Z_BIT,  0,  0, -1, 1);
		LINE_CLIP(CLIP_NEG_Z_BIT,  0,  0,  1, 1);

		// Restore the old values as this line
		// was not fully clipped.
		indices[0] = 0;
		indices[1] = 1;

		int numVertices = 2;

		if (clip_mask[0])
		{
			indices[0] = numVertices;
			AddInterpolatedVertex(t0, 0, 1, numVertices);
		}

		if (clip_mask[1])
		{
			indices[1] = numVertices;
			AddInterpolatedVertex(t1, 1, 0, numVertices);
		}
	}
Ejemplo n.º 2
0
/* Clip a line against the viewport and user clip planes.
 */
static void TAG(clip_draw_line)( GLcontext *ctx,
				 TNL_VERTEX *I,
				 TNL_VERTEX *J,
				 GLuint mask )
{
   LOCAL_VARS;
   GET_INTERP_FUNC;
   TNL_VERTEX tmp[MAX_CLIPPED_VERTICES];
   TNL_VERTEX *verts = tmp;
   TNL_VERTEX *pv = J;

   LINE_CLIP( CLIP_RIGHT_BIT,  -1,  0,  0, 1 );
   LINE_CLIP( CLIP_LEFT_BIT,    1,  0,  0, 1 );
   LINE_CLIP( CLIP_TOP_BIT,     0, -1,  0, 1 );
   LINE_CLIP( CLIP_BOTTOM_BIT,  0,  1,  0, 1 );
   LINE_CLIP( CLIP_FAR_BIT,     0,  0, -1, 1 );
   LINE_CLIP( CLIP_NEAR_BIT,    0,  0,  1, 1 );

   if ((ctx->_TriangleCaps & DD_FLATSHADE) && J != pv)
      COPY_PV( ctx, J, pv );

   DRAW_LINE( I, J );
}