now disco debugging the clipping algorithm
This commit is contained in:
		
							parent
							
								
									a14acdb0ed
								
							
						
					
					
						commit
						3d40bb2943
					
				@ -1,4 +1,5 @@
 | 
				
			|||||||
#include <stdlib.h>
 | 
					#include <stdlib.h>
 | 
				
			||||||
 | 
					#include "log.h"
 | 
				
			||||||
#include "fbinit.h"
 | 
					#include "fbinit.h"
 | 
				
			||||||
#include "devctxt.h"
 | 
					#include "devctxt.h"
 | 
				
			||||||
#include "dc_screen.h"
 | 
					#include "dc_screen.h"
 | 
				
			||||||
@ -78,6 +79,15 @@ static BOOL screen_line(PVOID privdata, INT32 x1, INT32 y1, INT32 x2, INT32 y2,
 | 
				
			|||||||
  INT32 tmp;
 | 
					  INT32 tmp;
 | 
				
			||||||
  PUINT16 loc;
 | 
					  PUINT16 loc;
 | 
				
			||||||
  
 | 
					  
 | 
				
			||||||
 | 
					  ASSERT(x1 >= 0);
 | 
				
			||||||
 | 
					  ASSERT(x1 < Fb_Info->width);
 | 
				
			||||||
 | 
					  ASSERT(y1 >= 0);
 | 
				
			||||||
 | 
					  ASSERT(y1 < Fb_Info->height);
 | 
				
			||||||
 | 
					  ASSERT(x2 >= 0);
 | 
				
			||||||
 | 
					  ASSERT(x2 < Fb_Info->width);
 | 
				
			||||||
 | 
					  ASSERT(y2 >= 0);
 | 
				
			||||||
 | 
					  ASSERT(y2 < Fb_Info->height);
 | 
				
			||||||
 | 
					  
 | 
				
			||||||
  if (ABS(dx) < ABS(dy))
 | 
					  if (ABS(dx) < ABS(dy))
 | 
				
			||||||
  {
 | 
					  {
 | 
				
			||||||
    if (y1 > y2)
 | 
					    if (y1 > y2)
 | 
				
			||||||
 | 
				
			|||||||
@ -1,5 +1,6 @@
 | 
				
			|||||||
#include <string.h>
 | 
					#include <string.h>
 | 
				
			||||||
#include <stdlib.h>
 | 
					#include <stdlib.h>
 | 
				
			||||||
 | 
					#include "log.h"
 | 
				
			||||||
#include "gfxtype.h"
 | 
					#include "gfxtype.h"
 | 
				
			||||||
#include "gfxobj.h"
 | 
					#include "gfxobj.h"
 | 
				
			||||||
#include "devctxt.h"
 | 
					#include "devctxt.h"
 | 
				
			||||||
@ -23,17 +24,27 @@ static BOOL line_clip(PINT32 output, INT32 x1, INT32 y1, INT32 x2, INT32 y2, INT
 | 
				
			|||||||
  BYTE outcode1, outcode2, tmpb;
 | 
					  BYTE outcode1, outcode2, tmpb;
 | 
				
			||||||
  INT32 tmp;
 | 
					  INT32 tmp;
 | 
				
			||||||
  
 | 
					  
 | 
				
			||||||
 | 
					  Log(LDEBUG, "clipping line from (%d, %d) to (%d, %d) against bounding box (%d, %d, %d, %d)", x1 >> 16, y1 >> 16, x2 >> 16, y2 >> 16,
 | 
				
			||||||
 | 
					      xmin >> 16, ymin >> 16, xmax >> 16, ymax >> 16);
 | 
				
			||||||
 | 
					  
 | 
				
			||||||
  /* Cohen-Sutherland line-clipping algorithm (see Foley & Van Dam, pp. 145-149) */
 | 
					  /* Cohen-Sutherland line-clipping algorithm (see Foley & Van Dam, pp. 145-149) */
 | 
				
			||||||
  for (;;)
 | 
					  for (;;)
 | 
				
			||||||
  {
 | 
					  {
 | 
				
			||||||
    outcode1 = line_clip_outcode(x1, y1, xmin, ymin, xmax, ymax);
 | 
					    outcode1 = line_clip_outcode(x1, y1, xmin, ymin, xmax, ymax);
 | 
				
			||||||
	outcode2 = line_clip_outcode(x2, y2, xmin, ymin, xmax, ymax);
 | 
						outcode2 = line_clip_outcode(x2, y2, xmin, ymin, xmax, ymax);
 | 
				
			||||||
	if ((outcode1 & outcode2) != 0)
 | 
						if ((outcode1 & outcode2) != 0)
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
						  Log.debug("*REJECT*");
 | 
				
			||||||
	  return FALSE; /* trivial rejection */
 | 
						  return FALSE; /* trivial rejection */
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	else if ((outcode1 == 0) && (outcode2 == 0))
 | 
						else if ((outcode1 == 0) && (outcode2 == 0))
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
						  Log.debug("*ACCEPT*");
 | 
				
			||||||
	  break; /* trivial acceptance */
 | 
						  break; /* trivial acceptance */
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	if (outcode1 == 0)
 | 
						if (outcode1 == 0)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
 | 
						  Log(LDEBUG, "exchange points")
 | 
				
			||||||
	  tmp = x1;
 | 
						  tmp = x1;
 | 
				
			||||||
	  x1 = x2;
 | 
						  x1 = x2;
 | 
				
			||||||
	  x2 = tmp;
 | 
						  x2 = tmp;
 | 
				
			||||||
@ -48,23 +59,28 @@ static BOOL line_clip(PINT32 output, INT32 x1, INT32 y1, INT32 x2, INT32 y2, INT
 | 
				
			|||||||
	{
 | 
						{
 | 
				
			||||||
	  x1 += (x2 - x1) * (ymin - y1) / (y2 - y1);
 | 
						  x1 += (x2 - x1) * (ymin - y1) / (y2 - y1);
 | 
				
			||||||
	  y1 = ymin;
 | 
						  y1 = ymin;
 | 
				
			||||||
 | 
						  Log.debug("clipped against top to point (%d, %d)", x1 >> 16, y1 >> 16);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	else if (outcode1 & 0x4)
 | 
						else if (outcode1 & 0x4)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
	  x1 += (x2 - x1) * (ymax - y1) / (y2 - y1);
 | 
						  x1 += (x2 - x1) * (ymax - y1) / (y2 - y1);
 | 
				
			||||||
	  y1 = ymax;
 | 
						  y1 = ymax;
 | 
				
			||||||
 | 
						  Log.debug("clipped against bottom to point (%d, %d)", x1 >> 16, y1 >> 16);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	else if (outcode1 & 0x2)
 | 
						else if (outcode1 & 0x2)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
	  y1 += (y2 - y1) * (xmax - x1) / (x2 - x1);
 | 
						  y1 += (y2 - y1) * (xmax - x1) / (x2 - x1);
 | 
				
			||||||
	  x1 = xmax;
 | 
						  x1 = xmax;
 | 
				
			||||||
 | 
						  Log.debug("clipped against right to point (%d, %d)", x1 >> 16, y1 >> 16);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	else if (outcode1 & 0x1)
 | 
						else if (outcode1 & 0x1)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
	  y1 += (y2 - y1) * (xmin - x1) / (x2 - x1);
 | 
						  y1 += (y2 - y1) * (xmin - x1) / (x2 - x1);
 | 
				
			||||||
	  x1 = xmin;
 | 
						  x1 = xmin;
 | 
				
			||||||
 | 
						  Log.debug("clipped against left to point (%d, %d)", x1 >> 16, y1 >> 16);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					  Log(LDEBUG, "final line is from (%d, %d) to (%d, %d)", x1 >> 16, y1 >> 16, x2 >> 16, y2 >> 16);
 | 
				
			||||||
  output[0] = x1;
 | 
					  output[0] = x1;
 | 
				
			||||||
  output[1] = y1;
 | 
					  output[1] = y1;
 | 
				
			||||||
  output[2] = x2;
 | 
					  output[2] = x2;
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user