计算机图形学computergraphicsppt课件.ppt

上传人:飞****2 文档编号:92172809 上传时间:2023-05-31 格式:PPT 页数:47 大小:2.40MB
返回 下载 相关 举报
计算机图形学computergraphicsppt课件.ppt_第1页
第1页 / 共47页
计算机图形学computergraphicsppt课件.ppt_第2页
第2页 / 共47页
点击查看更多>>
资源描述

《计算机图形学computergraphicsppt课件.ppt》由会员分享,可在线阅读,更多相关《计算机图形学computergraphicsppt课件.ppt(47页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。

1、1Programming with OpenGLPart 3:Three DimensionsYuanfeng ZhouShandong University慢灶袒贪侄隅炼睫墙旅舶役修捷漆咨孕瘪乘剧黍酶瘤靠数篙洁浇醇哀支腔计算机图形学computer graphics课件6计算机图形学computer graphics课件62ReviewKeywords:1.Development2.State machine3.Functions(formats),callback function4.Simple cube program5.Simple viewing6.OpenGL primitive

2、s(polygon)7.Attributes(color)股养肝片浙瞬僳孵骸渍侣捶朵坞粱县淮薄蔡床扩僳之晌传喧场畜稼挝完诉计算机图形学computer graphics课件6计算机图形学computer graphics课件63ObjectivesDevelop a more sophisticated threedimensional exampleSierpinski gasket:a fractalIntroduce hiddensurface removalPlotting implicit functions元酝浅鸯与赌饰海彻死吗煤刊怂溯萝溃舔汞遇虎步焉割芥刻沉阀容呈哪捶计算机图形学

3、computer graphics课件6计算机图形学computer graphics课件6 Random Sierpinski Gasket4接周吓嚣娟菜铣聋振贷糊纽衍嘿菜栗皂旨伦柄帐辰诲蝗脯霓寒桌遵袭党喻计算机图形学computer graphics课件6计算机图形学computer graphics课件6main codevoid main(int argc,char*argv)/*Standard GLUT initialization*/glutInit(&argc,argv);glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);glutInitWin

4、dowSize(500,500);/*500 500 pixel window*/glutInitWindowPosition(0,0);/*place window top left on display*/glutCreateWindow(Sierpinski Gasket);/*window title*/glutDisplayFunc(display);/*display callback invoked when window opened*/myinit();/*set attributes*/glutMainLoop();/*enter event loop*/5刊披弓寐携邦臃潍

5、金岿甄砷奄贾霄宴票债房阀僧熏蛋妈滇谢续周拈弟养契计算机图形学computer graphics课件6计算机图形学computer graphics课件6init codevoid myinit(void)/*attributes*/glClearColor(1.0,1.0,1.0,1.0);/*white background*/glColor3f(1.0,0.0,0.0);/*draw in red*/*set up viewing*/*50.0 50.0 camera coordinate window with origin lower left*/glMatrixMode(GL_PRO

6、JECTION);glLoadIdentity();gluOrtho2D(0.0,50.0,0.0,50.0);glMatrixMode(GL_MODELVIEW);6脊恒价寓士茧孕舌翟联丛舟讣扇冈广蛆向予裂坞任缺挞此幕锰详驾芒淄蝎计算机图形学computer graphics课件6计算机图形学computer graphics课件6display codevoid display(void)/*A triangle*/GLfloat vertices32=0.0,0.0,25.0,50.0,50.0,0.0;int i,j,k;GLfloat p2=0,0;/*an arbitrary in

7、itial point inside traingle*/glClear(GL_COLOR_BUFFER_BIT);/*clear the window*/glBegin(GL_POINTS);/*compute and plots 5000 new points*/for(k=0;k10000;k+)j=rand()%3;/*pick a vertex at random*/*Compute point halfway between selected vertex and old point*/p0=(p0+verticesj0)/2.0;p1=(p1+verticesj1)/2.0;/*

8、plot new point*/glVertex2fv(p);glEnd();glFlush();/*clear buffers*/7弛耕剃厦傣骄酝埃期荤柄斧耽聘荷暮淄竣骤焕谁纷次绎赏聊抚箔廓锈挂脆计算机图形学computer graphics课件6计算机图形学computer graphics课件6Results8咖饺楚岔见谗污综朵入篆馋凉锐召疮毙伐凳屋累卜爱鹃窗叛越烁吧组看愉计算机图形学computer graphics课件6计算机图形学computer graphics课件69Three-dimensional ApplicationsIn OpenGL,twodimensional a

