1、/实验屏幕使用int i,j,c;double x,y,pi,t;pi=3.1416;/ for(i=0;iSetPixel(i,j,i*j);for(i=0;iSetPixel(i,j,c);/画有颜色的色块long int c8;c0=RGB(200,200,200);c1=RGB(255,0,0);c2=RGB(0,255,0);c3=RGB(0,0,255);c4=RGB(255,255,0); c5=RGB(255,0,255);c6=RGB(0,255,255);c7=RGB(0,0,0);int k=0;for(int i=10;iSetPixel(x,y,ck);k+;if(k
2、7)k=0;/ 画任意的函数,以 x=cos(2*pi*t),y=sin(2*pi*t)的 1/4,1/2,1,2,4 次乘方为例。double pi,t,x0,y0,x1,y1,x2,y2,x3,y3,x4,y4;pi=3.1415926535;for(t=0;tSetPixel(400.0+150*x2,200+150*y2,RGB(255,0,0);x3=x2*x2;y3=y2*y2;pDC-SetPixel(400.0+150*x3,200+150*y3,RGB(255,255,0);x4=x3*x2;y4=y3*y2;pDC-SetPixel(400.0+150*x4,200+150
3、*y4,RGB(0,255,0); x1=sqrt(x2);y2=sqrt(y2);pDC-SetPixel(400.0+150*x1,200+150*y1,RGB(0,255,255); x0=sqrt(x1);y0=sqrt(y1);pDC-SetPixel(400.0+150*x0,200+150*y0,RGB(0,0,255); /画一个填充颜色 cl 的正方形,角点(s,t),大小 k*kvoid CW6View:fillrect(CDC *p, int s, int t, int k,int cl)int i,j;for(i=s;iSetPixel(i,j,RGB(255,0,0)
4、;else if(cl=2) p-SetPixel(i,j,RGB(255,255,0);else p-SetPixel(i,j,RGB(0,0,255);/角点(sx,sy),长 n, k*k 的棋盘格void CW6View:checkerbord(CDC *p, int sx, int sy, int n,int k)int i,j,l;double tx,ty;tx=sx;ty=sy;l=int(double)n/(double)k+0.5);for(i=0;i= sx+n) tx=sx;ty=ty+l;/DDA 算法void CW1View:dda(int x0,int y0,int
5、 x1,int y1,CDC *pDC)double dx,dy,e,x,y;dx=x1-x0;dy=y1-y0;e=(fabs(dx)fabs(dy)? fabs(dx):fabs(dy);dx=dx/e;dy=dy/e;x=x0;y=y0;for(int i=1;iSetPixel(int)(x+0.5),(int)(y+0.5),RGB(255,0,0);x=x+dx;y=y+dy;/推广 DDA 增量法画抛物线,?处用自己的名字void C?View:dda2(float a, float b, float c, float x0, float x1, float d, CDC *pD
6、C)float x,y,d1,d2;x=x0;y=a*x*x+b*x+c;d1=2.0*a*x*d+a*d*d+b*d;d2=2.0*a*d*d;while(xSetPixel(x+480,y+440,RGB(0,0,255);x=x+d;y=y+d1;d1=d1+d2;/没有限制条件的中点画线法完整程序void CC8View:midline(int x0, int y0, int x1, int y1,CDC *p)int i,a,b,d1,d2,d,x,y;if(x0=x1)if(y0SetPixel(x0,i,RGB(0,0,0); else for(i=y1;iSetPixel(x0
7、,i,RGB(0,0,0);return;if(x0x1)d=x0;x0=x1;x1=d;d=y0;y0=y1;y0=d;a=y0-y1;b=x1-x0;x=x0;y=y0;p-SetPixel(x,y,RGB(0,0,0);BOOL m=(fabs(y1-y0) SetPixel(x,y,RGB(0,0,0);else d=2*a-b;d1=2*a;d2=2*(a-b);while(xSetPixel(x,y,RGB(0,0,0);elseif(y0SetPixel(x,y,RGB(0,0,0);else d=a-2*b;d1=-2*b;d2=2*(a-b);while(yy1)if(dSe
8、tPixel(x,y,RGB(0,0,0);/没有限制条件的 Bresenham 画线算法完整程序void CC8View:Bresenham(int x0, int y0, int x1, int y1, CDC *pDC)int i,d,x,y,dx,dy,p;if(x0=x1)if(y0SetPixel(x0,i,RGB(0,0,0); else for(i=y1;iSetPixel(x0,i,RGB(0,0,0);return;if(x0x1)d=x0;x0=x1;x1=d;d=y0;y0=y1;y1=d;x=x0;y=y0;dx=x1-x0;dy=y1-y0;BOOL m=(fabs
9、(y1-y0) SetPixel(x,y,RGB(0,0,0);if(pSetPixel(x,y,RGB(0,0,0);if(pSetPixel(x,y,RGB(0,0,0);if(p=y1)pDC-SetPixel(x,y,RGB(0,0,0);if(pMoveTo(xi,yi);pDC-LineTo(xj,yj);/画五角星,?处用自己的名字void C?View:wujiaoxing(int x0,int y0,int rr,CDC *pDC)int n,i;double t,pi,x40,y40;pi=3.1415926535;n=20;t=2.0*pi/n;t=0.1*pi;for
10、(i=0;iMoveTo(x0,y0);pDC-LineTo(x2,y2);pDC-LineTo(x4,y4);/pDC-LineTo(x1,y1);pDC-LineTo(x3,y3);pDC-LineTo(x0,y0);/画箭头void jiantou(int x0,int y0,int x1,int y1,CDC *pDC)double x2,y2,x3,y3,x4,y4;x2=x0+0.9*(x1-x0);y2=y0+0.9*(y1-y0);x3=x2+0.05*(y1-y0);y3=y2+0.05*(x0-x1);x4=x2-0.05*(y1-y0);y4=y2-0.05*(x0-x1
11、);dda(x0,y0,x1,y1,pDC);dda(x3,y3,x1,y1,pDC);dda(x4,y4,x1,y1,pDC);for(double s=0.0;sMoveTo(x1,y1);pDC-LineTo(x2,y2);pDC-MoveTo(x4,y4);pDC-LineTo(x5,y5); /Cohen_Sutherland 裁剪算法的编码部分int encode(int x,int y,int xl,int xr,int yb,int yt) int code4,c;code0=(yyt)? 1:0; code1=(yxr)? 1:0; code3=(xMoveTo(xs,y);
12、p-LineTo(xe,y);if(y=y1 if(y=y1 xs=xs+n*m0;xe=xe+n*m1;if(xsxe)t=xs;xs=xe;xe=t;t=m0;m0=m1;m1=t;/多边形扫描转换算法,共 4 个函数void CC9View:GetET(PT poly,int pcount) /构造边表EDGE *pHead=NULL;EDGE *p=NULL;for(int i=0;ifm=(double)(pp2.x-pp1.x)/(pp2.y-pp1.y);if(pp1.ypp2.y)edge-ymax=pp1.y;edge-ymin=pp2.y;edge-xmin=pp2.x;e
13、lse edge-ymax=pp2.y;edge-ymin=pp1.y;edge-xmin=pp1.x;edge-next=NULL;edge-last=NULL; /构造边表 ETif( p = NULL) pHead=edge;p=edge; else p-next=edge;edge-last=p;p=edge; p=pHead; /下面判断局部极大极小并缩短相应的边EDGE* pNext = NULL;while(p != NULL) if(p-next = NULL) pNext=pHead; else pNext=p-next;/如果没有下一条边则和第一条边比较if(p-ymin
14、!= pNext-ymin p-xmin+=p-fm; else pNext-ymin+;pNext-xmin+=pNext-fm;/缩短 ymax 值大的边p=p-next;SortET(pHead); /边表按输入顶点形成各边的次序进入构造,所以要按 ymin 重排序pAT=pHead; /结果用全局变量 pAT 带回。void CC9View:Polygonfill(CDC *pDC, PT poly,int pcount)/多边形填充的主程序GetET(poly,pcount); /调用 GetET 构造边表,全局变量 pAT 带回,送 pET。EDGE* pET=pAT; EDGE*
15、 p;EDGE* pAET=NULL;int y=pET-ymin; /最小 y 值int ymax=pET-ymax;/最大 y 值,随新边加入更新至真正最大while(yymin = y)/ET 表不空,且与当前边的 ymin 即当前扫描线相等,当前边移动到 AET 表中p=pET; /获得当前边pET=pET-next; /ET 指针后移p-next=NULL; /不连接到下一条边,以免重新连回到 ET表if(pAET = NULL) pAET=p; else pAET-next=p;p-last=pAET;pAET=p; /加入到 AET 表,连接当前边上一条边为 AET 表原有最后一
16、条边if(ymaxymax) ymax=pAET-ymax;/根据新进入边修改 ymax 值while(pAET-last != NULL)pAET=pAET-last;/找到 AET 的第一条边SortA(pAET); /AET 表排序EDGE* pFill=pAET;while(pFill != NULL)for(inti=(int)pFill-xmin;inext-xmin;i+) pDC-SetPixel(i,y,RGB(255,0,0); /填充当前边和下一条边间的区间pFill=pFill-next-next; /AET 表中边成对处理pFill=pAET;/将 AET 表中 ym
17、ax 为当前扫描线的边清除出表while(pFill != NULL)if(pFill-ymax = y) /ymax 为当前扫描线if(pFill-last != NULL)pFill-last-next=pFill-next; else pAET=pFill-next;/区分当前边在 AET 中有没有上一条边if(pFill-next != NULL) pFill-next-last=pFill-last;/当前边在 AET 中有下一条边EDGE* pdelete=pFill; /销毁清除的边对象pFill=pFill-next; /移动到下一条边 delete pdelete;else
18、pFill=pFill-next;/移动到下一条边 if(pAET != NULL) /AET 表中仍然有边pFill=pAET; /重新计算 AET 表中各边的 xmin 值while (pFill != NULL)pFill-xmin+=pFill-fm;pFill=pFill-next;SortA(pAET); /排序while(pAET-next != NULL) pAET=pAET-next;y+;/去处理下一条扫描线void CC9View:SortET(EDGE *pEDGE) /初始构造的边表排序EDGE* p1=pEDGE;/要排序链表中第一条边EDGE* p2=NULL;
19、/第一条边的下一条边while( p1 != NULL)p2=p1-next;while(p2 != NULL)if(p1-ymin p2-ymin | (p1-ymin = p2-ymin double cdd; /交换cid=p1-ymax;p1-ymax=p2-ymax;p2-ymax=cid;cid=p1-ymin;p1-ymin=p2-ymin;p2-ymin=cid;cdd=p1-xmin;p1-xmin=p2-xmin;p2-xmin=cdd;cdd=p1-fm;p1-fm=p2-fm;p2-fm=cdd;p2=p2-next;p1=p1-next;void CC9View:So
20、rtA(EDGE *pEDGE) /活动边表排序EDGE* p1=pEDGE;EDGE* p2=NULL;while( p1 != NULL)p2=p1-next;while(p2 != NULL)if(p1-xmin p2-xmin)/若前边的 xmin 大于后边的 xmin,int cid;double cdd;/交换cid=p1-ymax;p1-ymax=p2-ymax;p2-ymax=cid;cid=p1-ymin;p1-ymin=p2-ymin;p2-ymin=cid;cdd=p1-xmin;p1-xmin=p2-xmin;p2-xmin=cdd;cdd=p1-fm;p1-fm=p2
21、-fm;p2-fm=cdd;p2=p2-next;p1=p1-next;void CW4View:OnDraw(CDC* pDC) /多边形扫描转换的主程序,在 OnDraw 中填加 /另外, PT 和 EDGE 做为成员变量加入 struct PTPOINT p;/struct EDGE int ymin;int ymax;double xmin;double fm;EDGE *next;EDGE *last; *pAT;CW4Doc* pDoc = GetDocument();ASSERT_VALID(pDoc);/ TODO: add draw code for native data
22、hereint i;pp0.p.x=100;pp0.p.y=500;pp1.p.x=400;pp1.p.y=10;pp2.p.x=800;pp2.p.y=300;pp3.p.x=800;pp3.p.y=600;pp4.p.x=600;pp4.p.y=300;pp5.p.x=500;pp5.p.y=500;pp6.p.x=600;pp6.p.y=200;pp7.p.x=400;pp7.p.y=600;pp8.p.x=300;pp8.p.y=500;pp9.p.x=400;pp9.p.y=200;pp10.p.x=100;pp10.p.y=500;pDC-MoveTo(pp0.p.x,pp0.p.
23、y);for(i=1;iLineTo(ppi.p.x,ppi.p.y);polyfill(pDC,pp,11);/裁剪程序的主程序部分xl=200;xr=500;yb=200;yt=400;pDC-MoveTo(xl,yb);pDC-LineTo(xr,yb);pDC-LineTo(xr,yt);pDC-LineTo(xl,yt); pDC-LineTo(xl,yb);CSclip(pDC,20,100,600,500);/Cohen-Sutherland 直线段裁剪算法void CC10View:CSclip(CDC *p, double x0, double y0, double x1,
24、double y1) int c,c1,c2;double x,y; p-Ellipse(x0-5,y0-5,x0+5,y0+5); p-Ellipse(x1-5,y1-5,x1+5,y1+5);c1=makecode(x0,y0);c2=makecode(x1,y1);while(c1 != 0 | c2 != 0)if(c1 c=c1;if(!c)c=c2; / c3=c if(c x=xl;else if(c x=xr;else if(c y=yb;else if(c y=yt;if(c = c1)x0=x;y0=y;c1=makecode(x,y);else x1=x;y1=y;c2=
25、makecode(x,y); p-MoveTo(x0,y0);p-LineTo(x1,y1);int CC10View:makecode(double x, double y) /Cohen-Sutherland 直线段裁剪的编码 int c=0;if(xxr) c=2;if(yyt) c=c+8;return(c);void CW1View:makecode(double x,double y,int *c) /C-S 直线段裁剪编码另一方式 *c=0;if(xxr) *c=2;if(yyt) *c=*c+8;/修改 Cohen-Sutherland 直线段裁剪为开窗void CC10Vie
26、w:CSopenw(CDC *p, int x1, int y1, int x2, int y2)int c,c1,c2,c3;double x,y; p-Ellipse(x1-5,y1-5,x1+5,y1+5); p-Ellipse(x2-5,y2-5,x2+5,y2+5);c1=makecode(x1,y1);c2=makecode(x2,y2);while(!(c1 c=c1;if(!c)c=c2;if(c x=xl;else if(c x=xr;else if(c y=yb;else if(c y=yt;if(c = c1) p-MoveTo(x1,y1);p-LineTo(x,y);
27、x1=x;y1=y;c1=makecode(x,y);else p-MoveTo(x,y);p-LineTo(x2,y2);x2=x;y2=y;c2=makecode(x,y); p-MoveTo(x1,y1);p-LineTo(x2,y2);/从重心向外用画三角形逐渐填充整个三角形void CW2View:tri2(CDC *p, int x0, int y0, int x1, int y1, int x2, int y2)double x4,y4,x5,y5,x6,y6,x7,y7,t;int n;n=5;x4=(x1+x2+x0)/3.0;y4=(y1+y2+y0)/3.0;for(t=
28、0;tMoveTo(x5,y5);p-LineTo(x6,y6);p-LineTo(x7,y7);p-LineTo(x5,y5);/画一个填充颜色的正方形void CW6View:fillrect(CDC *p, int s, int t, int k,int cl) int i,j;long c8;c0=RGB(255,0,0); c1=RGB(0,255,0); c2=RGB(0,0,255);c3=RGB(255,255,0);c4=RGB(0,255,255);c5=RGB(255,0,255);c6=RGB(255,255,255);c7=RGB(100,100,100);for(i
29、=s;iSetPixel(i,j,ccl);/角点(sx,sy),长 n, k*k 的棋盘格void CW6View:checkerbord(CDC *p, int sx, int sy, int n,int k) int i,j,l;double tx,ty;tx=sx;ty=sy;l=int(double)n/(double)k+0.5);for(i=0;i= sx+n) tx=sx;ty=ty+l;/画一个菱形块,左侧顶点在(x, y) ,水平长度 d,用颜色 clvoid CW4View:diamond(CDC *p, double x, double y, double d,int
30、cl)double s,t,xx,yy,x0,y0,x1,y1,x2,y2,x3,y3;long c8;c0=RGB(255,0,0); c1=RGB(0,255,0); c2=RGB(0,0,255);c3=RGB(255,255,0);c4=RGB(0,255,255);c5=RGB(255,0,255);c6=RGB(255,255,255);c7=RGB(100,100,100);x0=x;y0=y;x1=x0+0.5*d;y1=y-0.5*d;x2=x0+d;y2=y0;x3=x0+0.5*d;y3=y0+0.5*d;for(s=0.0;sSetPixel(xx,yy,ccl);/填
31、充一个由菱形块组成的“菱形块 k*k 棋盘格” ,左角点 (x, y), 水平总长 dvoid CW4View:kdiamond(CDC *p, double x, double y, double d, int k) double s,t,xx,yy,x0,y0,x1,y1,x2,y2,x3,y3;int i,cc;cc=0;i=0;x0=x;y0=y;x1=x0+0.5*d;y1=y-0.5*d;x2=x0+d;y2=y0;x3=x0+0.5*d;y3=y0+0.5*d;d=d/(double)k);s=x0;t=y0; /这里 d 是每个小菱形块的水平长度while(i=x1-0.5)
32、s=x0=x0+0.5*d;t=y0=y0-0.5*d;x1=x1+0.5*d;if(!(k%2)cc+;/构造和绘制自定义的图案int a8=3,3,3,3,3,3,3,3,3,0,0,0,0,0,0,3,3,0,0,1,1,0,0,3,3,0,1,1,1,1,0,3,3,0,1,1,1,1,0,3,3,0,0,1,1,0,0,3,3,0,0,0,0,0,0,3,3,3,3,3,3,3,3,3;int b8=0,0,0,1,1,3,3,3,1,1,1,1,1,1,1,1,0,0,0,1,1,3,3,3,0,1,1,1,1,1,1,3,0,0,0,0,3,3,3,3,0,1,1,1,1,1,1
33、,3,0,1,0,0,3,3,1,3,0,1,1,1,1,1,1,3;int c8=0,3,3,3,3,3,3,0,3,0,1,0,0,1,0,3,1,0,0,0,0,0,0,1,1,0,0,1,1,0,0,1,3,0,0,1,1,0,0,3,3,0,0,0,0,0,0,3,3,0,1,1,1,1,0,3,0,3,3,3,3,3,3,0;tuan(pDC,20,200,320,8,a);tuan(pDC,350,200,320,8,b);tuan(pDC,690,200,320,8,c);void CW6View:pattern(CDC *p, int s, int t, int n, int
34、 k, int aa8)int i,j,l;double tx,ty;tx=s;ty=t;l=int(double)n/(double)k+0.5);for(i=0;i= s+n) tx=s;ty=ty+l;/画一个四边形,顶点坐标在 x,y 数组,?处用自己的名字void C?View:rect(CDC *p,double x,double y,int n)int i;xn=x0;yn=y0;p-MoveTo(xwtov(x0),ywtov(y0);for(i=1;iLineTo(xwtov(xi),ywtov(yi);/平移、比例、旋转变换rect(pDC,x,y,4);for(i=0;i
35、MoveTo(x1,y1);pDC-LineTo(x2,y2);pDC-MoveTo(x4,y4);pDC-LineTo(x5,y5); /正方形绕中心旋转形成环形图案cs=cos(pi/36.0);sn=sin(pi/36.0);for(i=0;iSetPixel(sx+xwtov(xx),sy+ywtov(yy),RGB(255,0,0);pDC-SetPixel(sx+xwtov(xx),sy+ywtov(-yy),RGB(255,0,0);pDC-SetPixel(sx+xwtov(yy),sy+ywtov(xx),RGB(255,0,0);pDC-SetPixel(sx+xwtov(
36、yy),sy+ywtov(-xx),RGB(255,0,0);sx=sx+200;if (sx800) sx=-250;sy=sy+170;/给出画一个齿的数据,旋转 20 次,画出一个齿轮:xmin=40;xmax=240;ymin=0;ymax=200; double x=156.4,145.5,145.5,135.5,135,5,156.4;double y=26.7,25,14,14,25,26;double xb10,yb10;pDC-MoveTo(xwtov(x0),ywtov(y0);for( i=1;iLineTo(xwtov(xi),ywtov(yi);double sn=s
37、in(0.1*pi),cs=cos(0.1*pi);for(n=1;nLineTo(xwtov(xbi),ywtov(ybi);for(i=0;iMoveTo(320,200-y);p-LineTo(320-x,200);p-LineTo(320,200+y);p-LineTo(320+x,200);p-LineTo(320,200-y);/平移、放缩、旋转、正平行投影(三视图) 、一点透视投影在一起 int i;double pi;double x10=0.0,1.0,1.0,0.0;/定义一个正方形double y10=0.0,0.0,1.0,1.0;int es=0,1,0,0,1,2,
38、3,4,3;int ed=1,2,2,3,4,5,4,5,5; double xb10,yb10,z10;int a=8,b=7,tx=1,ty=2,tz=3; double u10,v10;double l,m,n,zprp,uu;xmin=0.0;xmax=15.0;ymin=-4.0;ymax=11.0;rect(pDC,x,y,4);/画原正方形for(i=0;iMoveTo(xwtov(a),ywtov(ymin);pDC-LineTo(xwtov(a),ywtov(ymax);pDC-MoveTo(xwtov(xmin),ywtov(b);pDC-LineTo(xwtov(xmax
39、),ywtov(b);for(i=0;iMoveTo(xwtov(uesi),ywtov(vesi);pDC-LineTo(xwtov(uedi),ywtov(vedi);for(i=0;iMoveTo(xwtov(uesi),ywtov(vesi);pDC-LineTo(xwtov(uedi),ywtov(vedi);for(i=0;iMoveTo(xwtov(uesi),ywtov(vesi);pDC-LineTo(xwtov(uedi),ywtov(vedi);l=m=n=0;zprp=10;/一点透视投影,没有平移,l,m,n 赋值就有了。for(i=0;iMoveTo(xwtov(x
40、besi)+400,ywtov(ybesi);pDC-LineTo(xwtov(xbedi)+400,ywtov(ybedi);/一点透视,没有平移xmin=-2;xmax=2;ymin=-2;ymax=2;double x=1,-1,-1,1,1,-1,-1,1;double y=-1,-1,1,1,-1,-1,1,1;double z=1,1,1,1,-1,-1,-1,-1;double zp=10,zv=0,d=10;double h,t,xb10,yb10;int i;for(i=0;iMoveTo(xwtov(xb0),ywtov(yb0);pDC-LineTo(xwtov(xb1)
41、,ywtov(yb1);pDC-LineTo(xwtov(xb2),ywtov(yb2);pDC-LineTo(xwtov(xb3),ywtov(yb3);pDC-LineTo(xwtov(xb0),ywtov(yb0);pDC-LineTo(xwtov(xb4),ywtov(yb4);pDC-LineTo(xwtov(xb5),ywtov(yb5);pDC-LineTo(xwtov(xb6),ywtov(yb6);pDC-LineTo(xwtov(xb7),ywtov(yb7);pDC-LineTo(xwtov(xb4),ywtov(yb4);pDC-MoveTo(xwtov(xb1),yw
42、tov(yb1);pDC-LineTo(xwtov(xb5),ywtov(yb5);pDC-MoveTo(xwtov(xb2),ywtov(yb2);pDC-LineTo(xwtov(xb6),ywtov(yb6);pDC-MoveTo(xwtov(xb3),ywtov(yb3);pDC-LineTo(xwtov(xb7),ywtov(yb7);/一点透视,加入平移,画一个立方体。 。xmin=0;xmax=2;ymin=-2;ymax=0;double l=0.8,m=-1.6,n=-2.0,d=2.5;double x=0,1,1,0,0,1,1,0;double y=0,0,1,1,0,
43、0,1,1;double z=0,0,0,0,1,1,1,1;for(i=0;iMoveTo(xwtov(xb0),ywtov(yb0);pDC-LineTo(xwtov(xb1),ywtov(yb1);pDC-LineTo(xwtov(xb2),ywtov(yb2);pDC-LineTo(xwtov(xb3),ywtov(yb3);pDC-LineTo(xwtov(xb0),ywtov(yb0);pDC-LineTo(xwtov(xb4),ywtov(yb4);pDC-LineTo(xwtov(xb5),ywtov(yb5);pDC-LineTo(xwtov(xb6),ywtov(yb6);
44、pDC-LineTo(xwtov(xb7),ywtov(yb7);pDC-LineTo(xwtov(xb4),ywtov(yb4);pDC-MoveTo(xwtov(xb1),ywtov(yb1);pDC-LineTo(xwtov(xb5),ywtov(yb5);pDC-MoveTo(xwtov(xb2),ywtov(yb2);pDC-LineTo(xwtov(xb6),ywtov(yb6);pDC-MoveTo(xwtov(xb3),ywtov(yb3);pDC-LineTo(xwtov(xb7),ywtov(yb7);/深度缓冲区算法的运行例子,struct point3d double
45、x,y,z; p6=20.0,250.0,1.0,230,100,10,50,20,1,10,180,5,254,255,5,254,10,5;/六个顶点确定了两个空间三角形,z 坐标对应深度。long colorb250250;/ “貞”缓冲区,或叫颜色缓冲区。double depthb250250;/深度缓冲区。int i,j;double r,s,t,xx,yy,zz;CClientDC dc(this);/下句两个缓冲区送初值。for(i=0;iMoveTo(xwtov(x0),ywtov(y0);p-LineTo(xwtov(x1),ywtov(y1);p-LineTo(xwtov(
46、x2),ywtov(y2);p-LineTo(xwtov(x3),ywtov(y3);for(t=0;tSetPixel(xwtov(xx),ywtov(yy),RGB(255,0,0);/decas 算法void CW4View:decas(int n, double xx, double yy, double t, double *xout, double *yout) int k,i;double xb10,yb10;for(i=0;iGetDC();CString s1,s2,s3;int x,y;x=point.x;y=point.y;p-Ellipse(x-5,y-5,x+5,y+5);/画出输入的点并显示坐标数值s1.Format(“(%d,“,x);p-TextOut(x,y+10,s1);s2.Format(“%d)“,y);p-TextOut(x+30,y+10,s2);xxcount=x;yycount=y;s3.Format(“c=%d“,count);p-TextOut(x+60,y+10