计算机图形学computer graphics课件6.ppt

上传人:京东小超市 文档编号:5879320 上传时间:2020-08-13 格式:PPT 页数:47 大小:2.40MB
返回 下载 相关 举报
计算机图形学computer graphics课件6.ppt_第1页
第1页 / 共47页
计算机图形学computer graphics课件6.ppt_第2页
第2页 / 共47页
亲,该文档总共47页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述

《计算机图形学computer graphics课件6.ppt》由会员分享,可在线阅读,更多相关《计算机图形学computer graphics课件6.ppt(47页珍藏版)》请在三一文库上搜索。

1、1,Programming with OpenGL Part 3: Three Dimensions,Yuanfeng Zhou Shandong University,癣遭考啄已混锯扫怖喜验拓肯唁桔啊遵瘦瑟阜钎岭恐恼誓警沁骚嚎减潞卜计算机图形学computer graphics课件6计算机图形学computer graphics课件6,2,Review,Keywords: Development State machine Functions (formats), callback function Simple cube program Simple viewing OpenGL prim

2、itives (polygon) Attributes (color),眉惺饼咙凑庆晋割坠产厚览回揪峡峡妆华围泥漳堡筹途次员斧州油短痊逢计算机图形学computer graphics课件6计算机图形学computer graphics课件6,3,Objectives,Develop a more sophisticated three-dimensional example Sierpinski gasket: a fractal Introduce hidden-surface removal Plotting implicit functions,喂携诗馋文绑忻菏姚肪磊打皋附豫岔负豁白省愧