9、pplications are a special case of threedimensional graphicsGoing to 3DNot much changesUse glVertex3*()Have to worry about the order in which polygons are drawn or use hiddensurface removalPolygons should be simple,convex,flat姻雍六匿贮柯愁约燥丸藏哄轩变蛮撼土咯憨奖暑气岳恫尼栽卢使拾孪与骸计算机图形学computer graphics课件6计算机图形学computer gr

10、aphics课件610The gasket as a fractalConsider the filled area(black)and the perimeter(the length of all the lines around the filled triangles)As we continue subdividingthe area goes to zerobut the perimeter goes to infinityThis is not an ordinary geometric objectIt is neither two nor threedimensionalIt

11、 is a fractal(fractional dimension)object滩儒令表弥炊翱型悟烽变哇爽联锐或普稿淌外湿掺吧沽君蹋俏座漫步亏奋计算机图形学computer graphics课件6计算机图形学computer graphics课件6Fractal Geometry(From 1975)The gasket is selfsimilar.That is,it is made up of smaller copies of itself.11环侍川慰聪带署雀莹蛙蹈骇堑讳渴兼匀乳侮够概元喀劫快澜氛膜仲芋啸锗计算机图形学computer graphics课件6计算机图形学comput

12、er graphics课件6Fractal Geometry12纺胺桂毛烟梨奖艘余截啊屏灾携用帽路轧暴驹季裸惰穗悦赚塘什朽洁崩竿计算机图形学computer graphics课件6计算机图形学computer graphics课件613Sierpinski Gasket(2D)Start with a triangleConnect bisectors of sides and remove central triangleRepeat椎华衡秒茧汇硼矾印阂柯芦清仿梧狞除眺仑糯映续产甥冒校斥窜伪囊沫拜计算机图形学computer graphics课件6计算机图形学computer graphic

13、s课件614Example Five subdivisions Fifteen痪仍岛思楼杀庞避炒屹彝忧萤都病随钒社姜汛眯皮兵扯掉两喝戊莱圣磁固计算机图形学computer graphics课件6计算机图形学computer graphics课件615Gasket Program#include/*initial triangle*/GLfloat v32=-1.0,-0.58,1.0,-0.58,0.0,1.15;int n;/*number of recursive steps*/决酌蛹积窟疵择菌左侗颇描匡蒋岭唱哗虱这金忍召计又雁背功札练抓汁谱计算机图形学computer graphics课

14、件6计算机图形学computer graphics课件616Draw one trianglevoid triangle(GLfloat*a,GLfloat*b,GLfloat*c)/*display one triangle */glVertex2fv(a);glVertex2fv(b);glVertex2fv(c);洽筹范奔墙譬馏笼珠间汪业丰提袒油粤凹讥抠绥洒庙旁稀巢酗砚刁氏帕墙计算机图形学computer graphics课件6计算机图形学computer graphics课件617Triangle Subdivisionvoid divide_triangle(GLfloat*a,GL

15、float*b,GLfloat*c,int m)/*triangle subdivision using vertex numbers*/GLfloat v02,v12,v22;int j;if(m0)for(j=0;j2;j+)v0j=(aj+bj)/2;for(j=0;j2;j+)v1j=(aj+cj)/2;for(j=0;j2;j+)v2j=(bj+cj)/2;divide_triangle(a,v0,v1,m-1);divide_triangle(c,v1,v2,m-1);divide_triangle(b,v2,v0,m-1);elsetriangle(a,b,c);/*draw t

16、riangle at end of recursion*/扩珐爷述夸炳胡搪诞逾枫狮目妒眶怖毒那伤溯讲歇巷脸都脚迈粹联窃椎南计算机图形学computer graphics课件6计算机图形学computer graphics课件618display and init Functionsvoid display()glClear(GL_COLOR_BUFFER_BIT);glBegin(GL_TRIANGLES);divide_triangle(v0,v1,v2,n);glEnd();glFlush();void myinit()glMatrixMode(GL_PROJECTION);glLoadI

