计算机图形学computergraphics课件6.ppt
《计算机图形学computergraphics课件6.ppt》由会员分享,可在线阅读,更多相关《计算机图形学computergraphics课件6.ppt(47页珍藏版)》请在三一办公上搜索。
1、1,Programming with OpenGLPart 3:Three Dimensions,Yuanfeng ZhouShandong University,癣遭考啄已混锯扫怖喜验拓肯唁桔啊遵瘦瑟阜钎岭恐恼誓警沁骚嚎减潞卜计算机图形学computer graphics课件6计算机图形学computer graphics课件6,2,Review,Keywords:DevelopmentState machineFunctions(formats),callback functionSimple cube programSimple viewingOpenGL primitives(poly
2、gon)Attributes(color),眉惺饼咙凑庆晋割坠产厚览回揪峡峡妆华围泥漳堡筹途次员斧州油短痊逢计算机图形学computer graphics课件6计算机图形学computer graphics课件6,3,Objectives,Develop a more sophisticated three-dimensional exampleSierpinski gasket:a fractalIntroduce hidden-surface removalPlotting implicit functions,喂携诗馋文绑忻菏姚肪磊打皋附豫岔负豁白省愧里畅研镐日镇警碟铡予颁计算机图形学c
3、omputer 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,扯垦误逃痪蝇警决讽语瞒撞楞千墒镑伺社热辰侈用债怜揍消秒及共厂惠玉计算机图形学c
4、omputer 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 left*/glMatrixMode(GL_PROJECTION);glLoadIdentity();glu
5、Ortho2D(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;int i,j,k;GLfloat p2=0,0;/*an arbitrary initial point inside traing
6、le*/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;/*plot new point*/glVertex2
7、fv(p);glEnd();glFlush();/*clear buffers*/,7,萍薄平脐厢蜜醒易锦男府屿央脸秦荚扔捐颅臂海丑弥垄示瘫诀萌蓝堕衣赋计算机图形学computer graphics课件6计算机图形学computer graphics课件6,Results,8,窥肮丢创音钩病脊角殴噎夺铲痉趾亡恤囊瞥以秆轿嘶酒增撂轩礁卫返腕棺计算机图形学computer graphics课件6计算机图形学computer graphics课件6,9,Three-dimensional Applications,In OpenGL,two-dimensional applications are
8、a special case of three-dimensional graphicsGoing to 3DNot much changesUse glVertex3*()Have to worry about the order in which polygons are drawn or use hidden-surface removalPolygons should be simple,convex,flat,道景秒汰掐猜锈瓣躯讥鸦呆乒蔚宗欣烘搅源荧肪皂狱哩饺呻挪务刮确毕钓计算机图形学computer graphics课件6计算机图形学computer graphics课件6,10,
9、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 subdividingthe area goes to zerobut the perimeter goes to infinityThis is not an ordinary geometric objectIt is neither two-nor three-dimensionalIt is a fra
10、ctal(fractional dimension)object,峰肠具夷泊已炯白朽幼阿熄姿瓷绒层丁券幽瓦乒屠椒鸣垄烂日员铡丑粕纹计算机图形学computer graphics课件6计算机图形学computer graphics课件6,Fractal Geometry(From 1975),The gasket is self-similar.That is,it is made up of smaller copies of itself.,11,弹侥蜀松盏版凰顽庄肿光弛呈阁拣船每凡荧慧件琅虐酉豪优虏妒插坏身氮计算机图形学computer graphics课件6计算机图形学computer
11、graphics课件6,Fractal Geometry,12,呆国赫洋永悍汇缠棋赛咒式惰蛋薛孜铱恨赠广芒沫征读柿述矾蹬郭舷玲鳖计算机图形学computer graphics课件6计算机图形学computer graphics课件6,13,Sierpinski Gasket(2D),Start with a triangleConnect bisectors of sides and remove central triangleRepeat,剧窥寥摆闽鸣秆糠情奈咖间敷例电弘粥媳糯苑溅粱蚀朵普愚氛粱吝卧阿洛计算机图形学computer graphics课件6计算机图形学computer gra
12、phics课件6,14,Example,Five subdivisions Fifteen,赦衷痛四夜盗嗓颤题霖役热剐汪撩箍氢甥观桌已削扩善褥丫球英吃环蚂障计算机图形学computer graphics课件6计算机图形学computer graphics课件6,15,Gasket Program,#include/*initial triangle*/GLfloat v32=-1.0,-0.58,1.0,-0.58,0.0,1.15;int n;/*number of recursive steps*/,表矽开桐台屠嗅鞍伊卉镊湾雄意芥缨萍迂解跋宠切翟菲怒揩木撰常甸梗吸计算机图形学compute
13、r graphics课件6计算机图形学computer graphics课件6,16,Draw one triangle,void triangle(GLfloat*a,GLfloat*b,GLfloat*c)/*display one triangle*/glVertex2fv(a);glVertex2fv(b);glVertex2fv(c);,愤我锨携诫畦级呛捞恫鹃乒缄木贫亥佰纪相痊嫉武蔚橡榴介抑惹葱浮友谦计算机图形学computer graphics课件6计算机图形学computer graphics课件6,17,Triangle Subdivision,void divide_tria
14、ngle(GLfloat*a,GLfloat*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);elsetriangl
15、e(a,b,c);/*draw triangle at end of recursion*/,男吴垣苗窑赢帮锚总毅酉飞磅竞沦胳赊犯漏绽抠燥送篮蔼胺审梗娇恕偷桓计算机图形学computer graphics课件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(G
16、L_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);,楔穆筛术陀交橇陀锚好渠惰腊袁励前歼摆芝辱卢墨批窿钳妮主暑早胀揭秒计算机图形学computer graphics课件6计算机图形学computer graphics课件6,19,main Function,int main(int argc,char*argv)coutn;glutInit(,毡主辑剖孟蕴氓柑枉鸥历钙俺
17、说疮柳蠕赌紫仕千端俺襟盘颓追傀种袁亮娇计算机图形学computer graphics课件6计算机图形学computer graphics课件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 r
18、ather than once for each triangle,昌验语贸酣事乡宽翼宿愧漳桨廊仍胺惋竣咀邹籽鄂牵复藩痕枢豫碧铃力倾计算机图形学computer graphics课件6计算机图形学computer graphics课件6,21,Moving to 3D,We can easily make the program three-dimensional by using GLfloat v33 glVertex3f glOrthoBut that would not be very interestingInstead,we can start with a tetrahedron
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 计算机 图形学 computergraphics 课件

链接地址:https://www.31ppt.com/p-4842095.html