计算机图形学computer graphics课件6.ppt
《计算机图形学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计算机图形
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 计算机图形学computer graphics课件6 计算机 图形学 computer graphics 课件
链接地址:https://www.31doc.com/p-5879320.html