高级计算机图形学

Similar documents
高级计算机图形学

高级计算机图形学

高级计算机图形学

高级计算机图形学

C 1


untitled

山东建筑大学学分制管理规定(试行)

FY.DOC






新版 明解C++入門編

PowerPoint Presentation

第 一 节 认 识 自 我 的 意 义 一 个 人 只 有 认 识 自 我, 才 能 够 正 确 地 认 识 到 自 己 的 优 劣 势, 找 出 自 己 的 职 业 亮 点, 为 自 己 的 顺 利 求 职 推 波 助 澜 ; 一 个 人 只 有 认 识 自 我, 才 能 在 求 职 中 保 持

致理技術學院

<4D F736F F D20BACEECF1E2D3A3BAD6D0D2BDC0EDC2DBB5C4BACBD0C4CAC7CEB1BFC6D1A72E646F63>

<B0DACDD1D1C7BDA1BFB5B5C4C0A7C8C52E733932>

把生命托付给谁?

《中老年男性养生保健》

1 行 业 发 展 不 平 衡 我 国 房 地 产 中 介 服 务 业 起 步 较 晚, 专 业 分 工 程 度 和 国 外 发 达 国 家 相 比 还 有 很 大 差 距 房 地 产 中 介 服 务 行 业 的 发 展 水 平 与 房 地 产 开 发 行 业 的 市 场 化 水 平 密 切 相 关

汇集全球21位医生的经验和智慧,总结出最实用的专业建议,这些都是最值得你牢记的健康提醒

2 黑 色 皇 后 兵 向 前 移 動 兩 格 3 白 色 主 教 兵 4 黑 色 皇 后 對 角 移 動 到 對 吃 掉 白 色 國 王 的 位 置 在 這 個 章 節 中 你 會 學 到 1 打 開 設 定 關 鍵 (Set Key) 模 式 2 使 用 在 檢 視 軌 跡 中 的 可 設 定

Microsoft PowerPoint - chapter09.ppt

概述

untitled

Microsoft Word - 实用案例.doc

mvc

台北市立大安高工職業學校

chap02_part2

绘制OpenCascade中的曲线

Microsoft Word - 01.DOC

Java

高级计算机图形学

1 Project New Project 1 2 Windows 1 3 N C test Windows uv2 KEIL uvision2 1 2 New Project Ateml AT89C AT89C51 3 KEIL Demo C C File

epub 94-3

三維空間之機械手臂虛擬實境模擬

JLX

C/C++语言 - 分支结构

FIT1改1.FIT)

coverage2.ppt

Microsoft PowerPoint - cg_ch02_01

ebook39-5

第3章.doc

Strings

BOOL EnumWindows(WNDENUMPROC lparam); lpenumfunc, LPARAM (Native Interface) PowerBuilder PowerBuilder PBNI 2

51 C 51 isp 10 C PCB C C C C KEIL

Microsoft PowerPoint 龍華科技大學遊戲系-Unity teaching

Microsoft Word - 09.doc

CC213

C/C++语言 - C/C++数据

untitled

3. 反 映 : 4. 五 花 八 门 : 5. 慷 慨 : 6. 参 与 : 7. 慰 劳 : 8. 延 续 : 9. 珍 爱 : 10. 浪 漫 : 三. 找 出 下 列 每 组 词 中 的 近 义 词 或 同 义 词 : 节 日 节 气 节 令 时 节 习 俗 民 俗 仪 式 风 俗 文 献