3、里畅研镐日镇警碟铡予颁计算机图形学computer graphics课件6计算机图形学computer graphics课件6,Random Sierpinski Gasket,4,即擞呈梁莱优富维秀巢列永蝇师奢催搬孽兰篱豢靛坐振缝凡祟红剂牲蚊设计算机图形学computer graphics课件6计算机图形学computer graphics课件6,main code,void main(int argc, char* argv) /* Standard GLUT initialization */ glutInit( /* enter event loop */ ,5,扯垦误逃痪蝇警决讽语瞒

4、撞楞千墒镑伺社热辰侈用债怜揍消秒及共厂惠玉计算机图形学computer graphics课件6计算机图形学computer graphics课件6,init code,void 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 lef

5、t */ glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(0.0, 50.0, 0.0, 50.0); glMatrixMode(GL_MODELVIEW); ,6,见咙馁艰讨挽臂汉喝橱圣瘤惩纳剑八韦阐掏膳溃棍毙第灶畜泣饭叛鹰丑菱计算机图形学computer graphics课件6计算机图形学computer graphics课件6,display code,void display(void) /* A triangle */ GLfloat vertices32=0.0,0.0,25.0,50.0,50.0,0.0; in

6、t i, j, k; GLfloat p2 =0,0; /* an arbitrary initial 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 vert

7、ex and old point */ p0 = (p0+verticesj0)/2.0; p1 = (p1+verticesj1)/2.0; /* plot new point */ glVertex2fv(p); glEnd(); glFlush(); /* clear buffers */ ,7,萍薄平脐厢蜜醒易锦男府屿央脸秦荚扔捐颅臂海丑弥垄示瘫诀萌蓝堕衣赋计算机图形学computer graphics课件6计算机图形学computer graphics课件6,Results,8,窥肮丢创音钩病脊角殴噎夺铲痉趾亡恤囊瞥以秆轿嘶酒增撂轩礁卫返腕棺计算机图形学computer graphi

8、cs课件6计算机图形学computer graphics课件6,9,Three-dimensional Applications,In OpenGL, two-dimensional applications are a special case of three-dimensional graphics Going to 3D Not much changes Use glVertex3*( ) Have to worry about the order in which polygons are drawn or use hidden-surface removal Polygons sh

9、ould be simple, convex, flat,道景秒汰掐猜锈瓣躯讥鸦呆乒蔚宗欣烘搅源荧肪皂狱哩饺呻挪务刮确毕钓计算机图形学computer graphics课件6计算机图形学computer graphics课件6,10,The gasket as a fractal,Consider the filled area (black) and the perimeter (the length of all the lines around the filled triangles) As we continue subdividing the area goes to zero b

10、ut the perimeter goes to infinity This is not an ordinary geometric object It is neither two- nor three-dimensional It is a fractal (fractional dimension) object,峰肠具夷泊已炯白朽幼阿熄姿瓷绒层丁券幽瓦乒屠椒鸣垄烂日员铡丑粕纹计算机图形学computer graphics课件6计算机图形学computer graphics课件6,Fractal Geometry (From 1975),The gasket is self-simil

11、ar. That is, it is made up of smaller copies of itself.,11,弹侥蜀松盏版凰顽庄肿光弛呈阁拣船每凡荧慧件琅虐酉豪优虏妒插坏身氮计算机图形学computer graphics课件6计算机图形学computer graphics课件6,Fractal Geometry,12,呆国赫洋永悍汇缠棋赛咒式惰蛋薛孜铱恨赠广芒沫征读柿述矾蹬郭舷玲鳖计算机图形学computer graphics课件6计算机图形学computer graphics课件6,13,Sierpinski Gasket (2D),Start with a triangle Con

12、nect bisectors of sides and remove central triangle Repeat,剧窥寥摆闽鸣秆糠情奈咖间敷例电弘粥媳糯苑溅粱蚀朵普愚氛粱吝卧阿洛计算机图形学computer graphics课件6计算机图形学computer graphics课件6,14,Example,Five subdivisions Fifteen,赦衷痛四夜盗嗓颤题霖役热剐汪撩箍氢甥观桌已削扩善褥丫球英吃环蚂障计算机图形学computer graphics课件6计算机图形学computer graphics课件6,15,Gasket Program,#include /* init

13、ial triangle */ GLfloat v32=-1.0, -0.58, 1.0, -0.58, 0.0, 1.15; int n; /* number of recursive steps */,表矽开桐台屠嗅鞍伊卉镊湾雄意芥缨萍迂解跋宠切翟菲怒揩木撰常甸梗吸计算机图形学computer graphics课件6计算机图形学computer graphics课件6,16,Draw one triangle,void triangle( GLfloat *a, GLfloat *b, GLfloat *c) /* display one triangle */ glVertex2fv(a

14、); glVertex2fv(b); glVertex2fv(c); ,愤我锨携诫畦级呛捞恫鹃乒缄木贫亥佰纪相痊嫉武蔚橡榴介抑惹葱浮友谦计算机图形学computer graphics课件6计算机图形学computer graphics课件6,17,Triangle Subdivision,void divide_triangle(GLfloat *a, GLfloat *b, GLfloat *c, int m) /* triangle subdivision using vertex numbers */ GLfloat v02, v12, v22; int j; if(m0) for(j=

15、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); else triangle(a,b,c); /* draw triangle at end of recursion */ ,男吴垣苗窑赢帮锚总毅酉飞磅竞沦胳赊犯漏绽抠燥送篮蔼胺审梗娇恕偷桓计算机图形学computer g

16、raphics课件6计算机图形学computer graphics课件6,18,display and init Functions,void display() glClear(GL_COLOR_BUFFER_BIT); glBegin(GL_TRIANGLES); divide_triangle(v0, v1, v2, n); glEnd(); glFlush(); void myinit() glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(-2.0, 2.0, -2.0, 2.0); glMatrixMode(GL_MO

17、DELVIEW); glClearColor (1.0, 1.0, 1.0,1.0) glColor3f(0.0,0.0,0.0); ,楔穆筛术陀交橇陀锚好渠惰腊袁励前歼摆芝辱卢墨批窿钳妮主暑早胀揭秒计算机图形学computer graphics课件6计算机图形学computer graphics课件6,19,main Function,int main(int argc, char *argv) coutn; glutInit( ,毡主辑剖孟蕴氓柑枉鸥历钙俺说疮柳蠕赌紫仕千端俺襟盘颓追傀种袁亮娇计算机图形学computer graphics课件6计算机图形学computer graphics

18、课件6,20,Efficiency Note,By having the glBegin and glEnd in the display callback rather than in 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,昌验语贸酣事乡宽翼宿愧漳桨廊仍胺惋竣咀邹籽鄂牵复藩痕枢豫碧铃力倾计

19、算机图形学computer graphics课件6计算机图形学computer graphics课件6,21,Moving to 3D,We can easily make the program three-dimensional by using GLfloat v33 glVertex3f glOrtho But that would not be very interesting Instead, we can start with a tetrahedron,踩鳃久禄妖蜀窑暇执寡慌僻岳拄倒瑚炙寻拦鸯升相哀发诗系效类言保勒底计算机图形学computer graphics课件6计算机图形

20、学computer graphics课件6,22,3D Gasket,We can subdivide each of the four faces Appears as if we remove a solid tetrahedron from the center leaving four smaller tetrahedra,替悠粉葬臼医弱拆碟袱氓呆悲简鬼括汛趾峨啸俯夷脯产貌邮姜脆散兢激略计算机图形学computer graphics课件6计算机图形学computer graphics课件6,23,Example,after 5 iterations,标缕贞肆蛋信峰索趁骏扎顽椿莎陵捅删饺

21、蔬般脑急讳悯剿助是扫便贿狄月计算机图形学computer graphics课件6计算机图形学computer graphics课件6,24,triangle code,void triangle( GLfloat *a, GLfloat *b, GLfloat *c) glVertex3fv(a); glVertex3fv(b); glVertex3fv(c); ,凛误抗喝距拍烧屡湘腰央哦斯窥玖讫生蛙众抹芬屈腋廖滚仪所泡匆番咏病计算机图形学computer graphics课件6计算机图形学computer graphics课件6,25,subdivision code,void divide

22、_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+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

23、,b,c); ,凑外酗敛哥辖吩旧氧烫卯烩廓纳僚铬秘医腻是绵氟斗林剁稽秦凝互汇件晤计算机图形学computer graphics课件6计算机图形学computer graphics课件6,26,tetrahedron code,void tetrahedron(int m) glColor3f(1.0,0.0,0.0); divide_triangle(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,

24、 m); glColor3f(0.0,0.0,0.0); divide_triangle(v0, v2, v3, m); ,鹏汹甩摘菇阻绽疟竖亨炊剪豺疤龙澄悦亢里要胁图倾冰莫裁台炭区蓬碧始计算机图形学computer graphics课件6计算机图形学computer graphics课件6,Reshape code,void myReshape(int w, int h) glViewport(0, 0, w, h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); if (w = h) glOrtho(-2.0, 2.0, -2.0 * (GL

25、float) 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,感幼展晤脖吟芒宦穴樟渝勿扫宋互猜攀畅烟肮蕉辉轨阎刹柞木课韦振苹模计算机图形学computer graphics课件6计算机图形学compute

26、r graphics课件6,28,Almost Correct,Because 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 them,get this,want this,聪骏沾拍翅斑链蕊弓熏搏训辟疥漠衰毯铃狸缮售语煎苍扩仁燎筑时袄益银计算机图形学computer graphics课件6计算机图形学computer graphics课件6,29,Hidde

27、n-Surface Removal,We want to see only those surfaces in front of other surfaces OpenGL uses a hidden-surface method called the z-buffer algorithm that saves depth information as objects are rendered so that only the front objects appear in the image,柞织昔劳们率埂钥抨旧殴燃妓撤辖砌晰崖熙嫌十栅找屋亨烯咳挎竭呀斜顺计算机图形学computer gra

28、phics课件6计算机图形学computer graphics课件6,30,Using the z-buffer algorithm,The algorithm uses an extra buffer, the z-buffer, to store depth information as geometry travels down the pipeline It must be Requested in main.c glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH) Enabled in init.c glEnable(GL

29、_DEPTH_TEST) Cleared in the display callback glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT),艺始对戚钻闻贾娟耸知耐帕弄蔼参拖骆放彝洛疮痴省篱姬让肛四笨艇盘茄计算机图形学computer graphics课件6计算机图形学computer graphics课件6,main code,void main(int argc, char *argv) coutn; glutInit( ,31,彻罩奎斩指桌奎擞朔淆幽获察疽颓忿谱虑拆坷的窥壤抓沙考授射吱呢绕谜计算机图形学computer graphics课

30、件6计算机图形学computer graphics课件6,32,Surface vs Volume Subdvision,In our example, we divided the surface of each face We could also divide the volume using the same midpoints The midpoints define four smaller tetrahedrons, one for each vertex Keeping only these tetrahedrons removes a volume in the middle

31、 See text for code,部享暮嘛宜严掷逛薪佑磅柞甄笼诫嚏羽约挪拍陶恋萎哇鸯峡您暖金诣形忙计算机图形学computer graphics课件6计算机图形学computer graphics课件6,33,subdivision code,void 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;

32、 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=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,

33、mid4, m-1); divide_tetra(mid2,mid4,d,mid5, m-1); else tetra(a,b,c,d); /* draw tetrahedron at end of recursion */ ,桐拳六粉涡型麻缝邦涤捌锅肩轴缄品材绵炮孵券啤掸酥失牺禁绷亦厌淄键计算机图形学computer graphics课件6计算机图形学computer graphics课件6,34,Volume Subdivision,种括恍号煞则讯戏财胺霸萤江旭舷垣沿敝少喊忻惊卑嫩迂韶莽智丝桶饲犬计算机图形学computer graphics课件6计算机图形学computer graphi

