實(shí)驗(yàn)三 觀察三維物體_第1頁(yè)
實(shí)驗(yàn)三 觀察三維物體_第2頁(yè)
實(shí)驗(yàn)三 觀察三維物體_第3頁(yè)
實(shí)驗(yàn)三 觀察三維物體_第4頁(yè)
實(shí)驗(yàn)三 觀察三維物體_第5頁(yè)
已閱讀5頁(yè),還剩21頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、.實(shí)驗(yàn)三 觀察三維物體姓名 葉傳軍 學(xué)號(hào) E11414103 得分 一.實(shí)驗(yàn)題目1. 閱讀arraycube.c,掌握彩色立方體的建模方法,為程序加注釋。2. 修改arraycube.c,實(shí)現(xiàn)交互式地移動(dòng)照相機(jī)來(lái)觀察已經(jīng)建模好的彩色立方體。即用鼠標(biāo)或鍵盤(pán)來(lái)改變gluLookAt(eyex, eyey, eyez, atx, aty, atz, upx, upy, upz)函數(shù)的9個(gè)參數(shù),以此來(lái)觀察立方體。要求:(1)交互時(shí)采用的鼠標(biāo)和鍵盤(pán)按鍵自定。(2)分別在正投影和透視投影下實(shí)現(xiàn)題目中的功能。(3)可增加菜單功能,將正投影和透視投影下的觀察功能融合到一個(gè)程序中??蓞⒖冀换ナ浇坛蘌roject

2、ion.c的功能。3. 在arraycube.c的基礎(chǔ)上編寫(xiě)一個(gè)交互式程序,實(shí)現(xiàn)立方體的旋轉(zhuǎn)。具體要求如下:(1)立方體的旋轉(zhuǎn)方式由鼠標(biāo)和鍵盤(pán)按鍵來(lái)控制:按下鼠標(biāo)左鍵,立方體繞x軸連續(xù)旋轉(zhuǎn);按下鼠標(biāo)左鍵+ctrl鍵,立方體繞y軸連續(xù)旋轉(zhuǎn);按下鼠標(biāo)右鍵,立方體繞z軸連續(xù)旋轉(zhuǎn)。(注意:旋轉(zhuǎn)的不動(dòng)點(diǎn)在原點(diǎn),正好是立方體的中心。)(2) 如果旋轉(zhuǎn)的不動(dòng)點(diǎn)不在原點(diǎn),而改為點(diǎn)P(1,1,1),如何實(shí)現(xiàn)立方體繞3個(gè)坐標(biāo)軸軸的旋轉(zhuǎn)?(3)如果要求每按下一次鼠標(biāo)按鍵或鍵盤(pán)按鍵,立方體旋轉(zhuǎn)的角度增加5度,應(yīng)如何修改程序?4. 自學(xué)教材4.2.7節(jié)。編寫(xiě)一個(gè)交互式程序,使其可以通過(guò)鼠標(biāo)(或鍵盤(pán))和菜單實(shí)現(xiàn)一些glu

3、和glut對(duì)象的旋轉(zhuǎn),平移和比例縮放。(加自己的創(chuàng)意)二.設(shè)計(jì)思想本次試驗(yàn)主要是用戶交互與三維物體觀察的結(jié)合,主要用到的函數(shù)有g(shù)luPerspective(fovy, aspect, near, far);glOrtho(left, right, bottom, top, near, far);gluLookAt(eyex, eyey, eyez, atx, aty, atz, upx, upy, upz);通過(guò)這些函數(shù)的調(diào)用可以分別在正投影和透視投影下從不同的角度來(lái)觀察三維物體。三.程序清單1. #includestdafx.h#include #include GLdouble verti

4、ces83= -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;GLdouble colors83=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;/定義頂點(diǎn)和顏色的全局?jǐn)?shù)組void polygon(int a, int b, int c , int d)/根據(jù)索引列