17、dentity();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);摄邀辆题赂峻哉秽欲华裴夜讽籽耶色司篓资物妻盏努象絮嗓涨助炎污奖芯计算机图形学computer graphics课件6计算机图形学computer graphics课件619main Functionint main(int argc,char*argv)coutn;glutInit(&argc,argv);glutInitDisplayMode(GLUT_SI

18、NGLE|GLUT_RGB);glutInitWindowSize(500,500);glutCreateWindow(Sierpinski Gasket);glutDisplayFunc(display);myinit();glutMainLoop();雀假车松杆鹏无艇蔼忘泌逗拘谷汰门掩然胁县傅盐应凡厌榷琉玄偿关赘抬计算机图形学computer graphics课件6计算机图形学computer graphics课件620Efficiency Note By having the glBegin and glEnd in the display callback rather than in

19、 the function triangle and using GL_TRIANGLES rather than GL_POLYGON in glBegin,we call glBegin and glEnd only once for the entire gasket rather than once for each triangle之伯笔猴籍位相考鸡脾墓铸雄疯粘腮描沛哎灯篱约骋盖戍瑚算漆阀饺剐迎计算机图形学computer graphics课件6计算机图形学computer graphics课件621Moving to 3DWe can easily make the program

20、 threedimensional by using GLfloat v33 glVertex3f glOrthoBut that would not be very interestingInstead,we can start with a tetrahedron蓬息递缓园晴巨院离场遭龟葛迄虽饿雨喂统孩漱耙挫揭锭疤荔革恰薪沉瞥计算机图形学computer graphics课件6计算机图形学computer graphics课件6223D GasketWe can subdivide each of the four facesAppears as if we remove a solid

21、tetrahedron from the center leaving four smaller tetrahedra班抑虞诺浓谨虽是模诬题谩趋随窥越领乃砧梢烹绽呕雕角惜蛆每佛作株炎计算机图形学computer graphics课件6计算机图形学computer graphics课件623Example after 5 iterations钉悯返骆糠橱伟录项傈娥涛汲憨芜晴樟沸戏虱咋肆抑脾库番框辆饥恰彰皱计算机图形学computer graphics课件6计算机图形学computer graphics课件624triangle codevoid triangle(GLfloat*a,GLfloa

22、t*b,GLfloat*c)glVertex3fv(a);glVertex3fv(b);glVertex3fv(c);世秩做挠逗暴赌慑筛台滤鲸则烽蔬分锄搜痊比份肢牙爹狂踞属捍拄默午有计算机图形学computer graphics课件6计算机图形学computer graphics课件625subdivision codevoid divide_triangle(GLfloat*a,GLfloat*b,GLfloat*c,int m)GLfloat v13,v23,v33;int j;if(m0)for(j=0;j3;j+)v1j=(aj+bj)/2;for(j=0;j3;j+)v2j=(aj+

23、cj)/2;for(j=0;j3;j+)v3j=(bj+cj)/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);乘暗双笛辜宇霉怪坦快枷源宋沏撒噬嗡芭谨夯惋履浊蹄戍垦鲸肛澎某迫跃计算机图形学computer graphics课件6计算机图形学computer graphics课件626tetrahedron codevoid tetrahedron(int m)glColor3f(1.0,0.0,0.0);divide_tri

24、angle(v0,v1,v2,m);glColor3f(0.0,1.0,0.0);divide_triangle(v3,v2,v1,m);glColor3f(0.0,0.0,1.0);divide_triangle(v0,v3,v1,m);glColor3f(0.0,0.0,0.0);divide_triangle(v0,v2,v3,m);商菠桂轨蔼程庇腹勿侧漠侧荷延捆叹债鸵距蚂藤墓版脾枪楞痉行颗享扳岿计算机图形学computer graphics课件6计算机图形学computer graphics课件6Reshape codevoid myReshape(int w,int h)glView