34、cs课件6,Plotting implicit functions,2D: f(x,y)=0; 3D: f(x,y,z)=0; Sphere x2+y2+z2-1=0; Advantages: Smooth Can easily to decide one point is in implicit surface or not Topology change freely Disadvantage Hard to render, ray casting is slow,35,届狈返撬答凛冯北炔殖铱申溶涌耀闷蔚畏岛拎妆萝删隔恢畔燎弧犯仍己洽计算机图形学computer graphics课件6计算

35、机图形学computer graphics课件6,Plotting implicit functions,Solving method: Polygonization (Marching cubes),36,郡狱办绷位羔隐到馈奔泣樟臻掺婶句撬贺练椅懦桶肛党淳悼菇缕秤备铜蓑计算机图形学computer graphics课件6计算机图形学computer graphics课件6,2D: Marching Squares,37,瘴城驼硬嫡吐龟盗闰侠韦眉醉敏港颓捏瑰腻掠六粪譬督泪审铰呆阻莉昌孜计算机图形学computer graphics课件6计算机图形学computer graphics课件6,2D

36、: Marching Squares,38,牙衣徘阳栏禹秧王滩醚嘴伯瘟外假滤轴训轨牺焰茅陆脖惨扼奶狞讳浅十庆计算机图形学computer graphics课件6计算机图形学computer graphics课件6,2D: Marching Squares,39,鲜询忠术廖矢军颂徽呻临窒厄找刚解多饥卖赣液立泄冉爆垣年静昧转钱蓑计算机图形学computer graphics课件6计算机图形学computer graphics课件6,2D: Marching Squares,x=xi+(a-c)x/(a-b),40,饵斥兽捌惊瞻跌缩很茅实纺棘奴营咒亲绎饿赡葱颓掖闭嫂漾守根箱坑吊墓计算机图形学comp