5、表繪制多邊形/* draw a polygon via list of vertices */ glBegin(GL_QUADS);glColor3dv(colorsa);glVertex3dv(verticesa);glColor3dv(colorsb);glVertex3dv(verticesb);glColor3dv(colorsc);glVertex3dv(verticesc);glColor3dv(colorsd);glVertex3dv(verticesd);glEnd();void colorcube()/* map vertices to faces */利用表面繪制立方體po

6、lygon(0,3,2,1);polygon(2,3,7,6);polygon(0,4,7,3);polygon(1,2,6,5);polygon(4,5,6,7);polygon(0,1,5,4);void display()/* display callback, clear frame buffer and z buffer,/ and draw, swap buffers */顯示回調(diào)函數(shù)glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_MODELVIEW);glLoadIdentity();gluL

7、ookAt(1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);colorcube();glutSwapBuffers();void myReshape(int w, int h)/設(shè)置投影方式 glViewport(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); e

8、lse glOrtho(-2.0 * (GLfloat) w / (GLfloat) h, 2.0 * (GLfloat) w / (GLfloat) h, -2.0, 2.0, -10.0, 10.0); glMatrixMode(GL_MODELVIEW);void main(int argc, char *argv) glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);/設(shè)置窗口的顯示模式 glutInitWindowSize(500, 500);/指定窗口大小 glutCreat

9、eWindow(E11414103葉傳軍);/創(chuàng)建一個(gè)名為E11414103葉傳軍的窗口 glClearColor(0.0,0.0,0.0,0.0);/指定窗口的背景色為黑色/glShadeModel(GL_SMOOTH);glShadeModel(GL_FLAT); glutReshapeFunc(myReshape); glutDisplayFunc(display);/設(shè)置當(dāng)前窗口的顯示回調(diào)函數(shù) /glEnable(GL_DEPTH_TEST); /* Enable hidden-surface-removal */ glutMainLoop();/啟動(dòng)主GLUT事件處理循環(huán)2.(1)#

10、includestdafx.h#include #include GLdouble vertices83= -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;GLdouble colors83=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;/定義頂點(diǎn)和顏色的全局?jǐn)?shù)組in

11、t x1=1,y1=1,z1=1,x2=0,y2=0,z2=0,x3=0,y3=1,z3=0;void polygon(int a, int b, int c , int d)/根據(jù)索引列表繪制多邊形/* draw a polygon via list of vertices */ glBegin(GL_QUADS);glColor3dv(colorsa);glVertex3dv(verticesa);glColor3dv(colorsb);glVertex3dv(verticesb);glColor3dv(colorsc);glVertex3dv(verticesc);glColor3dv(

12、colorsd);glVertex3dv(verticesd);glEnd();void colorcube()/利用表面繪制立方體/* map vertices to faces */polygon(0,3,2,1);polygon(2,3,7,6);polygon(0,4,7,3);polygon(1,2,6,5);polygon(4,5,6,7);polygon(0,1,5,4);void display()/顯示回調(diào)函數(shù)/* display callback, clear frame buffer and z buffer,/ and draw, swap buffers */glCl

13、ear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_MODELVIEW);glLoadIdentity();gluLookAt(x1, y1, z1, x2, y2, z2, x3, y3, z3);colorcube();glutSwapBuffers();void myReshape(int w, int h)/設(shè)置投影方式正投影 glViewport(0, 0, w, h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); if (w = h) glOrtho(-2.

14、0, 2.0, -2.0 * (GLfloat) 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);void keyboard(unsigned char key,int x,int y)if(key=q) x1+;glutPostRedisplay();e

15、lse if(key=Q) x1-;glutPostRedisplay();else if(key=w) y1+;glutPostRedisplay();else if(key=W) y1-;glutPostRedisplay();else if(key=e) z1+;glutPostRedisplay();else if(key=E) z1-;glutPostRedisplay();else if(key=a) x2+;glutPostRedisplay();else if(key=A) x2-;glutPostRedisplay();else if(key=s) y2+;glutPostR

