计算机图形学Cohen-Sutherland直线裁剪算法实验

计算机图形学Cohen-Sutherland直线裁剪算法实验

ID:46899995

大小:274.50 KB

页数:10页

时间:2019-11-29

计算机图形学Cohen-Sutherland直线裁剪算法实验_第1页
计算机图形学Cohen-Sutherland直线裁剪算法实验_第2页
计算机图形学Cohen-Sutherland直线裁剪算法实验_第3页
计算机图形学Cohen-Sutherland直线裁剪算法实验_第4页
计算机图形学Cohen-Sutherland直线裁剪算法实验_第5页
资源描述:

《计算机图形学Cohen-Sutherland直线裁剪算法实验》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库

1、《计算机图形学实验》报告任课教师:钱文华2016年春季学期实验:Cohen-Sutherland直线裁剪算法实验时间:2016年11月3日实验地点:信息学院2204实验目的:掌握Cohen-Sutherland直线裁剪算法程序代码:#include#include#include#include#include#include#includeinta,b,a1,b1,p

2、p0,pq0,pp1,pq1;voidsetPixel(GLintx,GLinty){glBegin(GL_POINTS);glVertex2i(x,y);glEnd();}voidinit(void){glClearColor(1.0,1.0,1.0,0.0);glMatrixMode(GL_PROJECTION);gluOrtho2D(0.0,200.0,0.0,150.0);}voidLineDDA(intx0,inty0,intxEnd,intyEnd){intdx=xEnd-x0;int

3、dy=yEnd-y0;intsteps,k;floatxIncrement,yIncrement,x=x0,y=y0;if(abs(dx)>abs(dy))steps=abs(dx);elsesteps=abs(dy);xIncrement=float(dx)/float(steps);yIncrement=float(dy)/float(steps);for(k=0;k

4、swcPt2D{public:GLfloatx,y;};inlineGLintround(constGLfloata){returnGLint(a+0.5);}constGLintwinLeftBitCode=0x1;constGLintwinRightBitCode=0x2;constGLintwinBottomBitCode=0x4;constGLintwinTopBitCode=0x8;inlineGLintinside(GLintcode){returnGLint(!code);}inli

5、neGLintreject(GLintcode1,GLintcode2){returnGLint(code1&code2);}inlineGLintaccept(GLintcode1,GLintcode2){returnGLint(!(code1

6、code2));}GLubyteencode(wcPt2Dpt,wcPt2DwinMin,wcPt2DwinMax){GLubytecode=0x00;if(pt.x

7、winLeftBitCode;if(pt.x>w

8、inMax.x)code=code

9、winRightBitCode;if(pt.y

10、winBottomBitCode;if(pt.y>winMax.y)code=code

11、winTopBitCode;return(code);}voidswapPts(wcPt2D*p1,wcPt2D*p2){wcPt2Dtmp;tmp=*p1;*p1=*p2;*p2=tmp;}voidswapCodes(GLubyte*c1,GLubyte*c2){GLubytetmp;tm

12、p=*c1;*c1=*c2;*c2=tmp;}voidlineClipCohSuth(wcPt2DwinMin,wcPt2DwinMax,wcPt2Dp1,wcPt2Dp2){GLubytecode1,code2;GLintdone=false,plotLine=false;GLfloatm;intx0=0;inty0=0;intx1=0;inty1=0;while(!done){code1=encode(p1,winMin,winMax);code2=encode(p2,winMin,winMa

13、x);if(accept(code1,code2)){done=true;plotLine=true;}//简取elseif(reject(code1,code2))//简弃done=true;else{if(inside(code1)){swapPts(&p1,&p2);swapCodes(&code1,&code2);}if(p2.x!=p1.x)m=(p2.y-p1.y)/(p2.x-p1.x);//计算kif(code1&winLeftBitCode){p1.y+=(win

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

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

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