扫描线算法代码.doc

扫描线算法代码.doc

ID:57648010

大小:40.00 KB

页数:5页

时间:2020-08-30

扫描线算法代码.doc_第1页
扫描线算法代码.doc_第2页
扫描线算法代码.doc_第3页
扫描线算法代码.doc_第4页
扫描线算法代码.doc_第5页
资源描述:

《扫描线算法代码.doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库

1、#include#include#include"stdlib.h"voidinit(void){glClearColor(1.0,1.0,1.0,0.0);//指定清空颜色(背景色)为白色glMatrixMode(GL_PROJECTION);//指定投影矩阵gluOrtho2D(0.0,400.0,0.0,400.0);//指定二维坐标系中被显示的区域}typedefstructtEdge{intyUpper;floatxIntersect,dxPerScan;structtE

2、dge*next;}Edge;structdcPt{//dcPt实际上是一个点的结构体intx;inty;};voidsetPixel(GLintx,GLinty){glBegin(GL_POINTS);glVertex2i(x,y);glEnd();}/*InsertsedgeintolistinorderofincreasingxIntersectfield.*/voidinsertEdge(Edge*list,Edge*edge){Edge*p,*q=list;p=q->next;while(p!=NULL){if

3、(edge->xIntersectxIntersect)p=NULL;else{q=p;p=p->next;}}edge->next=q->next;q->next=edge;}/*Foranindex,returny-coordinateofnextnonhorizontalline*/intyNext(intk,intcnt,dcPt*pts){intj;if((k+1)>(cnt-1))j=0;elsej=k+1;while(pts[k].y==pts[j].y)if((j+1)>(cnt-1))j=0;e

4、lsej++;return(pts[j].y);}/*Storelower-ycoordinateandinverseslopeforeachedge.Adjustandstoreupper-ycoordinateforedgesthatarethelowermemberofamonoticallyincreasingordecreasingpairofedges*/voidmakeEdgeRec(dcPtlower,dcPtupper,intyComp,Edge*edge,Edge*edges[]){edge->dxP

5、erScan=(float)(upper.x-lower.x)/(upper.y-lower.y);edge->xIntersect=lower.x;if(upper.yyUpper=upper.y-1;elseedge->yUpper=upper.y;insertEdge(edges[lower.y],edge);}voidbuildEdgeList(intcnt,dcPt*pts,Edge*edges[]){Edge*edge;dcPtv1,v2;inti,yPrev=pts[cnt-2].

6、y;v1.x=pts[cnt-1].x;v1.y=pts[cnt-1].y;for(i=0;i

7、edges);}yPrev=v1.y;v1=v2;}}voidbuildActiveList(intscan,Edge*active,Edge*edges[]){Edge*p,*q;p=edges[scan]->next;while(p){q=p->next;insertEdge(active,p);p=q;}}voidfillScan(intscan,Edge*active){Edge*p1,*p2;inti;p1=active->next;while(p1){p2=p1->next;for(i=p1->xInters

8、ect;ixIntersect;i++)setPixel((int)i,scan);p1=p2->next;}}voiddeleteAfter(Edge*q){Edge*p=q->next;q->next=p->next;free(p);}/*Deletecompletededges.Update'xInt

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。