16、edisplay();else if(key=S) y2-;glutPostRedisplay();else if(key=d) z2+;glutPostRedisplay();else if(key=D) z2-;glutPostRedisplay();else if(key=z) x3+;glutPostRedisplay();else if(key=Z) z3-;glutPostRedisplay();else if(key=x) y3+;glutPostRedisplay();else if(key=X) y3-;glutPostRedisplay();else if(key=c) z

17、3+;glutPostRedisplay();else if(key=C) z3-;glutPostRedisplay();void main(int argc, char *argv) glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB|GLUT_DEPTH);/設(shè)置窗口的顯示模式 glutInitWindowSize(500, 500);/指定窗口大小 glutCreateWindow(E11414103葉傳軍);/創(chuàng)建一個(gè)名為E11414103葉傳軍的窗口glClearColor(0.0,0.0,0.0,0.0)

18、;/指定窗口的背景色為黑色/glShadeModel(GL_SMOOTH);glShadeModel(GL_FLAT); glutReshapeFunc(myReshape); glutDisplayFunc(display);/設(shè)置當(dāng)前窗口的顯示回調(diào)函數(shù)glutKeyboardFunc(keyboard); /glEnable(GL_DEPTH_TEST); /* Enable hidden-surface-removal */ glutMainLoop();/啟動(dòng)主GLUT事件處理循環(huán) (2)#includestdafx.h#include #include GLdouble vertic

19、es83= -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;GLdouble colors83=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;/定義頂點(diǎn)和顏色的全局?jǐn)?shù)組int x1=1,y1=1,z1=1,x2=0,y2=0,z2=0,x3=0,y3=1,z3=0;v

20、oid polygon(int a, int b, int c , int d)/根據(jù)索引列表繪制多邊形/* draw a polygon via list of vertices */ glBegin(GL_QUADS);glColor3dv(colorsa);glVertex3dv(verticesa);glColor3dv(colorsb);glVertex3dv(verticesb);glColor3dv(colorsc);glVertex3dv(verticesc);glColor3dv(colorsd);glVertex3dv(verticesd);glEnd();void col

21、orcube()/利用表面繪制立方體/* map vertices to faces */polygon(0,3,2,1);polygon(2,3,7,6);polygon(0,4,7,3);polygon(1,2,6,5);polygon(4,5,6,7);polygon(0,1,5,4);void display()/顯示回調(diào)函數(shù)/* display callback, clear frame buffer and z buffer,/ and draw, swap buffers */glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

22、glMatrixMode(GL_MODELVIEW);glLoadIdentity();gluLookAt(x1, y1, z1, x2, y2, z2, x3, y3, z3);colorcube();glutSwapBuffers();void myReshape(int w, int h)/設(shè)置投影方式透視投影 glViewport(0, 0, w, h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); if (w = h) glFrustum(-2.0, 2.0, -2.0 * (GLfloat) h / (GLfloat) w, 2.0

23、 * (GLfloat) h / (GLfloat) w, -10.0, 10.0); else glFrustum(-2.0 * (GLfloat) w / (GLfloat) h, 2.0 * (GLfloat) w / (GLfloat) h, -2.0, 2.0, -10.0, 10.0); glMatrixMode(GL_MODELVIEW);void keyboard(unsigned char key,int x,int y)if(key=q) x1+;glutPostRedisplay();else if(key=Q) x1-;glutPostRedisplay();else

24、if(key=w) y1+;glutPostRedisplay();else if(key=W) y1-;glutPostRedisplay();else if(key=e) z1+;glutPostRedisplay();else if(key=E) z1-;glutPostRedisplay();else if(key=a) x2+;glutPostRedisplay();else if(key=A) x2-;glutPostRedisplay();else if(key=s) y2+;glutPostRedisplay();else if(key=S) y2-;glutPostRedisplay();else if(key=d) z2+;glutPostRe

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論