計(jì)算機(jī)圖形學(xué)實(shí)驗(yàn)報(bào)告_第1頁(yè)
計(jì)算機(jī)圖形學(xué)實(shí)驗(yàn)報(bào)告_第2頁(yè)
計(jì)算機(jī)圖形學(xué)實(shí)驗(yàn)報(bào)告_第3頁(yè)
計(jì)算機(jī)圖形學(xué)實(shí)驗(yàn)報(bào)告_第4頁(yè)
計(jì)算機(jī)圖形學(xué)實(shí)驗(yàn)報(bào)告_第5頁(yè)
已閱讀5頁(yè),還剩45頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

計(jì)算機(jī)圖形學(xué)實(shí)驗(yàn)報(bào)告計(jì)算機(jī)圖形學(xué)實(shí)驗(yàn)報(bào)告姓名:學(xué)號(hào):班級(jí):專業(yè):計(jì)算機(jī)科學(xué)與技術(shù)完成日期:2017.1.3voidInitial(void){ glClearColor(1.0f,1.0f,1.0f,1.0f); glMatrixMode(GL_PROJECTION); gluOrtho2D(0.0,200.0,0.0,150.0);}voidDisplay(void){ glClear(GL_COLOR_BUFFER_BIT); glColor3f(1.0f,0.0f,0.0f); glRectf(50.0f,100.0f,150.0f,50.0f); glFlush();}intmain(intargc,char*argv[]){ glutInit(&argc,argv); glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB); glutInitWindowSize(400,300); glutInitWindowPosition(100,120); glutCreateWindow("矩形"); glutDisplayFunc(Display); Initial(); glutMainLoop(); return0;}畫點(diǎn)glPointSize(3);glBegin(GL_POINTS);glColor3f(1.0f,0.0f,0.0f);glVertex2i(10,140);glVertex2i(100,75); glVertex2i(190,10);glEnd();畫直線glPointSize(3);glBegin(GL_LINE_LOOP);glColor3f(1.0f,0.0f,0.0f);glVertex2i(20,10);glVertex2i(60,50); glVertex2i(20,50); glVertex2i(60,10); glVertex2i(40,70);glEnd();畫等邊三角形glPointSize(3);glBegin(GL_TRIANGLES);glColor3f(1.0f,0.0f,0.0f);glVertex2i(20,10);glVertex2i(60,10); glVertex2f(40.0,44.64);glEnd();實(shí)驗(yàn)二直線繪制實(shí)驗(yàn)實(shí)驗(yàn)?zāi)康暮蛯?shí)驗(yàn)內(nèi)容掌握數(shù)值微分算法編程繪制直線掌握中點(diǎn)畫線算法編程繪制直線掌握Bresenham算法編程繪制直線實(shí)驗(yàn)代碼和實(shí)驗(yàn)結(jié)果掌握數(shù)值微分算法編程繪制直線#include<gl/glut.h>#include<math.h>voidInitial(void){ glClearColor(1.0f,1.0f,1.0f,1.0f); glMatrixMode(GL_PROJECTION); gluOrtho2D(0.0,200.0,0.0,150.0);}voidDisplay(void){ glClear(GL_COLOR_BUFFER_BIT); glColor3f(1.0f,0.0f,0.0f); glPointSize(3); intdx,dy,epsl,k; floatx,y,xIncre,yIncre; intx0=10; inty0=10; intx1=20; inty1=80; dx=x1-x0; dy=y1-y0; x=x0; y=y0; if(abs(dx)>abs(dy)) epsl=abs(dx); else epsl=abs(dy); xIncre=(float)dx/(float)epsl; yIncre=(float)dy/(float)epsl; for(k=0;k<=epsl;k++){ glBegin(GL_POINTS); glVertex2i(int(x+0.5),(int)(y+0.5)); glEnd(); x+=xIncre; y+=yIncre; } glFlush();}intmain(intargc,char*argv[]){ glutInit(&argc,argv); glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB); glutInitWindowSize(400,300); glutInitWindowPosition(100,120); glutCreateWindow("矩形"); glutDisplayFunc(Display); Initial(); glutMainLoop(); return0;}掌握中點(diǎn)畫線算法編程繪制直線voidDisplay(void){ glClear(GL_COLOR_BUFFER_BIT); glColor3f(1.0f,0.0f,0.0f); glPointSize(3); intdx,dy,d,UpIncre,DownIncre,x,y; intx0=10; inty0=10; intx1=80; inty1=20; if(x0>x1){ x=x1;x1=x0;x0=x; y=y1;y1=y0;y0=y; } x=x0;y=y0; dx=x1-x0;dy=y1-y0; d=dx-2*dy; UpIncre=2*dx-2*dy; DownIncre=-2*dy; while(x<=x1){ glBegin(GL_POINTS); glVertex2f(x,y); glEnd(); x++; if(d<0){ y++; d+=UpIncre; } else d+=DownIncre; } glFlush();}掌握Bresenham算法編程繪制直線voidDisplay(void){ glClear(GL_COLOR_BUFFER_BIT); glColor3f(1.0f,0.0f,0.0f); glPointSize(3); intx,y,dx,dy,e; intx0=10; inty0=10; intx1=80; inty1=20; dx=x1-x0; dy=y1-y0; e=-dx;x=x0;y=y0; while(x<=x1){ glBegin(GL_POINTS); glVertex2f(x,y); glEnd(); x++; e=e+2*dy; if(e>0){ y++; e=e-2*dx; } } glFlush();}