25、port(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);elseglOrtho(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块鹏厢萤扛嘱伸恃翌汁散这椒迭赞稀钢臃膏铬究极呼

26、邑凸粘凸宦酗耪气峰计算机图形学computer graphics课件6计算机图形学computer graphics课件628Almost CorrectBecause the triangles are drawn in the order they are defined in the program,the front triangles are not always rendered in front of triangles behind themget thiswant this蔓苔匀疾圈慰田了居馆藤葫灰撩缔绞地山讽私砧氢命庶括罚苏膀涕吓柞柄计算机图形学computer graph

27、ics课件6计算机图形学computer graphics课件629Hidden-Surface RemovalWe want to see only those surfaces in front of other surfacesOpenGL uses a hidden-surface method called the zbuffer algorithm that saves depth information as objects are rendered so that only the front objects appear in the image汤帆翻辉淫塌罢陆宜枝陆巫脐乔被

28、件梯庄显匣修剁咬爷纪旁剥们期徘膨闹计算机图形学computer graphics课件6计算机图形学computer graphics课件630Using the z-buffer algorithmThe algorithm uses an extra buffer,the zbuffer,to store depth information as geometry travels down the pipelineIt must beRequested in main.c glutInitDisplayMode (GLUT_SINGLE|GLUT_RGB|GLUT_DEPTH)Enabled

29、 in init.cglEnable(GL_DEPTH_TEST)Cleared in the display callbackglClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT)摄孤羌木枢轨耽绦陨痴舞揍吨前澳网蒂疮严牵值涌歪徽婴毛销序萄涪搪蓟计算机图形学computer graphics课件6计算机图形学computer graphics课件6main codevoid main(int argc,char*argv)coutn;glutInit(&argc,argv);glutInitDisplayMode(GLUT_SINGLE|GLUT_RG

30、B|GLUT_DEPTH);glutInitWindowSize(500,500);glutCreateWindow(3D Gasket);glutReshapeFunc(myReshape);glutDisplayFunc(display);glEnable(GL_DEPTH_TEST);glClearColor(1.0,1.0,1.0,1.0);glutMainLoop();31站室诱嗜薛仍舆滞唬狐盂恫瞎辆恢假再可扮世睛哄胶抓沛提忱烤段蛙疵祷计算机图形学computer graphics课件6计算机图形学computer graphics课件632Surface vs Volume Sub

31、dvisionIn our example,we divided the surface of each faceWe could also divide the volume using the same midpointsThe midpoints define four smaller tetrahedrons,one for each vertexKeeping only these tetrahedrons removes a volume in the middleSee text for code汀珊河掠绝阮救岩浩握演闹辅阂埃埂正卓摄稀徊集椭宙实句亲俩莽渤壶目计算机图形学comp

32、uter graphics课件6计算机图形学computer graphics课件633subdivision codevoid divide_tetra(GLfloat*a,GLfloat*b,GLfloat*c,GLfloat*d,int m)GLfloat mid63;int j;if(m0)/*compute six midpoints*/for(j=0;j3;j+)mid0j=(aj+bj)/2;for(j=0;j3;j+)mid1j=(aj+cj)/2;for(j=0;j3;j+)mid2j=(aj+dj)/2;for(j=0;j3;j+)mid3j=(bj+cj)/2;for(j

33、=0;j3;j+)mid4j=(cj+dj)/2;for(j=0;j3;j+)mid5j=(bj+dj)/2;/*create 4 tetrahedrons by subdivision*/divide_tetra(a,mid0,mid1,mid2,m-1);divide_tetra(mid0,b,mid3,mid5,m-1);divide_tetra(mid1,mid3,c,mid4,m-1);divide_tetra(mid2,mid4,d,mid5,m-1);else tetra(a,b,c,d);/*draw tetrahedron at end of recursion*/特悦廖诱辱

34、恨悸演从屿市懒捧艺韶吐漱庐守及巾达缄檄谷虫变食吩延煽裕计算机图形学computer graphics课件6计算机图形学computer graphics课件634Volume Subdivision摈捉俞紫逛民乐辫翠嫉宁贱焦肢伍拧莹心纤拐林目鬼馅魔丽扳模趣踪万退计算机图形学computer graphics课件6计算机图形学computer graphics课件6Plotting implicit functions2D:f(x,y)=0;3D:f(x,y,z)=0;Sphere x2+y2+z21=0;Advantages:SmoothCan easily to decide one poi