fvalue = (pdata[y][i] + pdata[y][i + 1]) / 2; pdata[y][nhalfw + i] -= fvalue; fvalue = (pdata[y][nhalfw - 1] + pdata[y][nhalfw - 2]) / 2; pdata[y][nwi

3D 水墨動畫研製 劉啟東梁詠傑 許倫維 鄭景文 葉坤育 陳楷壬 朝陽科技大學資訊工程系 摘要 水墨文化在中國的文化有相當長久的歷史, 利用墨汁的濃淡以及毛筆的運用來描繪出對比極為強烈的圖, 使其產生不同的渲染效果 我們利用 opengl(open Gra

Text 文字输入功能 , 使用者可自行定义文字 高度, 旋转角度 , 行距 , 字间距离 和 倾斜角度。

说 : 荀 子 极 偏 驳, 只 一 句 性 恶, 大 本 已 失 5 朱 熹 说 : 荀 扬 不 惟 说 性 不 是, 从 头 到 底 皆 不 识 6 采 取 的 都 是 这 种 理 论 框 架 另 一 种 理 论 框 架 始 于 20 世 纪 前 期, 这 便 是 诸 子 学 研 究 的 框 架


應用3D/VR虛擬實境技術於踝關節之3D/VR模擬驗證

Adobe® Flash® 的 Adobe® ActionScript® 3.0 程式設計

第三节 软件测试的过程与策略

微积分 授课讲义

Microsoft PowerPoint - OpenGL简介.ppt [兼容模式]

C++ 程式設計

Transcription:

高级计算机图形学 讲授 : 董兰芳研究方向 : 科学计算可视化图形 图像处理模式识别 Telephone:0551-3603484 Email:lfdong@ustc.edu.cn Homepage: http://staff.ustc.edu.cn/~lfdong 中国科学技术大学视觉计算与可视化实验室 1

第四章几何对象和变换 (3)( 4.5 OpenGL 中的标架 4.6 建模一个彩色立方体 4.7 OpenGL 中几何变换 4.8 虚拟跟踪球 2

4.5 OpenGL 中的标架 对象坐标系或建模坐标系 世界坐标系 照相机坐标系 裁剪坐标系 规范化的设备坐标系 窗口坐标系或者屏幕坐标系 3

4.5 OpenGL 中的标架 4

4.5 OpenGL 中的标架 世界坐标系下的表示到照相机坐标系下的表示的变换矩阵 : 5

第四章几何对象和变换 (3)( 4.5 OpenGL 中的标架 4.6 建模一个彩色立方体 4.7 OpenGL 中几何变换 4.8 虚拟跟踪球 6

4.6.1 建模立方体的面 void polygon(int a, int b, int c, int d) GLfloat vertices[][3] = { glbegin(gl_polygon); {{-1.0,-1.0,-1.0}, glcolor3fv(colors[a]); {1.0,-1.0,-1.0},{1.0,1.0,-1.0}, glnormal3fv(normals[a]); {-1.0,1.0,-1.0}, {-1.0,-1.0,1.0}, glvertex3fv(vertices[a]); {1.0,-1.0,1.0}, {1.0,1.0,1.0}, glcolor3fv(colors[b]); {-1.0,1.0,1.0}}; glnormal3fv(normals[b]); glvertex3fv(vertices[b]); GLfloat colors[][3] = glcolor3fv(colors[c]); {{0.0,0.0,0.0},{1.0,0.0,0.0}, glnormal3fv(normals[c]); {1.0,1.0,0.0}, {0.0,1.0,0.0}, glvertex3fv(vertices[c]); {0.0,0.0,1.0},{1.0,0.0,1.0}, glcolor3fv(colors[d]); 1.0,1.0,1.0}, {0.0,1.0,1.0}}; glnormal3fv(normals[d]); glvertex3fv(vertices[d]); glend();} 7

4.6.2 向内和向外的面 8

4.6.3 对象表示的数据结构 9

4.6.4 彩色立方体 void polygon(int a, int b, int c, int d) GLfloat vertices[][3] = {{-1.0,-1.0,-1.0}, { glbegin(gl_polygon); glcolor3fv(colors[a]); {1.0,-1.0,-1.0},{1.0,1.0,-1.0}, glnormal3fv(normals[a]); void colorcube(void) {-1.0,1.0,-1.0}, {-1.0,-1.0,1.0}, glvertex3fv(vertices[a]); { polygon(0,3,2,1); {1.0,-1.0,1.0}, {1.0,1.0,1.0}, glcolor3fv(colors[b]); polygon(2,3,7,6); {-1.0,1.0,1.0}}; glnormal3fv(normals[b]); polygon(0,4,7,3); glvertex3fv(vertices[b]); polygon(1,2,6,5); glcolor3fv(colors[c]); GLfloat colors[][3] = polygon(4,5,6,7); glnormal3fv(normals[c]); {{0.0,0.0,0.0},{1.0,0.0,0.0}, polygon(0,1,5,4); glvertex3fv(vertices[c]); {1.0,1.0,0.0}, {0.0,1.0,0.0}, } glcolor3fv(colors[d]); {0.0,0.0,1.0},{1.0,0.0,1.0}, glnormal3fv(normals[d]); 1.0,1.0,1.0}, {0.0,1.0,1.0}}; glvertex3fv(vertices[d]); glend();} 10

4.6.5 双线性插值 11

4.6.6 顶点数组 GLfloat vertices[][3] = {{-1.0,-1.0,-1.0}, {1.0,-1.0,-1.0},{1.0,1.0,-1.0}, {-1.0,1.0,-1.0}, {-1.0,-1.0,1.0}, {1.0,-1.0,1.0}, {1.0,1.0,1.0}, {-1.0,1.0,1.0}}; GLfloat colors[][3] = {{0.0,0.0,0.0},{1.0,0.0,0.0}, {1.0,1.0,0.0}, {0.0,1.0,0.0}, {0.0,0.0,1.0},{1.0,0.0,1.0}, 1.0,1.0,1.0}, {0.0,1.0,1.0}}; GLubyte cubeindices[]={ 0,3,2,1, 2,3,7,6, 0,4,7,3, 1,2,6,5, 4,5,6,7, 0,1,5,4}; glvertexpointer(3,gl_float, 0, vertices); glcolorpointer(3,gl_float, 0, colors); gldrawelements(gl_quads,24, GL_UNSIGNED_BYTE, cubeindices); 12

第四章几何对象和变换 (3)( 4.5 OpenGL 中的标架 4.6 建模一个彩色立方体 4.7 OpenGL 中几何变换 4.8 虚拟跟踪球 13

4.7 OpenGL 中的几何变换 当前变换矩阵 CTM: 14

4.7 OpenGL 中的几何变换 OpenGL 的矩阵操作指定一个 4*4 的建模观察矩阵为当前矩阵 OpenGL 中的 4 种矩阵模式 : 建模观察模式, 允许保存 32 个矩阵投影模式纹理模式颜色模式 OpenGl 按照列优先次序存储矩阵元素 15

4.7 OpenGL 中的几何变换 旋转 平移和缩放 : glrotatef(angle,vx,vy,vz); gltranslatef(dx,dy,dz); glscalef(sx,sy,sz); glloadmatrixf(pointer_to_matrix); glloadidentity(); 16

4.7 OpenGL 中的几何变换 在 OpenGL 中实现具有任意不动点的旋转 : glmatrixmode(gl_modelview); glloadidentity(); gltranslatef(4.0,5.0,6.0); glrotatef(45.0,1.0,2.0,3.0); gltranslatef(-4.0,-5.0,-6.0); 17

4.7 OpenGL 中的几何变换 变换的顺序 : C<-I C<-CT(4.0,5.0,6.0) C<-CR(45.0,1.0,2.0,3.0) C<-CT(-4.0,-5.0,-6.0) C=T(4.0,5.0,6.0)R(45.0,1.0,2.0,3.0) T(-4.0,-5.0,-6.0) 18

4.7 OpenGL 中的几何变换 glulookat(eyex, eyey, eyez, /* 视点 */ atx, aty, atz, /* 参考点 */ upx, upy, upz); /* 观察正向 */ 19

4.7 OpenGL 中的几何变换 例 : glcolor3f (0.0, 0.0, 1.0); glrecti (50, 100, 200, 150); // Display blue rectangle. glcolor3f (1.0, 0.0, 0.0); gltranslatef (-200.0, -50.0, 0.0); // Set translation parameters. glrecti (50, 100, 200, 150); // Display red, translated rectangle. glloadidentity ( ); // Reset current matrix to identity. glrotatef (90.0, 0.0, 0.0, 1.0); // Set 90-deg. rotation about z axis. glrecti (50, 100, 200, 150); // Display red, rotated rectangle. glloadidentity ( ); // Reset current matrix to identity. glscalef (-0.5, 1.0, 1.0); // Set scale-reflection parameters. glrecti (50, 100, 200, 150); // Display red, transformed rectangle. 20

4.7 OpenGL 中的几何变换 例 : glmatrixmode (GL_MODELVIEW); glcolor3f (0.0, 0.0, 1.0); // Set current color to blue. glrecti (50, 100, 200, 150); // Display blue rectangle. glpushmatrix ( ); // Make copy of identity (top) matrix. glcolor3f (1.0, 0.0, 0.0); // Set current color to red. gltranslatef (-200.0, -50.0, 0.0); // Set translation parameters. glrecti (50, 100, 200, 150); // Display red, translated rectangle. glpopmatrix ( ); // Throw away the translation matrix. glpushmatrix ( ); // Make copy of identity (top) matrix. glrotatef (90.0, 0.0, 0.0, 1.0); // Set 90-deg. rotation about z axis. glrecti (50, 100, 200, 150); // Display red, rotated rectangle. glpopmatrix ( ); // Throw away the rotation matrix. glscalef (-0.5, 1.0, 1.0); // Set scale-reflection parameters. glrecti (50, 100, 200, 150); // Display red, transformed rectangle. 21

4.7 OpenGL 中的几何变换 立方体的旋转 : glutdisplayfunc(display); glutidlefunc(spincube); glutmousefunc(mouse); void spincube() { theta[axis] += 2.0; if( theta[axis] > 360.0 ) theta[axis] -= 360.0; glutpostredisplay(); } void display(void) { glclear(gl_color_buffer_bit GL_DEPTH_BUFFER_BIT); glloadidentity(); glulookat(1.0,1.0,1.0,0.0,0.0,0.0,0.0,1.0,0.0); gltranslatef(0.0, 3.0, 0.0); glrotatef(theta[0], 1.0, 0.0, 0.0); glrotatef(theta[1], 0.0, 1.0, 0.0); glrotatef(theta[2], 0.0, 0.0, 1.0); glcolorpointer(3,gl_float, 0, colors); gldrawelements(gl_quads, 24, GL_UNSIGNED_BYTE, cubeindices); glutswapbuffers(); } 22

4.7 OpenGL 中的几何变换 立方体的旋转变换矩阵的加载 进栈和出栈 : glloadmatrixf(myarray) glmultmatrixf(myarray) Glfloat m[4][4]; Glfloat myarray[16]; glpushmatrix(); gltranslatef( ); gltranslatef( ); gltranslatef( ); glpopmatrix(); for(i=0;i<3;i++) for(j=0;j<3;j++) myarray[4*j+i]=m[i][j]; 23

第四章几何对象和变换 (3)( 4.5 OpenGL 中的标架 4.6 建模一个彩色立方体 4.7 OpenGL 中的几何变换 4.8 虚拟跟踪球 24

4.8 虚拟跟踪球 25

4.8 虚拟跟踪球 int float bool bool bool winwidth, winheight; angle = 0.0, axis[3], trans[3]; trackingmouse = false; redrawcontinue = false; trackballmove = false; main(int argc, char **argv) { glutinit(&argc, argv); glutinitdisplaymode(glut_double GLUT_RGB GLUT_DEPTH); glutinitwindowsize(500, 500); glutcreatewindow("colorcube"); glutreshapefunc(myreshape); glutdisplayfunc(display); glutidlefunc(spincube); glutmousefunc(mousebutton); glutmotionfunc(mousemotion); glenable(gl_depth_test); glmatrixmode(gl_projection); glloadidentity(); glortho(-2.0, 2.0, -2.0, 2.0, -2.0, 2.0); glmatrixmode(gl_modelview); glutmainloop(); } 26

4.8 虚拟跟踪球 void display(void) { glclear(gl_color_buffer_bit GL_DEPTH_BUFFER_BIT); /* view transform */ //glpushmatrix(); if (trackballmove) { glrotatef(angle, axis[0], axis[1], axis[2]); } colorcube(); //glpopmatrix(); glutswapbuffers(); } void mousebutton(int button, int state, int x, int y) { if(button==glut_right_button) exit(0); if(button==glut_left_button) switch(state) { case GLUT_DOWN: y=winheight-y; startmotion( x,y); break; case GLUT_UP: stopmotion( x,y); break; } } 27

4.8 虚拟跟踪球 startmotion(int x, int y) { } trackingmouse = true; redrawcontinue = false; startx = x; starty = y; curx = x; cury = y; trackball_ptov(x, y, winwidth, winheight, lastpos); trackballmove=true; stopmotion(int x, int y) { trackingmouse = false; if (startx!= x starty!= y) { redrawcontinue = true; } else { angle = 0.0F; redrawcontinue = false; trackballmove = false; } } 28

4.8 虚拟跟踪球 mousemotion(int x, int y) { float curpos[3], dx, dy, dz; trackball_ptov(x, y, winwidth, winheight, curpos); if(trackingmouse) {dx = curpos[0] - lastpos[0]; dy = curpos[1] - lastpos[1]; dz = curpos[2] - lastpos[2]; if (dx dy dz) { angle = 90.0F * sqrt(dx*dx + dy*dy + dz*dz); axis[0] = lastpos[1]*curpos[2] - lastpos[2]*curpos[1]; axis[1] = lastpos[2]*curpos[0] - lastpos[0]*curpos[2]; axis[2] = lastpos[0]*curpos[1] - lastpos[1]*curpos[0]; lastpos[0] = curpos[0]; lastpos[1] = curpos[1]; lastpos[2] = curpos[2]; }} glutpostredisplay();} 29

4.8 虚拟跟踪球 trackball_ptov(int x, int y, int width, int height, float v[3]) { float d, a; /* project x,y onto a hemi-sphere centered within width, height */ v[0] = (2.0F*x - width) / width; v[1] = (height - 2.0F*y) / height; d = (float) sqrt(v[0]*v[0] + v[1]*v[1]); v[2] = (float) cos((m_pi/2.0f) * ((d < 1.0F)? d : 1.0F)); a = 1.0F / (float) sqrt(v[0]*v[0] + v[1]*v[1] + v[2]*v[2]); v[0] *= a; v[1] *= a; v[2] *= a; } 30

第四章几何对象和变换 (3)( 4.5 OpenGL 中的标架 4.6 建模一个彩色立方体 4.7 OpenGL 中几何变换 4.8 虚拟跟踪球 31