實(shí)驗(yàn)三圓繪制實(shí)驗(yàn)實(shí)驗(yàn)?zāi)康暮蛯?shí)驗(yàn)內(nèi)容實(shí)現(xiàn)八分法畫圓程序?qū)崿F(xiàn)Bresenham算法繪制圓實(shí)現(xiàn)中點(diǎn)Bresenham算法繪制橢圓實(shí)驗(yàn)代碼實(shí)驗(yàn)結(jié)果實(shí)現(xiàn)八分法畫圓程序#include<gl/glut.h>#include<math.h>voidInitial(void){ glClearColor(1.0f,1.0f,1.0f,1.0f); glMatrixMode(GL_PROJECTION); gluOrtho2D(0.0,200.0,0.0,150.0);}voidputpixel(intx,inty){ x+=20; y+=20; glBegin(GL_POINTS); glVertex2i(x,y); glEnd();}voidCirclePoint(intx,inty){ putpixel(x,y); putpixel(y,x); putpixel(-y,x); putpixel(-x,y); putpixel(-x,-y); putpixel(-y,-x); putpixel(y,-x); putpixel(x,-y);}voidDisplay(void){ glClear(GL_COLOR_BUFFER_BIT); glColor3f(1.0f,0.0f,0.0f); glPointSize(3); CirclePoint(5,2); glFlush();}intmain(intargc,char*argv[]){ glutInit(&argc,argv); glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB); glutInitWindowSize(400,300); glutInitWindowPosition(100,120); glutCreateWindow("矩形"); glutDisplayFunc(Display); Initial(); glutMainLoop(); return0;}實(shí)現(xiàn)Bresenham算法繪制圓#include<gl/glut.h>#include<math.h>voidInitial(void){ glClearColor(1.0f,1.0f,1.0f,1.0f); glMatrixMode(GL_PROJECTION); gluOrtho2D(0.0,200.0,0.0,150.0);}voidputpixel(intx,inty){ x+=75; y+=75; glBegin(GL_POINTS); glVertex2i(x,y); glEnd();}voidCirclePoint(intx,inty){ putpixel(x,y); putpixel(y,x); putpixel(-y,x); putpixel(-x,y); putpixel(-x,-y); putpixel(-y,-x); putpixel(y,-x); putpixel(x,-y);}voidMidBressenhamCircle(intr){ intx,y,d; x=0;y=r;d=1-r; while(x<=y){ CirclePoint(x,y); if(d<0) d+=x*x+3; else{ d+=2*(x-y)+5; y--; } x++; }}voidDisplay(void){ glClear(GL_COLOR_BUFFER_BIT); glColor3f(1.0f,0.0f,0.0f); glPointSize(3); MidBressenhamCircle(50); glFlush();}intmain(intargc,char*argv[]){ glutInit(&argc,argv); glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB); glutInitWindowSize(400,300); glutInitWindowPosition(100,120); glutCreateWindow("矩形"); glutDisplayFunc(Display); Initial(); glutMainLoop(); return0;}實(shí)現(xiàn)中點(diǎn)Bresenham算法繪制橢圓#include<gl/glut.h>#include<math.h>voidInitial(void){ glClearColor(1.0f,1.0f,1.0f,1.0f); glMatrixMode(GL_PROJECTION); gluOrtho2D(0.0,200.0,0.0,150.0);}voidputpixel(intx,inty){ x+=100; y+=75; glBegin(GL_POINTS); glVertex2i(x,y); glEnd();}voidMidBressenhamElipse(inta,intb){ intx,y; floatd1,d2; x=0;y=b; d1=b*b+a*a*(-b+0.25); putpixel(x,y); putpixel(-x,-y); putpixel(-x,y); putpixel(x,-y); while(b*b*(x+1)<a*a*(y-0.5)){ if(d1<=0){ d1+=b*b*(2*x+3); x++; } else{ d1+=b*b*(2*x+3)+a*a*(-2*y+2); x++; y--; } putpixel(x,y); putpixel(-x,-y); putpixel(-x,y); putpixel(x,-y); }/*while上半部分*/ d2=b*b*(x+0.5)*(x+0.5)+a*a*(y-1)*(y-1)-a*a*b*b; while(y>0){ if(d2<=0){ d2+=b*b*(2*x+2)+a*a*(-2*y+3); x++; y--; } else{ d2+=a*a*(-2*y+3); y--; } putpixel(x,y); putpixel(-x,-y); putpixel(-x,y); putpixel(x,-y); }}voidDisplay(void){ glClear(GL_COLOR_BUFFER_BIT); glColor3f(1.0f,0.0f,0.0f); glPointSize(3); MidBressenhamElipse(80,60); glFlush();}intmain(intargc,char*argv[]){ glutInit(&argc,argv); glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB); glutInitWindowSize(400,300); glutInitWindowPosition(100,120); glutCreateWindow("矩形"); glutDisplayFunc(Display); Initial(); glutMainLoop(); return0;}實(shí)驗(yàn)四填充算法實(shí)驗(yàn)實(shí)驗(yàn)?zāi)康恼莆沼脪呙杈€種子填充法實(shí)現(xiàn)掃描線種子填充算法填充任一多邊形區(qū)域的程序?qū)嶒?yàn)內(nèi)容堆棧庫(kù)#include<stack>//實(shí)現(xiàn)了堆棧操作structPoint{GLintx;GLinty;};std::stack<Point>stk;structPointpoint1;stk.pop(point1);//pop從棧中彈出最上面的元素并取得它stk.push(point1);//壓入一個(gè)元素stk.empty();//判空point1=stk.top();//取得棧最上面元素,但不彈出,仍在棧中獲取像素顏色typedeffloatColor[3];Colorc;glReadPixels(cur_point.x,cur_point.y,1,1,GL_RGB,GL_FLOAT,c);//實(shí)驗(yàn)代碼和實(shí)驗(yàn)結(jié)果#include<GL/glut.h>#include<stdlib.h>#include<math.h>#include<conio.h>#include<stack>#include<windows.h>typedeffloatColor[3];structPoint{ GLintx; GLinty;};std::stack<Point>stk;voidinit(void){ glClearColor(1.0,1.0,1.0,0.0); glMatrixMode(GL_PROJECTION); gluOrtho2D(0.0,400.0,0.0,400.0);}//種子像素坐標(biāo)voidsetPixel(Pointcur_point){ glBegin(GL_POINTS); glVertex2i(cur_point.x,cur_point.y); glEnd(); glFlush();}voidgetPixel(Pointcur_point,Colorc){ glReadPixels(cur_point.x,cur_point.y,1,1,GL_RGB,GL_FLOAT,c);}boolrgbColorEqual(Colorc1,Colorc2){ if((abs(c1[0]-c2[0])>0.001)||(abs(c1[1]-c2[1])>0.001)||(abs(c1[2]-c2[2])>0.001)) return0; else return1;}intFillLineRegion(Pointcur_point,ColorfillColor,ColorborderColor,intdirection){ intcount=0; ColorinteriorColor; glColor3f(fillColor[0],fillColor[1],fillColor[2]); getPixel(cur_point,interiorColor); while(!(rgbColorEqual(interiorColor,borderColor))&&!(rgbColorEqual(interiorColor,fillColor))) { setPixel(cur_point); if(direction==0) cur_point.x++; else cur_point.x--; getPixel(cur_point,interiorColor); count++; } returncount;}intisPixelValid(Pointcur_point,ColorfillColor,ColorborderColor){ ColorinteriorColor; getPixel(cur_point,interiorColor); if(!(rgbColorEqual(interiorColor,borderColor))&&!(rgbColorEqual(interiorColor,fillColor))) return1; else return0;}voidSearchLineNewSeed(intxLeft,intxRight,inty,ColorfillColor,ColorborderColor){ intxt=xLeft; intseed_left=-1; Pointtemp_point; Pointseed_point; while(xt<=xRight){ seed_left=-1; temp_point.x=xt; temp_point.y=y; while(xt<=xRight){ if(isPixelValid(temp_point,fillColor,borderColor)){ seed_left=temp_point.x; break; } else{ xt++; temp_point.x=xt; } } while(xt<=xRight){ if(isPixelValid(temp_point,fillColor,borderColor)){ xt++; temp_point.x=xt; } else{ break; } } if(seed_left!=-1){ seed_point.x=seed_left; seed_point.y=y; stk.push(seed_point); } }}voidscanLine(Pointcur_point,ColorfillColor,ColorborderColor){ intcount=0; intright,left; Pointtemp_point; while(!stk.empty()) { Pointseed_point=stk.top(); stk.pop(); count=FillLineRegion(seed_point,fillColor,borderColor,0); right=seed_point.x+count-1; temp_point.x=seed_point.x-1; temp_point.y=seed_point.y; count=FillLineRegion(temp_point,fillColor,borderColor,1); left=seed_point.x-count; SearchLineNewSeed(left,right,seed_point.y-1,fillColor,borderColor); SearchLineNewSeed(left,right,seed_point.y+1,fillColor,borderColor); } return;}voidmyDraw(void){ glClear(GL_COLOR_BUFFER_BIT); glColor3f(0.0,0.0,0.0); glBegin(GL_LINE_LOOP); glVertex2f(20.0f,80.0f); glVertex2f(30.0f,95.0f); glVertex2f(50.0f,95.0f); glVertex2f(60.0f,80.0f); glVertex2f(70.0f,95.0f); glVertex2f(90.0f,95.0f); glVertex2f(100.0f,80.0f); glVertex2f(60.0f,30.0f); glEnd(); intx=60,y=60; structPointseed_point={65,65}; ColorfillColor,borderColor; fillColor[0]=1.0;fillColor[1]=0.0;fillColor[2]=0.0; borderColor[0]=0.0;borderColor[1]=0.0;borderColor[2]=0.0; stk.push(seed_point); scanLine(seed_point,fillColor,borderColor); glFlush();}voidmain(intargc,char**argv){ glutInit(&argc,argv); glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB); glutInitWindowPosition(50,100); glutInitWindowSize(400,400); glutCreateWindow("bianjie"); init(); glutDisplayFunc(myDraw); glutMainLoop();}