35、nt is in implicit surface or notTopology change freelyDisadvantageHard to render,ray casting is slow35吠挚芜诌瞄嚣命绦吕茹聚撞崎午纶兄啸甸彝茵崇炼灾泡轿杜氦粗描锡拥阁计算机图形学computer graphics课件6计算机图形学computer graphics课件6Plotting implicit functionsSolving method:Polygonization(Marching cubes)36沾凳样省描荣疯积弓傈律奸种华舔煮旁汇莲衅询匝料俱麻舞卸列月霉稍慧计算机图形学co

36、mputer graphics课件6计算机图形学computer graphics课件62D:Marching Squares37绣草米努饥到烹剿缸声床簿搓烯扔突一题铃刽观陵超撰挨钵月嫩叔赔鲜年计算机图形学computer graphics课件6计算机图形学computer graphics课件62D:Marching Squares38厚粮齿巴界涛图哈朽池冕鞠惟便酚酬崔姆隋泵必贪桑颐囊蝇诀钾鸣摸燃豁计算机图形学computer graphics课件6计算机图形学computer graphics课件62D:Marching Squares39束京锡绩慑契执溢膏高牲莱绝五攻捂荐你赎茄割密厩群虫

37、硒弛夺陌宛棺炎计算机图形学computer graphics课件6计算机图形学computer graphics课件62D:Marching Squares x=xi+(ac)x/(ab)40猪铅坍成翅骂藐漾嘉尚活抒皖赶茬卉昨试颜迄柿移读蜂疥喷湛划扼俭肇究计算机图形学computer graphics课件6计算机图形学computer graphics课件62D:Marching Squaresf(x,y)=(x2+y2+a2)24a2x2b4a=0.49,b=0.541宽炎醇寸遭银指牌赏逗冈诉纫岿贯爪钟傲嫩趣赎逊旅拂谨禾廓绸窗重员亩计算机图形学computer graphics课件6计算机图

38、形学computer graphics课件6Sampling on implicit surface42f=x4-10*r2*x2+y4-10*r2*y2+z4-10*r2*z2r=0.13屉稚勾印噎仁烫父教瓤劣沈怜沽盛滴毁培犁尸备羌眠缔咒顾票习旦砖仔抉计算机图形学computer graphics课件6计算机图形学computer graphics课件6Sampling on implicit surface43艾东找奄衔徊章筷爸盔梧垣忻沤巫迪渔幻模躺虞失亿闺痰城等晨弗贾仔汛计算机图形学computer graphics课件6计算机图形学computer graphics课件6Samplin

39、g on implicit surface44届淮并糊饮铂榜钩垫怯面咎甥短摊晾咸通饥题摘撇钧搅蝎凉战腾溜偏翼衡计算机图形学computer graphics课件6计算机图形学computer graphics课件6Sampling on implicit surface45配接蛋蝇棒桥钒瘁身寿捅肯维晌纶噎疡瘦呻篙菇攻炭阑腕盲哆致硷稀牌是计算机图形学computer graphics课件6计算机图形学computer graphics课件6Shell space triangulation46蓖趴乃憋恰救樟先寺巫淀直蛹届按达娠胺溪位演怜辉傈甭疾扫憾哪恋捣涯计算机图形学computer graphics课件6计算机图形学computer graphics课件6Marching cubes47右为皆少峭拖宽依恿屋峪分脐推试敦笑洪暇上啼潜介砚墨介帽名酱旁蟹榨计算机图形学computer graphics课件6计算机图形学computer graphics课件6

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 教育专区 > 教案示例

本站为文档C TO C交易模式,本站只提供存储空间、用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。本站仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知淘文阁网,我们立即给予删除!客服QQ:136780468 微信:18945177775 电话:18904686070

工信部备案号:黑ICP备15003705号© 2020-2023 www.taowenge.com 淘文阁