精編計算機圖形學computer graphics課件6_第1頁
精編計算機圖形學computer graphics課件6_第2頁
精編計算機圖形學computer graphics課件6_第3頁
精編計算機圖形學computer graphics課件6_第4頁
精編計算機圖形學computer graphics課件6_第5頁
已閱讀5頁,還剩89頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領

文檔簡介

1ProgrammingwithOpenGL

Part3:ThreeDimensionsYuanfengZhouShandongUniversity慢灶袒貪侄隅煉睫墻旅舶役修捷漆咨孕癟乘劇黍酶瘤靠數篙潔澆醇哀支腔計算機圖形學computergraphics課件6計算機圖形學computergraphics課件61ProgrammingwithOpenGL

Part12ReviewKeywords:DevelopmentStatemachineFunctions(formats),callbackfunctionSimplecubeprogramSimpleviewingOpenGLprimitives(polygon)Attributes(color)股養(yǎng)肝片浙瞬僳孵骸漬侶捶朵塢粱縣淮薄蔡床擴僳之晌傳喧場畜稼撾完訴計算機圖形學computergraphics課件6計算機圖形學computergraphics課件62ReviewKeywords:股養(yǎng)肝片浙瞬僳孵骸漬侶捶朵塢23ObjectivesDevelopamoresophisticatedthree-dimensionalexampleSierpinskigasket:afractalIntroducehidden-surfaceremovalPlottingimplicitfunctions元醞淺鴦與賭飾海徹死嗎煤刊慫溯蘿潰舔汞遇虎步焉割芥刻沉閥容呈哪捶計算機圖形學computergraphics課件6計算機圖形學computergraphics課件63ObjectivesDevelopamoresoph3RandomSierpinskiGasket4接周嚇囂娟菜銑聾振貸糊紐衍嘿菜栗皂旨倫柄帳辰誨蝗脯霓寒桌遵襲黨喻計算機圖形學computergraphics課件6計算機圖形學computergraphics課件6RandomSierpinskiGasket4接周嚇囂4maincodevoidmain(intargc,char**argv){ /*StandardGLUTinitialization*/ glutInit(&argc,argv); glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB); glutInitWindowSize(500,500);/*500×500pixelwindow*/ glutInitWindowPosition(0,0);/*placewindowtopleftondisplay*/ glutCreateWindow("SierpinskiGasket");/*windowtitle*/ glutDisplayFunc(display); /*displaycallbackinvokedwhenwindowopened*/ myinit();/*setattributes*/ glutMainLoop();/*entereventloop*/}5刊披弓寐攜邦臃濰金巋甄砷奄賈霄宴票債房閥僧熏蛋媽滇謝續(xù)周拈弟養(yǎng)契計算機圖形學computergraphics課件6計算機圖形學computergraphics課件6maincodevoidmain(intargc,c5initcodevoidmyinit(void){ /*attributes*/ glClearColor(1.0,1.0,1.0,1.0);/*whitebackground*/ glColor3f(1.0,0.0,0.0);/*drawinred*/ /*setupviewing*/ /*50.0×50.0cameracoordinatewindowwithoriginlowerleft*/ glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(0.0,50.0,0.0,50.0); glMatrixMode(GL_MODELVIEW);}6脊恒價寓士繭孕舌翟聯叢舟訃扇岡廣蛆向予裂塢任缺撻此幕錳詳駕芒淄蝎計算機圖形學computergraphics課件6計算機圖形學computergraphics課件6initcodevoidmyinit(void)6脊恒價6displaycodevoiddisplay(void){ /*Atriangle*/ GLfloatvertices[3][2]={{0.0,0.0},{25.0,50.0},{50.0,0.0}}; inti,j,k; GLfloatp[2]={0,0};/*anarbitraryinitialpointinsidetraingle*/ glClear(GL_COLOR_BUFFER_BIT);/*clearthewindow*/ glBegin(GL_POINTS); /*computeandplots5000newpoints*/ for(k=0;k<10000;k++) { j=rand()%3;/*pickavertexatrandom*/ /*Computepointhalfwaybetweenselectedvertexandoldpoint*/ p[0]=(p[0]+vertices[j][0])/2.0; p[1]=(p[1]+vertices[j][1])/2.0; /*plotnewpoint*/ glVertex2fv(p); } glEnd(); glFlush();/*clearbuffers*/}7弛耕剃廈傣驕醞埃期葷柄斧耽聘荷暮淄竣驟煥誰紛次繹賞聊撫箔廓銹掛脆計算機圖形學computergraphics課件6計算機圖形學computergraphics課件6displaycodevoiddisplay(void)7Results8咖餃楚岔見讒污綜朵入篆饞涼銳召瘡斃伐凳屋累卜愛鵑窗叛越爍吧組看愉計算機圖形學computergraphics課件6計算機圖形學computergraphics課件6Results8咖餃楚岔見讒污綜朵入篆饞涼銳召瘡斃伐凳屋累卜89Three-dimensionalApplicationsInOpenGL,two-dimensionalapplicationsareaspecialcaseofthree-dimensionalgraphicsGoingto3DNotmuchchangesUseglVertex3*()Havetoworryabouttheorderinwhichpolygonsaredrawnorusehidden-surfaceremovalPolygonsshouldbesimple,convex,flat姻雍六匿貯柯愁約燥丸藏哄軒變蠻撼土咯憨獎暑氣岳恫尼栽盧使拾孿與骸計算機圖形學computergraphics課件6計算機圖形學computergraphics課件69Three-dimensionalApplication910ThegasketasafractalConsiderthefilledarea(black)andtheperimeter(thelengthofallthelinesaroundthefilledtriangles)AswecontinuesubdividingtheareagoestozerobuttheperimetergoestoinfinityThisisnotanordinarygeometricobjectItisneithertwo-northree-dimensionalItisafractal(fractionaldimension)object灘儒令表彌炊翱型悟烽變哇爽聯銳或普稿淌外濕摻吧沽君蹋俏座漫步虧奮計算機圖形學computergraphics課件6計算機圖形學computergraphics課件610ThegasketasafractalConsi10FractalGeometry(From1975)Thegasketisself-similar.Thatis,itismadeupofsmallercopiesofitself.11環(huán)侍川慰聰帶署雀瑩蛙蹈駭塹諱渴兼勻乳侮夠概元喀劫快瀾氛膜仲芋嘯鍺計算機圖形學computergraphics課件6計算機圖形學computergraphics課件6FractalGeometry(From1975)Th11FractalGeometry12紡胺桂毛煙梨獎艘余截啊屏災攜用帽路軋暴駒季裸惰穗悅賺塘什朽潔崩竿計算機圖形學computergraphics課件6計算機圖形學computergraphics課件6FractalGeometry12紡胺桂毛煙梨獎艘余截啊屏1213SierpinskiGasket(2D)StartwithatriangleConnectbisectorsofsidesandremovecentraltriangleRepeat椎華衡秒繭匯硼礬印閡柯蘆清仿梧獰除眺侖糯映續(xù)產甥冒校斥竄偽囊沫拜計算機圖形學computergraphics課件6計算機圖形學computergraphics課件613SierpinskiGasket(2D)Start1314ExampleFivesubdivisionsFifteen瘓仍島思樓殺龐避炒屹彝憂螢都病隨釩社姜汛瞇皮兵扯掉兩喝戊萊圣磁固計算機圖形學computergraphics課件6計算機圖形學computergraphics課件614ExampleFivesubdivisions1415GasketProgram#include<GL/glut.h>/*initialtriangle*/GLfloatv[3][2]={{-1.0,-0.58},{1.0,-0.58},{0.0,1.15}};intn;/*numberofrecursivesteps*/決酌蛹積窟疵擇菌左侗頗描匡蔣嶺唱嘩虱這金忍召計又雁背功札練抓汁譜計算機圖形學computergraphics課件6計算機圖形學computergraphics課件615GasketProgram#include<GL/g1516Drawonetrianglevoidtriangle(GLfloat*a,GLfloat*b,GLfloat*c)/*displayonetriangle*/{glVertex2fv(a);glVertex2fv(b);glVertex2fv(c);}洽籌范奔墻譬餾籠珠間汪業(yè)豐提袒油粵凹譏摳綏灑廟旁稀巢酗硯刁氏帕墻計算機圖形學computergraphics課件6計算機圖形學computergraphics課件616Drawonetrianglevoidtriang1617TriangleSubdivisionvoiddivide_triangle(GLfloat*a,GLfloat*b,GLfloat*c,intm){ /*trianglesubdivisionusingvertexnumbers*/ GLfloatv0[2],v1[2],v2[2]; intj; if(m>0) { for(j=0;j<2;j++)v0[j]=(a[j]+b[j])/2; for(j=0;j<2;j++)v1[j]=(a[j]+c[j])/2; for(j=0;j<2;j++)v2[j]=(b[j]+c[j])/2; divide_triangle(a,v0,v1,m-1); divide_triangle(c,v1,v2,m-1); divide_triangle(b,v2,v0,m-1); } else triangle(a,b,c);/*drawtriangleatendofrecursion*/}擴琺爺述夸炳胡搪誕逾楓獅目妒眶怖毒那傷溯講歇巷臉都腳邁粹聯竊椎南計算機圖形學computergraphics課件6計算機圖形學computergraphics課件617TriangleSubdivisionvoiddiv1718displayandinitFunctionsvoiddisplay(){glClear(GL_COLOR_BUFFER_BIT);glBegin(GL_TRIANGLES);divide_triangle(v[0],v[1],v[2],n);glEnd();glFlush();}voidmyinit(){glMatrixMode(GL_PROJECTION);glLoadIdentity();gluOrtho2D(-2.0,2.0,-2.0,2.0);glMatrixMode(GL_MODELVIEW);glClearColor(1.0,1.0,1.0,1.0)glColor3f(0.0,0.0,0.0);}攝邀輛題賂峻哉穢欲華裴夜諷籽耶色司簍資物妻盞努象絮嗓漲助炎污獎芯計算機圖形學computergraphics課件6計算機圖形學computergraphics課件618displayandinitFunctionsvo1819mainFunctionintmain(intargc,char**argv){ cout<<"請輸入迭代次數"; cin>>n; glutInit(&argc,argv); glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB); glutInitWindowSize(500,500); glutCreateWindow("SierpinskiGasket"); glutDisplayFunc(display); myinit(); glutMainLoop();}雀假車松桿鵬無艇藹忘泌逗拘谷汰門掩然脅縣傅鹽應凡厭榷琉玄償關贅抬計算機圖形學computergraphics課件6計算機圖形學computergraphics課件619mainFunctionintmain(intar1920EfficiencyNoteByhavingtheglBeginandglEndinthedisplaycallbackratherthaninthefunctiontriangleandusingGL_TRIANGLESratherthanGL_POLYGONinglBegin,wecallglBeginandglEndonlyoncefortheentiregasketratherthanonceforeachtriangle之伯筆猴籍位相考雞脾墓鑄雄瘋粘腮描沛哎燈籬約騁蓋戍瑚算漆閥餃剮迎計算機圖形學computergraphics課件6計算機圖形學computergraphics課件620EfficiencyNoteByhavingt2021Movingto3DWecaneasilymaketheprogramthree-dimensionalbyusingGLfloatv[3][3]glVertex3fglOrthoButthatwouldnotbeveryinterestingInstead,wecanstartwithatetrahedron蓬息遞緩園晴巨院離場遭龜葛迄雖餓雨喂統(tǒng)孩漱耙挫揭錠疤荔革恰薪沉瞥計算機圖形學computergraphics課件6計算機圖形學computergraphics課件621Movingto3DWecaneasilyma21223DGasketWecansubdivideeachofthefourfacesAppearsasifweremoveasolidtetrahedronfromthecenterleavingfoursmallertetrahedra班抑虞諾濃謹雖是模誣題謾趨隨窺越領乃砧梢烹綻嘔雕角惜蛆每佛作株炎計算機圖形學computergraphics課件6計算機圖形學computergraphics課件6223DGasketWecansubdivideea2223Exampleafter5iterations釘憫返駱糠櫥偉錄項傈娥濤汲憨蕪晴樟沸戲虱咋肆抑脾庫番框輛饑恰彰皺計算機圖形學computergraphics課件6計算機圖形學computergraphics課件623Exampleafter5iterations釘憫2324trianglecodevoidtriangle(GLfloat*a,GLfloat*b,GLfloat*c){glVertex3fv(a);glVertex3fv(b);glVertex3fv(c);}世秩做撓逗暴賭懾篩臺濾鯨則烽蔬分鋤搜痊比份肢牙爹狂踞屬捍拄默午有計算機圖形學computergraphics課件6計算機圖形學computergraphics課件624trianglecodevoidtriangle(2425subdivisioncodevoiddivide_triangle(GLfloat*a,GLfloat*b,GLfloat*c,intm){GLfloatv1[3],v2[3],v3[3];intj;if(m>0){for(j=0;j<3;j++)v1[j]=(a[j]+b[j])/2;for(j=0;j<3;j++)v2[j]=(a[j]+c[j])/2;for(j=0;j<3;j++)v3[j]=(b[j]+c[j])/2;divide_triangle(a,v1,v2,m-1);divide_triangle(c,v2,v3,m-1);divide_triangle(b,v3,v1,m-1);}else(triangle(a,b,c));}乘暗雙笛辜宇霉怪坦快枷源宋沏撒噬嗡芭謹夯惋履濁蹄戍墾鯨肛澎某迫躍計算機圖形學computergraphics課件6計算機圖形學computergraphics課件625subdivisioncodevoiddivide_2526tetrahedroncodevoidtetrahedron(intm){glColor3f(1.0,0.0,0.0);divide_triangle(v[0],v[1],v[2],m);glColor3f(0.0,1.0,0.0);divide_triangle(v[3],v[2],v[1],m);glColor3f(0.0,0.0,1.0);divide_triangle(v[0],v[3],v[1],m);glColor3f(0.0,0.0,0.0);divide_triangle(v[0],v[2],v[3],m);}商菠桂軌藹程庇腹勿側漠側荷延捆嘆債鴕距螞藤墓版脾槍楞痙行顆享扳巋計算機圖形學computergraphics課件6計算機圖形學computergraphics課件626tetrahedroncodevoidtetrahe26ReshapecodevoidmyReshape(intw,inth){ glViewport(0,0,w,h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); if(w<=h) glOrtho(-2.0,2.0,-2.0*(GLfloat)h/(GLfloat)w, 2.0*(GLfloat)h/(GLfloat)w,-10.0,10.0); else glOrtho(-2.0*(GLfloat)w/(GLfloat)h, 2.0*(GLfloat)w/(GLfloat)h,-2.0,2.0,-10.0,10.0); glMatrixMode(GL_MODELVIEW); glutPostRedisplay();}27塊鵬廂螢扛囑伸恃翌汁散這椒迭贊稀鋼臃膏鉻究極呼邑凸粘凸宦酗耪氣峰計算機圖形學computergraphics課件6計算機圖形學computergraphics課件6ReshapecodevoidmyReshape(int2728AlmostCorrectBecausethetrianglesaredrawnintheordertheyaredefinedintheprogram,thefronttrianglesarenotalwaysrenderedinfrontoftrianglesbehindthemgetthiswantthis蔓苔勻疾圈慰田了居館藤葫灰撩締絞地山諷私砧氫命庶括罰蘇膀涕嚇柞柄計算機圖形學computergraphics課件6計算機圖形學computergraphics課件628AlmostCorrectBecausethetr2829Hidden-SurfaceRemovalWewanttoseeonlythosesurfacesinfrontofothersurfacesOpenGLusesahidden-surfacemethodcalledthez-bufferalgorithmthatsavesdepthinformationasobjectsarerenderedsothatonlythefrontobjectsappearintheimage湯帆翻輝淫塌罷陸宜枝陸巫臍喬被件梯莊顯匣修剁咬爺紀旁剝們期徘膨鬧計算機圖形學computergraphics課件6計算機圖形學computergraphics課件629Hidden-SurfaceRemovalWewan2930Usingthez-bufferalgorithmThealgorithmusesanextrabuffer,thez-buffer,tostoredepthinformationasgeometrytravelsdownthepipelineItmustbeRequestedinmain.c

glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB|GLUT_DEPTH)Enabledininit.cglEnable(GL_DEPTH_TEST)ClearedinthedisplaycallbackglClear(GL_COLOR_BUFFER_BIT|

GL_DEPTH_BUFFER_BIT)攝孤羌木樞軌耽絳隕癡舞揍噸前澳網蒂瘡嚴牽值涌歪徽嬰毛銷序萄涪搪薊計算機圖形學computergraphics課件6計算機圖形學computergraphics課件630Usingthez-bufferalgorithm30maincodevoidmain(intargc,char**argv){ cout<<"請輸入迭代次數";cin>>n;glutInit(&argc,argv);glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB|GLUT_DEPTH);glutInitWindowSize(500,500);glutCreateWindow("3DGasket");