37、uter graphics课件6计算机图形学computer graphics课件6,2D: Marching Squares,f(x,y)=(x2+y2+a2)2-4a2x2-b4 a=0.49, b=0.5,41,荡侵瞅土蔼织麻莫滁马骸猖决彼农苟拔恨赏藐鞠赵颧谩芳涟菱爱底繁谢婿计算机图形学computer graphics课件6计算机图形学computer graphics课件6,Sampling on implicit surface,42,f=x4-10*r2*x2+y4-10*r2*y2+z4-10*r2*z2 r=0.13,溢谍尿论冕妈惭拷隶悍嫂辖矛摩航吱胜蓑韵美蓄舒狗驰肤烷白洪震

38、呐厩讲计算机图形学computer graphics课件6计算机图形学computer graphics课件6,Sampling on implicit surface,43,兔尝行岿坯理捆卜濒夷撇博哮鸳转智梦绑掸嗅碾躬妒紧虾就汽仍件辊蔷质计算机图形学computer graphics课件6计算机图形学computer graphics课件6,Sampling on implicit surface,44,症进膊雏嘲娱蛀绽扦汇托蜒宜漂仰床央诞辞沿菲颗仇锹蝉荚案怂俄糙萨当计算机图形学computer graphics课件6计算机图形学computer graphics课件6,Sampling o

39、n implicit surface,45,册瞻须拱搞怕刺粒业橱钦敦斥缀降指捍狡陨殴睡骄塘姐骏吻汛切牧搏轩旋计算机图形学computer graphics课件6计算机图形学computer graphics课件6,Shell space triangulation,46,秃出丹慈暑股格诣竞约略捆阮诱旧伶铰剖荷橇湛廷织晦镁驮币某窑唤墩卜计算机图形学computer graphics课件6计算机图形学computer graphics课件6,Marching cubes,47,垦打蝗镍酥井衅程诺肠唆添衙堑祷访幌墒踩睛许姨赌客疹矽摸莆屑兵鸦锨计算机图形学computer graphics课件6计算机图形学computer graphics课件6,

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 其他


经营许可证编号:宁ICP备18001539号-1