實(shí)驗(yàn)五裁剪算法實(shí)驗(yàn)實(shí)驗(yàn)?zāi)康暮蛯?shí)驗(yàn)內(nèi)容掌握用Cohen-Sutherland法裁減直線實(shí)驗(yàn)代碼和實(shí)驗(yàn)結(jié)果#include<stdio.h>#include<gl/glut.h>#include<math.h>constwinLeftBitCode=0x1;constwinRightBitCode=0x2;constwinBottomBitCode=0x4;constwinTopBitCode=0x8;classwcPt2D{public:GLfloatx,y;};inlineintinside(intcode){ returnint(!code);}inlineintreject(intcode1,intcode2){ returnint(code1&code2);}inlineintaccept(intcode1,intcode2){ returnint(!(code1|code2));}GLubyteencode(wcPt2Dpt,wcPt2DwinMin,wcPt2DwinMax){ GLubytecode=0x00; if(pt.x<winMin.x) code=code|winLeftBitCode; if(pt.x>winMax.x) code=code+winRightBitCode; if(pt.y<winMin.y) code=code|winBottomBitCode; if(pt.y>winMax.y) code=code|winTopBitCode; return(code);}voidswapPts(wcPt2D*p1,wcPt2D*p2){ wcPt2Dtmp; tmp=*p1; *p1=*p2; *p2=tmp;}voidswapCodes(GLubyte*c1,GLubyte*c2){ GLubytetmp; tmp=*c1; *c1=*c2; *c2=tmp;}voiddraw_pixel(intix,intiy/*,intvalue*/){ glBegin(GL_POINTS); glVertex2i(ix,iy); glEnd();}intinlineround(constfloata){ returnint(a+0.5);}voidlineDDA(intx0,inty0,intx_end,inty_end,doublea,doubleb,doublec){ glColor3f(a,b,c); intdx=x_end-x0; intdy=y_end-y0; intsteps,k; floatxlncrement,ylncrement,x=x0,y=y0; if(abs(dx)>abs(dy)) steps=abs(dx); else steps=abs(dy); xlncrement=float(dx)/float(steps); ylncrement=float(dy)/float(steps); draw_pixel(round(x),round(y)); for(k=0;k<steps;k++){ x+=xlncrement; y+=ylncrement; draw_pixel(round(x),round(y)); }}voidlineClipCohSuth(wcPt2DwinMin,wcPt2DwinMax,wcPt2Dp1,wcPt2Dp2){ GLubytecode1,code2; GLintdone=false,plotLine=false; GLfloatm; while(!done){ code1=encode(p1,winMin,winMax); code2=encode(p2,winMin,winMax); if(accept(code1,code2)){ done=true; plotLine=true; } else if(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); if(code1&winLeftBitCode){ p1.y+=(winMin.x-p1.x)*m; p1.x=winMin.x; } else if(code1&winRightBitCode){ p1.y+=(winMax.x-p1.x)*m; p1.x=winMax.x; } else if(code1&winBottomBitCode){ if(p2.x!=p1.x) p1.x+=(winMin.y-p1.y)/m; p1.y=winMin.y; } else if(code1&winTopBitCode){ if(p2.x!=p1.x) p1.x+=(winMax.y-p1.y)/m; p1.y=winMax.y; } } } if(plotLine) lineDDA(round(p1.x),round(p1.y),round(p2.x),round(p2.y

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論