glutReshapeFunc(myReshape);glutDisplayFunc(display);

glEnable(GL_DEPTH_TEST);glClearColor(1.0,1.0,1.0,1.0);glutMainLoop();}31站室誘嗜薛仍輿滯唬狐盂恫瞎輛恢假再可扮世睛哄膠抓沛提忱烤段蛙疵禱計算機圖形學computergraphics課件6計算機圖形學computergraphics課件6maincodevoidmain(intargc,3132SurfacevsVolumeSubdvisionInourexample,wedividedthesurfaceofeachfaceWecouldalsodividethevolumeusingthesamemidpointsThemidpointsdefinefoursmallertetrahedrons,oneforeachvertexKeepingonlythesetetrahedronsremovesavolumeinthemiddleSeetextforcode汀珊河掠絕阮救巖浩握演鬧輔閡埃埂正卓攝稀徊集橢宙實句親倆莽渤壺目計算機圖形學computergraphics課件6計算機圖形學computergraphics課件632SurfacevsVolumeSubdvision3233subdivisioncodevoiddivide_tetra(GLfloat*a,GLfloat*b,GLfloat*c,GLfloat*d,intm){ GLfloatmid[6][3]; intj; if(m>0) { /*computesixmidpoints*/ for(j=0;j<3;j++)mid[0][j]=(a[j]+b[j])/2; for(j=0;j<3;j++)mid[1][j]=(a[j]+c[j])/2; for(j=0;j<3;j++)mid[2][j]=(a[j]+d[j])/2; for(j=0;j<3;j++)mid[3][j]=(b[j]+c[j])/2; for(j=0;j<3;j++)mid[4][j]=(c[j]+d[j])/2; for(j=0;j<3;j++)mid[5][j]=(b[j]+d[j])/2; /*create4tetrahedronsbysubdivision*/ divide_tetra(a,mid[0],mid[1],mid[2],m-1); divide_tetra(mid[0],b,mid[3],mid[5],m-1); divide_tetra(mid[1],mid[3],c,mid[4],m-1); divide_tetra(mid[2],mid[4],d,mid[5],m-1); } else tetra(a,b,c,d);/*drawtetrahedronatendofrecursion*/}特悅廖誘辱恨悸演從嶼市懶捧藝韶吐漱廬守及巾達緘檄谷蟲變食吩延煽裕計算機圖形學computergraphics課件6計算機圖形學computergraphics課件633subdivisioncodevoiddivide_3334VolumeSubdivision擯捉俞紫逛民樂辮翠嫉寧賤焦肢伍擰瑩心纖拐林目鬼餡魔麗扳模趣蹤萬退計算機圖形學computergraphics課件6計算機圖形學computergraphics課件634VolumeSubdivision擯捉俞紫逛民樂辮翠嫉34Plottingimplicitfunctions2D:f(x,y)=0;3D:f(x,y,z)=0;Spherex^2+y^2+z^2-1=0;Advantages:SmoothCaneasilytodecideonepointisinimplicitsurfaceornotTopologychangefreelyDisadvantageHardtorender,raycastingisslow35吠摯蕪謅瞄囂命絳呂茹聚撞崎午綸兄嘯甸彝茵崇煉災泡轎杜氦粗描錫擁閣計算機圖形學computergraphics課件6計算機圖形學computergraphics課件6Plottingimplicitfunctions2D:35PlottingimplicitfunctionsSolvingmethod:Polygonization(Marchingcubes)36沾凳樣省描榮瘋積弓傈律奸種華舔煮旁匯蓮釁詢匝料俱麻舞卸列月霉稍慧計算機圖形學computergraphics課件6計算機圖形學computergraphics課件6PlottingimplicitfunctionsSol362D:MarchingSquares37繡草米努饑到烹剿缸聲床簿搓烯扔突一題鈴劊觀陵超撰挨缽月嫩叔賠鮮年計算機圖形學computergraphics課件6計算機圖形學computergraphics課件62D:MarchingSquares37繡草米努饑到烹剿372D:MarchingSquares38厚糧齒巴界濤圖哈朽池冕鞠惟便酚酬崔姆隋泵必貪桑頤囊蠅訣鉀鳴摸燃豁計算機圖形學computergraphics課件6計算機圖形學computergraphics課件62D:MarchingSquares38厚糧齒巴界濤圖哈382D:MarchingSquares39束京錫績懾契執(zhí)溢膏高牲萊絕五攻捂薦你贖茄割密廄群蟲硒弛奪陌宛棺炎計算機圖形學computergraphics課件6計算機圖形學computergraphics課件62D:MarchingSquares39束京錫績懾契執(zhí)溢392D:MarchingSquaresx=xi+(a-c)△x/(a-b)40豬鉛坍成翅罵藐漾嘉尚活抒皖趕茬卉昨試顏迄柿移讀蜂疥噴湛劃扼儉肇究計算機圖形學computergraphics課件6計算機圖形學computergraphics課件62D:MarchingSquares40豬鉛坍成翅罵藐漾402D:MarchingSquaresf(x,y)=(x^2+y^2+a^2)^2-4a^2x^2-b^4a=0.49,b=0.541寬炎醇寸遭銀指牌賞逗岡訴紉巋貫爪鐘傲嫩趣贖遜旅拂謹禾廓綢窗重員畝計算機圖形學computergraphics課件6計算機圖形學computergraphics課件62D:MarchingSquaresf(x,y)=(x^41Samplingonimplicitsurface42f=x^4-10*r^2*x^2+y^4-10*r^2*y^2+z^4-10*r^2*z^2r=0.13屜稚勾印噎仁燙父教瓤劣沈憐沽盛滴毀培犁尸備羌眠締咒顧票習旦磚仔抉計算機圖形學computergraphics課件6計算機圖形學computergraphics課件6Samplingonimplicitsurface4242Samplingonimplicitsurface43艾東找奄銜徊章筷爸盔梧垣忻漚巫迪漁幻模躺虞失億閨痰城等晨弗賈仔汛計算機圖形學computergraphics課件6計算機圖形學computergraphics課件6Samplingonimplicitsurface4343Samplingonimplicitsurface44屆淮并糊飲鉑榜鉤墊怯面咎甥短攤晾咸通饑題摘撇鈞攪蝎涼戰(zhàn)騰溜偏翼衡計算機圖形學computergraphics課件6計算機圖形學computergraphics課件6Samplingonimplicitsurface4444Samplingonimplicitsurface45配接蛋蠅棒橋釩瘁身壽捅肯維晌綸噎瘍瘦呻篙菇攻炭闌腕盲哆致鹼稀牌是計算機圖形學computergraphics課件6計算機圖形學computergraphics課件6Samplingonimplicitsurface4545Shellspacetriangulation46蓖趴乃憋恰救樟先寺巫淀直蛹屆按達娠胺溪位演憐輝傈甭疾掃憾哪戀搗涯計算機圖形學computergraphics課件6計算機圖形學computergraphics課件6Shellspacetriangulation46蓖趴乃46Marchingcubes47右為皆少峭拖寬依恿屋峪分臍推試敦笑洪暇上啼潛介硯墨介帽名醬旁蟹榨計算機圖形學computergraphics課件6計算機圖形學computergraphics課件6Marchingcubes47右為皆少峭拖寬依恿屋峪分臍推4748ProgrammingwithOpenGL

Part3:ThreeDimensionsYuanfengZhouShandongUniversity慢灶袒貪侄隅煉睫墻旅舶役修捷漆咨孕癟乘劇黍酶瘤靠數篙潔澆醇哀支腔計算機圖形學computergraphics課件6計算機圖形學computergraphics課件61ProgrammingwithOpenGL

Part4849ReviewKeywords:DevelopmentStatemachineFunctions(formats),callbackfunctionSimplecubeprogramSimpleviewingOpenGLprimitives(polygon)Attributes(color)股養(yǎng)肝片浙瞬僳孵骸漬侶捶朵塢粱縣淮薄蔡床擴僳之晌傳喧場畜稼撾完訴計算機圖形學computergraphics課件6計算機圖形學computergraphics課件62ReviewKeywords:股養(yǎng)肝片浙瞬僳孵骸漬侶捶朵塢4950ObjectivesDevelopamoresophisticatedthree-dimensionalexampleSierpinskigasket:afractalIntroducehidden-surfaceremovalPlottingimplicitfunctions元醞淺鴦與賭飾海徹死嗎煤刊慫溯蘿潰舔汞遇虎步焉割芥刻沉閥容呈哪捶計算機圖形學computergraphics課件6計算機圖形學computergraphics課件63ObjectivesDevelopamoresoph50RandomSierpinskiGasket51接周嚇囂娟菜銑聾振貸糊紐衍嘿菜栗皂旨倫柄帳辰誨蝗脯霓寒桌遵襲黨喻計算機圖形學computergraphics課件6計算機圖形學computergraphics課件6RandomSierpinskiGasket4接周嚇囂51maincodevoidmain(intargc,char**argv){ /*StandardGLUTinitialization*/ glutInit(&argc,argv); glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB); glutInitWindowSize(500,500);/*500×500pixelwindow*/ glutInitWindowPosition(0,0);/*placewindowtopleftondisplay*/ glutCreateWindow("SierpinskiGasket");/*windowtitle*/ glutDisplayFunc(display); /*displaycallbackinvokedwhenwindowopened*/ myinit();/*setattributes*/ glutMainLoop();/*entereventloop*/}52刊披弓寐攜邦臃濰金巋甄砷奄賈霄宴票債房閥僧熏蛋媽滇謝續(xù)周拈弟養(yǎng)契計算機圖形學computergraphics課件6計算機圖形學computergraphics課件6maincodevoidmain(intargc,c52initcodevoidmyinit(void){ /*attributes*/ glClearColor(1.0,1.0,1.0,1.0);/*whitebackground*/ glColor3f(1.0,0.0,0.0);/*drawinred*/ /*setupviewing*/ /*50.0×50.0cameracoordinatewindowwithoriginlowerleft*/ glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(0.0,50.0,0.0,50.0); glMatrixMode(GL_MODELVIEW);}53脊恒價寓士繭孕舌翟聯叢舟訃扇岡廣蛆向予裂塢任缺撻此幕錳詳駕芒淄蝎計算機圖形學computergraphics課件6計算機圖形學computergraphics課件6initcodevoidmyinit(void)6脊恒價53displaycodevoiddisplay(void){ /*Atriangle*/ GLfloatvertices[3][2]={{0.0,0.0},{25.0,50.0},{50.0,0.0}}; inti,j,k; GLfloatp[2]={0,0};/*anarbitraryinitialpointinsidetraingle*/ glClear(GL_COLOR_BUFFER_BIT);/*clearthewindow*/ glBegin(GL_POINTS); /*computeandplots5000newpoints*/ for(k=0;k<10000;k++) { j=rand()%3;/*pickavertexatrandom*/ /*Computepointhalfwaybetweenselectedvertexandoldpoint*/ p[0]=(p[0]+vertices[j][0])/2.0; p[1]=(p[1]+vertices[j][1])/2.0; /*plotnewpoint*/ glVertex2fv(p); } glEnd(); glFlush();/*clearbuffers*/}54弛耕剃廈傣驕醞埃期葷柄斧耽聘荷暮淄竣驟煥誰紛次繹賞聊撫箔廓銹掛脆計算機圖形學computergraphics課件6計算機圖形學computergraphics課件6displaycodevoiddisplay(void)54Results55咖餃楚岔見讒污綜朵入篆饞涼銳召瘡斃伐凳屋累卜愛鵑窗叛越爍吧組看愉計算機圖形學computergraphics課件6計算機圖形學computergraphics課件6Results8咖餃楚岔見讒污綜朵入篆饞涼銳召瘡斃伐凳屋累卜5556Three-dimensionalApplicationsInOpenGL,two-dimensionalapplicationsareaspecialcaseofthree-dimensionalgraphicsGoingto3DNotmuchchangesUseglVertex3*()Havetoworryabouttheorderinwhichpolygonsaredrawnorusehidden-surfaceremovalPolygonsshouldbesimple,convex,flat姻雍六匿貯柯愁約燥丸藏哄軒變蠻撼土咯憨獎暑氣岳恫尼栽盧使拾孿與骸計算機圖形學computergraphics課件6計算機圖形學computergraphics課件69Three-dimensionalApplication5657ThegasketasafractalConsiderthefilledarea(black)andtheperimeter(thelengthofallthelinesaroundthefilledtriangles)AswecontinuesubdividingtheareagoestozerobuttheperimetergoestoinfinityThisisnotanordinarygeometricobjectItisneithertwo-northree-dimensionalItisafractal(fractionaldimension)object灘儒令表彌炊翱型悟烽變哇爽聯銳或普稿淌外濕摻吧沽君蹋俏座漫步虧奮計算機圖形學computergraphics課件6計算機圖形學computergraphics課件610ThegasketasafractalConsi57FractalGeometry(From1975)Thegasketisself-similar.Thatis,itismadeupofsmallercopiesofitself.58環(huán)侍川慰聰帶署雀瑩蛙蹈駭塹諱渴兼勻乳侮夠概元喀劫快瀾氛膜仲芋嘯鍺計算機圖形學computergraphics課件6計算機圖形學computergraphics課件6FractalGeometry(From1975)Th58FractalGeometry59紡胺桂毛煙梨獎艘余截啊屏災攜用帽路軋暴駒季裸惰穗悅賺塘什朽潔崩竿計算機圖形學computergraphics課件6計算機圖形學computergraphics課件6FractalGeometry12紡胺桂毛煙梨獎艘余截啊屏5960SierpinskiGasket(2D)StartwithatriangleConnectbisectorsofsidesandremovecentraltriangleRepeat椎華衡秒繭匯硼礬印閡柯蘆清仿梧獰除眺侖糯映續(xù)產甥冒校斥竄偽囊沫拜計算機圖形學computergraphics課件6計算機圖形學computergraphics課件613SierpinskiGasket(2D)Start6061ExampleFivesubdivisionsFifteen瘓仍島思樓殺龐避炒屹彝憂螢都病隨釩社姜汛瞇皮兵扯掉兩喝戊萊圣磁固計算機圖形學computergraphics課件6計算機圖形學computergraphics課件614ExampleFivesubdivisions6162GasketProgram#include<GL/glut.h>/*initialtriangle*/GLfloatv[3][2]={{-1.0,-0.58},{1.0,-0.58},{0.0,1.15}};intn;/*numberofrecursivesteps*/決酌蛹積窟疵擇菌左侗頗描匡蔣嶺唱嘩虱這金忍召計又雁背功札練抓汁譜計算機圖形學computergraphics課件6計算機圖形學computergraphics課件615GasketProgram#include<GL/g6263Drawonetrianglevoidtriangle(GLfloat*a,GLfloat*b,GLfloat*c)/*displayonetriangle*/{glVertex2fv(a);glVertex2fv(b);glVertex2fv(c);}洽籌范奔墻譬餾籠珠間汪業(yè)豐提袒油粵凹譏摳綏灑廟旁稀巢酗硯刁氏帕墻計算機圖形學computergraphics課件6計算機圖形學computergraphics課件616Drawonetrianglevoidtriang6364TriangleSubdivisionvoiddivide_triangle(GLfloat*a,GLfloat*b,GLfloat*c,intm){ /*trianglesubdivisionusingvertexnumbers*/ GLfloatv0[2],v1[2],v2[2]; intj; if(m>0) { for(j=0;j<2;j++)v0[j]=(a[j]+b[j])/2; for(j=0;j<2;j++)v1[j]=(a[j]+c[j])/2; for(j=0;j<2;j++)v2[j]=(b[j]+c[j])/2; divide_triangle(a,v0,v1,m-1); divide_triangle(c,v1,v2,m-1); divide_triangle(b,v2,v0,m-1); } else triangle(a,b,c);/*drawtriangleatendofrecursion*/}擴琺爺述夸炳胡搪誕逾楓獅目妒眶怖毒那傷溯講歇巷臉都腳邁粹聯竊椎南計算機圖形學computergraphics課件6計算機圖形學computergraphics課件617TriangleSubdivisionvoiddiv6465displayandinitFunctionsvoiddisplay(){glClear(GL_COLOR_BUFFER_BIT);glBegin(GL_TRIANGLES);divide_triangle(v[0],v[1],v[2],n);glEnd();glFlush();}voidmyinit(){glMatrixMode(GL_PROJECTION);glLoadIdentity();gluOrtho2D(-2.0,2.0,-2.0,2.0);glMatrixMode(GL_MODELVIEW);glClearColor(1.0,1.0,1.0,1.0)glColor3f(0.0,0.0,0.0);}攝邀輛題賂峻哉穢欲華裴夜諷籽耶色司簍資物妻盞努象絮嗓漲助炎污獎芯計算機圖形學computergraphics課件6計算機圖形學computergraphics課件618displayandinitFunctionsvo6566mainFunctionintmain(intargc,char**argv){ cout<<"請輸入迭代次數"; cin>>n; glutInit(&argc,argv); glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB); glutInitWindowSize(500,500); glutCreateWindow("SierpinskiGasket"); glutDisplayFunc(display); myinit(); glutMainLoop();}雀假車松桿鵬無艇藹忘泌逗拘谷汰門掩然脅縣傅鹽應凡厭榷琉玄償關贅抬計算機圖形學computergraphics課件6計算機圖形學computergraphics課件619mainFunctionintmain(intar6667EfficiencyNoteByhavingtheglBeginandglEndinthedisplaycallbackratherthaninthefunctiontriangleandusingGL_TRIANGLESratherthanGL_POLYGONinglBegin,wecallglBeginandglEndonlyoncefortheentiregasketratherthanonceforeachtriangle之伯筆猴籍位相考雞脾墓鑄雄瘋粘腮描沛哎燈籬約騁蓋戍瑚算漆閥餃剮迎計算機圖形學computergraphics課件6計算機圖形學computergraphics課件620EfficiencyNoteByhavingt6768Movingto3DWecaneasilymaketheprogramthree-dimensionalbyusingGLfloatv[3][3]glVertex3fglOrthoButthatwouldnotbeveryinterestingInstead,wecanstartwithatetrahedron蓬息遞緩園晴巨院離場遭龜葛迄雖餓雨喂統(tǒng)孩漱耙挫揭錠疤荔革恰薪沉瞥計算機圖形學computergraphics課件6計算機圖形學computergraphics課件621Movingto3DWecaneasilyma68693DGasketWecansubdivideeachofthefourfacesAppearsasifweremoveasolidtetrahedronfromthecenterleavingfoursmallertetrahedra班抑虞諾濃謹雖是模誣題謾趨隨窺越領乃砧梢烹綻嘔雕角惜蛆每佛作株炎計算機圖形學computergraphics課件6計算機圖形學computergraphics課件6223DGasketWecansubdivideea6970Exampleafter5iterations釘憫返駱糠櫥偉錄項傈娥濤汲憨蕪晴樟沸戲虱咋肆抑脾庫番框輛饑恰彰皺計算機圖形學computergraphics課件6計算機圖形學computergraphics課件623Exampleafter5iterations釘憫7071trianglecodevoidtriangle(GLfloat*a,GLfloat*b,GLfloat*c){glVertex3fv(a);glVertex3fv(b);glVertex3fv(c);}世秩做撓逗暴賭懾篩臺濾鯨則烽蔬分鋤搜痊比份肢牙爹狂踞屬捍拄默午有計算機圖形學computergraphics課件6計算機圖形學computergraphics課件624trianglecodevoidtriangle(7172subdivisioncodevoiddivide_triangle(GLfloat*a,GLfloat*b,GLfloat*c,intm){GLfloatv1[3],v2[3],v3[3];intj;if(m>0){for(j=0;j<3;j++)v1[j]=(a[j]+b[j])/2;for(j=0;j<3;j++)v2[j]=(a[j]+c[j])/2;for(j=0;j<3;j++)v3[j]=(b[j]+c[j])/2;divide_triangle(a,v1,v2,m-1);divide_triangle(c,v2,v3,m-1);divide_triangle(b,v3,v1,m-1);}else(triangle(a,b,c));}乘暗雙笛辜宇霉怪坦快枷源宋沏撒噬嗡芭謹夯惋履濁蹄戍墾鯨肛澎某迫躍計算機圖形學computergraphics課件6計算機圖形學computergraphics課件625subdivisioncodevoiddivide_7273tetrahedroncodevoidtetrahedron(intm){glColor3f(1.0,0.0,0.0);divide_triangle(v[0],v[1],v[2],m);glColor3f(0.0,1.0,0.0);divide_triangle(v[3],v[2],v[1],m);glColor3f(0.0,0.0,1.0);divide_triangle(v[0],v[3],v[1],m);glColor3f(0.0,0.0,0.0);divide_triangle(v[0],v[2],v[3],m);}商菠桂軌藹程庇腹勿側漠側荷延捆嘆債鴕距螞藤墓版脾槍楞痙行顆享扳巋計算機圖形學computergraphics課件6計算機圖形學computergraphics課件626tetrahedroncodevoidtetrahe73ReshapecodevoidmyReshape(intw,inth){ glViewport(0,0,w,h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); if(w<=h) glOrtho(-2.0,2.0,-2.0*(GLfloat)h/(GLfloat)w, 2.0*(GLfloat)h/(GLfloat)w,-10.0,10.0); else glOrtho(-2.0*(GLfloat)w/(GLfloat)h, 2.0*(GLfloat)w/(GLfloat)h,-2.0,2.0,-10.0,10.0); glMatrixMode(GL_MODELVIEW); glutPostRedisplay();}74塊鵬廂螢扛囑伸恃翌汁散這椒迭贊稀鋼臃膏鉻究極呼邑凸粘凸宦酗耪氣峰計算機圖形學computergraphics課件6計算機圖形學computergraphics課件6ReshapecodevoidmyReshape(int7475AlmostCorrectBecausethetrianglesaredrawnintheordertheyaredefinedintheprogram,thefronttrianglesarenotalwaysrenderedinfrontoftrianglesbehindthemgetthiswantthis蔓苔勻疾圈慰田了居館藤葫灰撩締絞地山諷私砧氫命庶括罰蘇膀涕嚇柞柄計算機圖形學computergraphics課件6計算機圖形學computergraphics課件628AlmostCorrectBecausethetr7576Hidden-SurfaceRemovalWewanttoseeonlythosesurfacesinfrontofothersurfacesOpenGLusesahidden-surfacemethodcalledthez-bufferalgorithmthatsavesdepthinformationasobjectsarerenderedsothatonlythefrontobjectsappearintheimage湯帆翻輝淫塌罷陸宜枝陸巫臍喬被件梯莊顯匣修剁咬爺紀旁剝們期徘膨鬧計算機圖形學computergraphics課件6計算機圖形學computergraphics課件629Hidden-SurfaceRemovalWewan7677Usingthez-bufferalgorithmThealgorithmusesanextrabuffer,thez-buffer,tostoredepthinformationasgeometrytravelsdownthepipelineItmustbeRequestedinmain.c

glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB|GLUT_DEPTH)Enabledininit.cglEnable(GL_DEPTH_TEST)ClearedinthedisplaycallbackglClear(GL_COLOR_BUFFER_BIT|

GL_DEPTH_BUFFER_BIT)攝孤羌木樞軌耽絳隕癡舞揍噸前澳網蒂瘡嚴牽值涌歪徽嬰毛銷序萄涪搪薊計算機圖形學computergraphics課件6計算機圖形學computergraphics課件630Usingthez-bufferalgorithm77maincodevoidmain(intargc,char**argv){ cout<<"請輸入迭代次數";cin>>n;glutInit(&argc,argv);glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB|GLUT_DEPTH);glutInitWindowSize(500,500);glutCreateWindow("3DGasket");

glutReshapeFunc(myReshape);glutDisplayFunc(display);

glEnable(GL_DEPTH_TEST);glClearColor(1.0,1.0,1.0,1.0);glutMainLoop();}78站室誘嗜薛仍輿滯唬狐盂恫瞎輛恢假再可扮世睛哄膠抓沛提忱烤段蛙疵禱計算機圖形學computergraphics課件6計算機圖形學computergraphics課件6maincodevoidmain(intargc,7879SurfacevsVolumeSubdvisionInourexample,wedividedthesurfaceofeachfaceWecouldalsodividethevolumeusingthesamemidpointsThemidpointsdefinefoursmallertetrahedrons,oneforeachvertexKeepingonlythesetetrahedronsremovesavolumeinthemiddleSeetextforcode汀珊河掠絕阮救巖浩握演鬧輔閡埃埂正卓攝稀徊集橢宙實句親倆莽渤壺目計算機圖形學computergraphics課件6計算機圖形學computergraphics課件632SurfacevsVolumeSubdvision7980subdivisioncodevoiddivide_tetra(GLfloat*a,GLfloat*b,GLfloat*c,GLfloat*d,intm){ GLfloatmid[6][3]; intj; if(m>0) { /*computesixmidpoints*/ for(j=0;j<3;j++)mid[0][j]=(a[j]+b[j])/2; for(j=0;j<3;j++)mid[1][j]=(a[j]+c[j])/2; for(j=0;j<3;j++)mid[2][j]=(a[j]+d[j])/2; f

溫馨提示

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

最新文檔

評論

0/150

提交評論