Ejemplo n.º 1
0
void clip_poly_menu() {
    cleardevice();
    std::vector<Point2D> p1, p2;

    outtext((char*)"Define the Polygon Window");
    outtextxy(0, 25, (char*)"Left click mouse to add points to polygon and right click to finish adding points");
    std::cout<<"\nPolygon1";
    p1 = mk_poly();

    cleardevice();

    setcolor(RED);
    mypoly(p1);

    outtext((char*)"Define the Polygon to be Clipped");
    std::cout<<"\nPolygon2";
    p2 = mk_poly();

    clip_poly(p1, p2);
}
Ejemplo n.º 2
0
Archivo: poly.c Proyecto: qeedquan/qmap
void draw_face(int face)
{
   int n = dfaces[face].numedges;
   int se = dfaces[face].firstedge;
   int i,codes_or=0,codes_and=0xff;
   point_3d **vlist;

   for (i=0; i < n; ++i) {
      int edge = dsurfedges[se+i];
      if (edge < 0)
         transform_point(&pts[i], (vector *) VERTEX(dedges[-edge].v[1]));
      else
         transform_point(&pts[i], (vector *) VERTEX(dedges[ edge].v[0]));
      codes_or  |= pts[i].ccodes;
      codes_and &= pts[i].ccodes;
   }

   if (codes_and) return;  // abort if poly outside frustrum

   if (codes_or) {
      // poly crosses frustrum, so clip it
      n = clip_poly(n, default_vlist, codes_or, &vlist);
   } else
      vlist = default_vlist;

   if (n) {
      bitmap bm;
      float u,v;
      int tex = dfaces[face].texinfo;
      int mip = compute_mip_level(face);
      get_tmap(&bm, face, texinfo[tex].miptex, mip, &u, &v);
      qmap_set_texture(&bm);
      compute_texture_gradients(face, tex, mip, u, v);
      draw_poly(n, vlist);
   }
}
Ejemplo n.º 3
0
static void
fz_paint_triangle(fz_pixmap *pix, float poly_in[3][MAXN], int n, const fz_irect *bbox)
{
	float poly[MAXV][MAXN];
	float temp[MAXV][MAXN];
	float cx0 = bbox->x0;
	float cy0 = bbox->y0;
	float cx1 = bbox->x1;
	float cy1 = bbox->y1;

	int gel[MAXV][MAXN];
	int ael[2][MAXN];
	int del[2][MAXN];
	int y, s0, s1, e0, e1;
	int top, bot, len;

	int i, k;

	len = clip_poly(poly_in, temp, 3, n, cx0, 0, 0);
	len = clip_poly(temp, poly, len, n, cx1, 0, 1);
	len = clip_poly(poly, temp, len, n, cy0, 1, 0);
	len = clip_poly(temp, poly, len, n, cy1, 1, 1);

	if (len < 3)
		return;

	for (i = 0; i < len; i++)
	{
		gel[i][0] = floorf(poly[i][0] + 0.5f) * 65536; /* trunc and fix */
		gel[i][1] = floorf(poly[i][1] + 0.5f); /* y is not fixpoint */
		for (k = 2; k < n; k++)
			gel[i][k] = poly[i][k] * 65536; /* fix with precision */
	}

	top = bot = 0;
	for (i = 0; i < len; i++)
	{
		if (gel[i][1] < gel[top][1])
			top = i;
		if (gel[i][1] > gel[bot][1])
			bot = i;
	}

	if (gel[bot][1] - gel[top][1] == 0)
		return;

	y = gel[top][1];

	if (find_next(gel, len, top, &s0, &e0, 1))
		return;
	if (find_next(gel, len, top, &s1, &e1, -1))
		return;

	load_edge(gel, s0, e0, ael[0], del[0], n);
	load_edge(gel, s1, e1, ael[1], del[1], n);

	while (1)
	{
		int x0 = ael[0][0] >> 16;
		int x1 = ael[1][0] >> 16;

		if (ael[0][0] < ael[1][0])
			paint_scan(pix, y, x0, x1, ael[0]+2, ael[1]+2, n-2);
		else
			paint_scan(pix, y, x1, x0, ael[1]+2, ael[0]+2, n-2);

		step_edge(ael[0], del[0], n);
		step_edge(ael[1], del[1], n);
		y ++;

		if (y >= gel[e0][1])
		{
			if (find_next(gel, len, e0, &s0, &e0, 1))
				return;
			load_edge(gel, s0, e0, ael[0], del[0], n);
		}

		if (y >= gel[e1][1])
		{
			if (find_next(gel, len, e1, &s1, &e1, -1))
				return;
			load_edge(gel, s1, e1, ael[1], del[1], n);
		}
	}
}
Ejemplo n.º 4
0
void clippoly(ClipOperation op, 
	      int n1, float* x1, float* y1, int n2, float* x2, float* y2,
	      int& npolys, int*& ni, float**& x, float**& y
	  ) {
    int i;
#if 0
    cout << "A:" << endl;
    for (i = 0; i < n1; i++)
	cout << x1[i] << " " << y1[i] << endl;
    cout << "B:" << endl;
    for (i = 0; i < n2; i++)
	cout << x2[i] << " " << y2[i] << endl;
    cout << endl;
#endif
    Poly* poly1;
    for (i = 0; i < n1; i++) {
	if (i == 0) {
	    Point* p0 = new Point(x1[0], y1[0]);
	    poly1 = new Poly(*p0);
	}
	else if (!(x1[i] == x1[i-1] && y1[i] == y1[i-1]) &&
		 !(i==n1-1 && x1[i] == x1[0] && y1[i] == y1[0])) {
	    Point* pi = new Point(x1[i], y1[i]);
	    poly1->add(*pi);
	}
    }
    Poly* poly2;
    for (i = 0; i < n2; i++) {
	if (i == 0) {
	    Point* p0 = new Point(x2[0], y2[0]);
	    poly2 = new Poly(*p0);
	}
	else if (!(x2[i] == x2[i-1] && y2[i] == y2[i-1]) &&
		 !(i==n2-1 && x2[i] == x2[0] && y2[i] == y2[0])) {
	    Point* pi = new Point(x2[i], y2[i]);
	    poly2->add(*pi);
	}
    }
#if 0
    cout << "a:\n" << *poly1;
    cout << "b:\n" << *poly2;
#endif
    if (poly1->area() == 0) {
      npolys = 0;
      return;
    }
    else if (poly2->area() == 0) {
      npolys = 0;
      return;
    }

    PolyPList a_min_b, b_min_a, a_and_b;
    clip_poly(*poly1, *poly2, a_min_b, b_min_a, a_and_b);
#if 0
    cout << "a_min_b:\n" << a_min_b;
    cout << "b_min_a:\n" << b_min_a;
    cout << "a_and_b:\n" << a_and_b;
#endif
#if 0
    cout << "A_MIN_B:" << endl;
    for (i = 0; i < a_min_b.length(); i++) {
	Poly* poly = a_min_b[i];
	cout << "poly " << i << ":" << endl;
	const PolyNode* node;
	int n = 0;
	for (node = poly->firstnode();
	     node && (n == 0 || node != poly->firstnode());
	     node = poly->nextnode(node), n++)
	    cout << node->point().x() << " " << node->point().y() << endl;
	cout << endl;
    }
    cout << "B_MIN_A:" << endl;
    for (i = 0; i < b_min_a.length(); i++) {
	Poly* poly = b_min_a[i];
	cout << "poly " << i << ":" << endl;
	const PolyNode* node;
	int n = 0;
	for (node = poly->firstnode();
	     node && (n == 0 || node != poly->firstnode());
	     node = poly->nextnode(node), n++)
	    cout << node->point().x() << " " << node->point().y() << endl;
	cout << endl;
    }
    cout << "A_AND_B:" << endl;
    for (i = 0; i < a_and_b.length(); i++) {
	Poly* poly = a_and_b[i];
	cout << "poly " << i << ":" << endl;
	const PolyNode* node;
	int n = 0;
	for (node = poly->firstnode();
	     node && (n == 0 || node != poly->firstnode());
	     node = poly->nextnode(node), n++)
	    cout << node->point().x() << " " << node->point().y() << endl;
	cout << endl;
    }
#endif
    switch (op) {
    case A_MIN_B:
	{
	    npolys = a_min_b.length();
	    x = new float*[npolys];
	    y = new float*[npolys];
	    ni = new int[npolys];
	    PolyPListIter iter(a_min_b);
	    for (i = 0; iter(); i++) {
		Poly* poly = iter.val();
		const PolyNode* node;
		int n = 0;
		for (node = poly->firstnode();
		     node && (n == 0 || node != poly->firstnode());
		     node = poly->nextnode(node), n++)
		    ;
		ni[i] = n;
		x[i] = new float[n];
		y[i] = new float[n];
		n = 0;
		int j = 0;
		for (j = 0, node = poly->firstnode();
		     node && (n == 0 || node != poly->firstnode());
		     j++, node = poly->nextnode(node), n++) {
		    x[i][j] = node->point().x();
		    y[i][j] = node->point().y();
		}
	    }
	}
	break;
    case B_MIN_A:
	{
	    npolys = b_min_a.length();
	    x = new float*[npolys];
	    y = new float*[npolys];
	    ni = new int[npolys];
	    PolyPListIter iter(b_min_a);
	    for (i = 0; iter(); i++) {
		Poly* poly = iter.val();
		const PolyNode* node;
		int n = 0;
		for (node = poly->firstnode();
		     node && (n == 0 || node != poly->firstnode());
		     node = poly->nextnode(node), n++)
		    ;
		ni[i] = n;
		x[i] = new float[n];
		y[i] = new float[n];
		n = 0;
		int j = 0;
		for (j = 0, node = poly->firstnode();
		     node && (n == 0 || node != poly->firstnode());
		     j++, node = poly->nextnode(node), n++) {
		    x[i][j] = node->point().x();
		    y[i][j] = node->point().y();
		}
	    }
	}
	break;
    case A_AND_B:
	{
	    npolys = a_and_b.length();
	    x = new float*[npolys];
	    y = new float*[npolys];
	    ni = new int[npolys];
	    PolyPListIter iter(a_and_b);
	    for (i = 0; iter(); i++) {
		Poly* poly = iter.val();
		const PolyNode* node;
		int n = 0;
		for (node = poly->firstnode();
		     node && (n == 0 || node != poly->firstnode());
		     node = poly->nextnode(node), n++)
		    ;
		ni[i] = n;
		x[i] = new float[n];
		y[i] = new float[n];
		n = 0;
		int j = 0;
		for (j = 0, node = poly->firstnode();
		     node && (n == 0 || node != poly->firstnode());
		     j++, node = poly->nextnode(node), n++) {
		    x[i][j] = node->point().x();
		    y[i][j] = node->point().y();
		}
	    }
	}
	break;
    default:
	cerr << "Error: uknown clippoly operation" << endl;
	break;
    }

}