版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
1、虛擬現(xiàn)實(shí)與系統(tǒng)統(tǒng)仿真實(shí)驗(yàn)指導(dǎo)書20132實(shí)驗(yàn)一 基于MMFC的基本本OpenGGL應(yīng)用程序序生成一:實(shí)驗(yàn)?zāi)康?. 熟悉VCC+20005集成開發(fā)發(fā)環(huán)境;2. 熟悉基本本MFC應(yīng)用用程序的生成成;3. 掌握基于于MFC的基基本OpennGL應(yīng)用程程序生成。二:實(shí)驗(yàn)內(nèi)容1. 建立基于于MFC的基基本OpennGL應(yīng)用程程序;2. 配置應(yīng)用用程序,添加加OpenGGL鏈接庫文文件;3. 建立OppenGL的的基本環(huán)境。三:實(shí)驗(yàn)背景知知識(shí)OpenGL是是一種圖形顯顯示軟件工具具包,它為圖圖形硬件提供供軟件接口。OOpenGLL為計(jì)算機(jī)動(dòng)動(dòng)畫提供由圖圖形生成圖像像幀的工具。MFC提供的圖形用戶界面程序設(shè)
2、計(jì)技術(shù)可以編寫人機(jī)交互程序,OpenGL技術(shù)可以進(jìn)行各種圖形繪制。四:實(shí)驗(yàn)步驟文件-新建-項(xiàng)目 選擇MFCC應(yīng)用程序 輸入名稱OOpenGLLPlat右擊項(xiàng)目名,選選擇屬性,再再選擇鏈接器器中的輸入選選項(xiàng),附加依依賴項(xiàng):oppengl332.libb; glu332.libb ;glauxx.lib3選擇類視圖圖模式,右擊擊View,再添加變量和頭文件件或直接在Vieew頭文件中中添加變量:protectted:HGLRC m_hRCC;添加包含OpeenGL頭文文件的語句:在COpenGGLPlattView.cpp中添加代碼#includde #includde #includde 4右擊
3、屬性 消息按鈕鈕 選擇WWM_CREEATE 添添加在int COOpenGLLPlatVView:OnCreeate(LLPCREAATESTRRUCT llpCreaateStrruct)函函數(shù)中添加代代碼/添加新的代代碼開始CClienttDC dcc(thiss); PIXEELFORMMATDESSCRIPTTOR pffd; memsset(&ppfd,0,sizeoof(PIXXELFORRMATDEESCRIPPTOR); pfd.nSizee=sizeeof(PIIXELFOORMATDDESCRIIPTOR); pfd.nVerssion=11; pfd.dwFlaags=
4、PFFD_DRAAW_TO_WINDOOW| PFD_SSUPPORRT_OPEENGL| PPFD_DOOUBLEBBUFFERR; pfd.iPixeelTypee=PFD_TYPE_RGBA; pfd.cColoorBitss=24; pfd.cDeptthBitss=32; int pixellFormaat=ChooosePiixelFoormat(dc.m_hDC,&pfd); SetPPixelFFormatt(dc.mm_hDC,pixellFormaat,&pffd); m_hRRC=wgllCreatteConttext(ddc.m_hhDC);returnn 0;右擊屬性
5、 消消息按鈕 選擇WM_DESTRROY 添加加void COOpenGLLPlatVView:OnDesstroy()函數(shù)中添添加代碼 /添加加新的代碼開開始wglMakeeCurreent(NULL,NULL);wglDelleteCoontextt(m_hRCC);m_hRC=NULL;右擊屬性 消消息按鈕 選擇WM_SIZE 添加void COOpenGLLPlatVView:OnSizze(UINT nTypee, int cx, int cy) 函數(shù)中添加加代碼 /添加加新的代碼開開始CClienttDC dc(this);wglMakkeCurrrent(dc.m_hDCC,m_
6、hRCC); glMMatrixxMode(GL_PRROJECTTION);glLoaddIdenttity();doublee d=10;doublee n=100;glOrthho(-cx/n,cx/n,-cy/n,cy/n,-d,d);glMatrrixModde(GL_MOODELVIIEW);glViewwport(0,0,ccx,cy);wglMakkeCurrrent(NULL,NULL);5.在OpennGLPlaatVieww.cpp中中OnDraaw函數(shù)中添添加以下代碼碼:void CMMy1Vieew:OnDrraw(CDC* pDC) / 把 ”/*pDCC*/” 改
7、成 ppDCCOpenGGLPlattDoc* pDocc = GettDocumment();ASSERTT_VALIID(pDoc);if (!ppDoc)returrn;/ TODDO: 在此此處為本機(jī)數(shù)數(shù)據(jù)添加繪制制代碼wglMakkeCurrrent(pDC-m_hDDC,m_hRCC);glCleaarColoor(1.0f,1.0f,1.0f,1.0f); glCClearDDepth(1.0);glCleaar(GL_COOLOR_BBUFFERR_BIT|GL_DEEPTH_BBUFFERR_BIT);glEnabble(GL_COOLOR_MMATERIIAL);glEna
8、bble(GL_LIIGHTINNG);glEnabble(GL_LIIGHT0); glEEnablee(GL_AUUTO_NOORMAL);glEnabble(GL_NOORMALIIZE);glEnabble(GL_DEEPTH_TTEST);glDeptthFuncc(GL_LEESS);glMatrrixModde(GL_MOODELVIIEW);glLoaddIdenttity();glColoor3f(1.0f,0.0f,0.0f);glRotaated(660.0,11.0,1.0,1.00); /茶壺auxWirreTeappot(3.0);SwapBufffers(pDC-
9、m_hDDC);wglMakkeCurrrent(NULL,NULL);五:實(shí)驗(yàn)結(jié)果 實(shí)驗(yàn)二OpennGL基本圖圖形元素和模模型變換一:實(shí)驗(yàn)?zāi)康?. 掌握二次次曲面的繪制制函數(shù)及其應(yīng)應(yīng)用方法。2. 掌握基本本實(shí)體模型的的繪制函數(shù)及及其應(yīng)用方法法。二:實(shí)驗(yàn)內(nèi)容1. 學(xué)習(xí)二次次曲面的繪制制函數(shù)及其應(yīng)應(yīng)用方法。2. 學(xué)習(xí)基本本實(shí)體模型的的繪制函數(shù)及及其應(yīng)用方法法。三:實(shí)驗(yàn)背景知知識(shí)OpenGL提提供了二次曲曲面和基本實(shí)實(shí)體模型的繪繪制函數(shù)及其其應(yīng)用方法。這這些二次曲面面和基本實(shí)體體模型在OppenGL內(nèi)內(nèi)部實(shí)現(xiàn)中實(shí)實(shí)際上也是將將它們離散分分割成為大量量的多邊形,然然后通過繪制制多邊形的方方法實(shí)現(xiàn)對這
10、這些二次曲面面和基本實(shí)體體模型的繪制制。四:實(shí)驗(yàn)程序 實(shí)驗(yàn)步驟144與上述實(shí)驗(yàn)驗(yàn)1相同5在OpenGGLPlattView.cpp中OOnDraww函數(shù)中添加加以下代碼:wglMakeeCurreent(pDC-m_hDDC,m_hRCC);glMatriixModee(GL_MOODELVIIEW); /二次次曲面glColorr3f(1.0f,0.0f,0.0f);GLUquaddric* qd=glluNewQQuadriic();/創(chuàng)建二次次曲面對象gluQuaddricDrrawStyyle(qdd,GLU_FILL);/設(shè)置二次次曲面對象繪繪制模式GLLU_LINNE;GLUU_S
11、ILHHOUETTTE;GLUU_POINNTglLoadIIdentiity();glRotatted(-1105.0,1.0,00.0,0.0);glTransslatedd(-6.00,0.0,-2.0);gluCyliinder(qd,2.0,1.00,4.0,30,4);/(圓臺(tái),下下底面半徑,上上底面半徑,圓圓臺(tái)高度,繞繞z軸分割瓣數(shù)數(shù),繞z軸方向?qū)訑?shù)數(shù))glLoadIIdentiity();glTransslatedd(-6.00,0.0,-2.0);gluDiskk(qd,11.0,2.0,30,4);/平面圓盤(,內(nèi)內(nèi)圓半徑,外外圓半徑,扇扇形瓣數(shù),環(huán)環(huán)的個(gè)數(shù))/.gluPa
12、rttialDiisk(qdd,1.0,2.0,110,4,00,75);/拱狀圖形形(,內(nèi)圓半半徑,外圓半半徑,扇形瓣瓣數(shù),環(huán)的個(gè)個(gè)數(shù),起始角角,圖形張開開的角度)/.gluSpheere(qdd,2.0,30,6);/球(,球球的半徑,分分割的瓣數(shù),分分割的層次)auxSoliidTetrrahedrron(4.0);/實(shí)體模型auuxWireeTeapoot();aauxSollidTeaapot();/auxWiireSphhere(33.0);aauxSollidSphhere(33.0);/auxWiireCubbe(4.00);auxxSoliddCube(4.0);/auxWi
13、ireBoxx(3.0,4.0,55.0);aauxSollidBoxx(3.0,4.0,55.0);/auxWiireTorrus(1.0,3.00);/圓圓環(huán)auxSSolidTTorus(1.0,33.0);/auxWiireCyllinderr(2.0,4.0);auxSoolidCyylindeer(2.00,4.0);/auxWiireIcoosaheddron(44.0);aauxSollidIcoosaheddron(44.0);/二十面體體 /auxWiireOcttahedrron(4.0);auuxSoliidOctaahedroon(4.00);/八八面體 /auxWi
14、ireTettraheddron(44.0);aauxSollidTettraheddron(44.0);/四面體 /auxWiireDoddecaheedron(4.0);auxSoolidDoodecahhedronn(4.0);/十二二面體 /auxWiireConne(2.00,4.0);auxSSolidCCone(22.0,4.0);/圓錐體 SwapBBufferrs(pDC-m_hDDC); /雙緩沖沖wglMakkeCurrrent(NULL,NULL); 實(shí)驗(yàn)三 光照與與材質(zhì)一:實(shí)驗(yàn)?zāi)康模?. 掌握利用用OpenGGL編寫繪制制具有真實(shí)感感效果的圖形形方法。2. 掌握添加加
15、光源和設(shè)置置顏色材料屬屬性的方法。二:實(shí)驗(yàn)內(nèi)容:1. 掌握添加加光源的實(shí)現(xiàn)現(xiàn)方法。2. 掌握設(shè)置置顏色和材料料屬性的方法法。三:實(shí)驗(yàn)要求通過本實(shí)驗(yàn),掌掌握添加光源源和設(shè)置顏色色材料屬性的的方法,利用用OpenGGL編寫繪制制具有真實(shí)感感效果的圖形形。四:實(shí)驗(yàn)程序?qū)嶒?yàn)步驟144與上述實(shí)驗(yàn)驗(yàn)1相同5在OpenGGLPlattView.cpp中OOnDraww函數(shù)中添加加以下代碼:wglMakeeCurreent(pDC-m_hDDC,m_hRCC);glClearrColorr(1.0f,1.0f,1.0f,1.0f);glClearrDepthh(1.0);glClearr(GL_COOLOR_
16、BBUFFERR_BIT|GL_DEEPTH_BBUFFERR_BIT);glEnablle(GL_COOLOR_MMATERIIAL);glEnablle(GL_LIIGHTINNG);glEnablle(GL_LIIGHT0);glEnablle(GL_AUUTO_NOORMAL);glEnablle(GL_NOORMALIIZE);glEnablle(GL_DEEPTH_TTEST);glDepthhFunc(GL_LEESS);/設(shè)置模型變變換矩陣glMatrrixModde(GL_MODELLVIEW);glLoaddIdenttity(); /設(shè)設(shè)置光源參數(shù)數(shù)GLfloaat li
17、gght_poositioon=1.0f,1.0f,1.0f,0.0f;GLfloaat ligght_ammbientt=00.2f,0.2f,0.2f,0.2f;GLfloaat ligght_diiffusee=00.5f,0.5f,0.2f,0.2f;GLfloaat ligght_sppeculaar=0.5f,0.5f,0.5f,0.2f;glLighhtfv(GGL_LIGGHT0,GGL_POSSITIONN,lighht_possitionn);glLighhtfv(GGL_LIGGHT0,GGL_AMBBIENT,lightt_ambiient);glLighhtfv(GG
18、L_LIGGHT0,GGL_DIFFFUSE,lightt_difffuse);glLighhtfv(GGL_LIGGHT0,GGL_SPEECULARR,lighht_speecularr);/設(shè)置材質(zhì)質(zhì)參數(shù)GLfloaat matteriall_ambiient=0.22f,0.2f,0.2f,0.2f;GLfloaat matteriall_difffuse=0.22f,0.8f,0.4f,0.8f;GLfloaat matteriall_speccular=0.2f,0.8f,0.4f,0.8f;GLfloaat matteriall_emisssion=0.2f,0.2f,0.2f,
19、1.0f;GLfloaat matteriall_shinness=10.0f; gllMaterrialfvv(GL_BBACK,GGL_AMBBIENT,materrial_aambiennt);/FRONTT_AND_BACKglMateerialffv(GL_BACK,GL_DIIFFUSEE,mateerial_diffuuse);glMateerialffv(GL_BACK,GL_SPPECULAAR,matteriall_speccular);glMateerialffv(GL_BACK,GL_EMMISSIOON,matteriall_emisssion);glMateeria
20、lffv(GL_BACK,GL_SHHININEESS,maateriaal_shiiness);glColoor3f(1.0f,0.0f,0.0f);/紅色glRotaated(660.0,11.0,1.0,1.00);auxSoliidTeappot(2.0);SwapBuufferss(pDC-m_hDDC); /雙緩沖沖wglMakkeCurrrent(NULL,NULL); 實(shí)驗(yàn)結(jié)果:實(shí)驗(yàn)四 紋理映映射一:實(shí)驗(yàn)?zāi)康?. 掌握二維維紋理映射方方法。2. 掌握利用用OpenGGL編寫繪制制具有真實(shí)感感效果的圖形形方法。二:實(shí)驗(yàn)內(nèi)容掌握二維紋理映映射方法。三:實(shí)驗(yàn)要求通過本實(shí)驗(yàn),掌掌握掌握
21、二維維紋理映射方方法。四:實(shí)驗(yàn)程序?qū)嶒?yàn)步驟144與上述實(shí)驗(yàn)驗(yàn)1相同5在OpenGGLPlattView.cpp中OOnDraww函數(shù)中添加加以下代碼:wglMakeeCurreent(pDC-m_hDDC,m_hRCC);glCleaarColoor(1.0f,1.0f,1.0f,1.0f);glCleaar(GL_COOLOR_BBUFFERR_BIT|GL_DEEPTH_BBUFFERR_BIT);glEnabble(GL_COOLOR_MMATERIIAL);glEnabble(GL_LIIGHTINNG);glEnabble(GL_LIIGHT0); glEEnablee(GL_AUU
22、TO_NOORMAL);glEnabble(GL_NOORMALIIZE);glEnabble(GL_DEEPTH_TTEST);glDeptthFuncc(GL_LEESS); glMMatrixxMode(GL_MOODELVIIEW);glLoaddIdenttity(); /設(shè)設(shè)置光源參數(shù)數(shù)GLfloaat lightt_posiition=1.0f,1.0f,1.0f,0.0f;GLfloaat lightt_ambiient=0.22f,0.2f,0.2f,0.2f;GLfloaat lightt_difffuse=0.55f,0.5f,0.2f,0.2f;GLfloaat lig
23、htt_speccular=0.5f,0.5f,0.5f,0.2f;glLighhtfv(GL_LIIGHT0,GL_POOSITIOON,lightt_posiition);glLighhtfv(GL_LIIGHT0,GL_AMMBIENTT,lightt_ambiient);glLighhtfv(GL_LIIGHT0,GL_DIIFFUSEE,lightt_difffuse);glLighhtfv(GL_LIIGHT0,GL_SPPECULAAR,lightt_speccular);/設(shè)置材質(zhì)質(zhì)參數(shù)GLfloaat materrial_aambiennt=0.2f,0.2f,0.2f,0.
24、2f;GLfloaat materrial_ddiffusse=0.2f,0.8f,0.4f,0.8f;GLfloaat materrial_sspecullar=0.2ff,0.8f,0.4f,0.8f;GLfloaat materrial_eemissiion=0.2ff,0.2f,0.2f,1.0f;GLfloaat materrial_sshinesss=10.0ff; gllMaterrialfvv(GL_BAACK,GL_AMMBIENTT,materrial_aambiennt);/FRRONT_AAND_BAACKglMateerialffv(GL_BAACK,GL_DIIFF
25、USEE,materrial_ddiffusse);glMateerialffv(GL_BAACK,GL_SPPECULAAR,materrial_sspecullar);glMateerialffv(GL_BAACK,GL_EMMISSIOON,materrial_eemissiion);glMateerialffv(GL_BAACK,GL_SHHININEESS,materrial_sshinesss);glRotaated(880.0,11.0,1.0,1.00);AUX_RGGBImaggeRec *pictture=auxDIIBImaggeLoadd(_T(C:tsIcoon.bm
26、pp);/(此處圖片路路徑為C盤根根目錄下)if(piccture!=NULLL)glEnaable(GL_TEEXTUREE_2D);glPixxelStoorei(GL_UNNPACK_ALIGNNMENT,1);glTexxImagee2D(GL_TEEXTUREE_2D,/二維紋理理 0,/紋理層次次 3,/顏色分量量個(gè)數(shù) pictuure-sizeeX,/紋理寬度度 pictuure-sizeeY,/紋理高度度 0,/紋理邊框框?qū)挾龋ɑ颍?GL_RGGB,/像素?cái)?shù)據(jù)據(jù)格式 GL_UNNSIGNEED_BYTTE,/像素?cái)?shù)據(jù)據(jù)類型 pictuure-dataa);/存儲(chǔ)圖象象數(shù)據(jù)glT
27、exxParammeterii(GL_TEEXTUREE_2D,GL_TEEXTUREE_WRAPP_S,GL_REEPEAT);/循環(huán)glTexxParammeterii(GL_TEEXTUREE_2D,GL_TEEXTUREE_WRAPP_T,GL_REEPEAT);glTexxParammeterii(GL_TEEXTUREE_2D,GL_TEEXTUREE_MAG_FILTEER,GL_NEEARESTT);glTexxParammeterii(GL_TEEXTUREE_2D,GL_TEEXTUREE_MIN_FILTEER,GL_NEEARESTT);glTexxEnvi(GL_TE
28、EXTUREE_ENV,GL_TEEXTUREE_ENV_MODE,GL_MOODULATTE);/GLL_DECAAL,GL_glBegiin(GL_QUUADS);glColoor3f(0.00,1.0,0.0);glTexCCoord22d(-2.0,-2.0);gllVerteex3d(-2.5,-2.5,33);glTexCCoord22d(-2.0,2.00);glVVertexx3d(2.5,-2.5,3);glTexCCoord22d(2.00,2.0);glVeertex33d(2.55,2.5,3);glTexCCoord22d(2.00,-2.00);glVVertexx
29、3d(-22.5,2.5,3);glColoor3f(1.00,1.0,0.0);glTexCCoord22d(0.00,0.0);glVeertex33d(-2.5,2.55,0);glTexCCoord22d(0.00,1.0);glVeertex33d(2.55,2.5,0);glTexCCoord22d(1.00,1.0);glVeertex33d(2.55,2.5,3);glTexCCoord22d(1.00,0.0);glVeertex33d(-2.5,2.55,3);glColoor3f(1.00,0.0,1.0);glTexCCoord22d(0.44,0.4);glVeert
30、ex33d(-2.5,-2.5,0);glTexCCoord22d(0.44,0.6);glVeertex33d(-2.5,-2.5,3);glTexCCoord22d(0.66,0.6);glVeertex33d(-2.5,2.55,3);glTexCCoord22d(0.44,0.4);glVeertex33d(-2.5,2.55,0);glEnd();SwapBuufferss(pDC-m_hDDC); /雙緩沖沖wglMakkeCurrrent(NULL,NULL); 實(shí)驗(yàn)五 基于OOpenGLL的動(dòng)畫編程程一:實(shí)驗(yàn)?zāi)康?. 掌握VCC中的文檔視視圖架構(gòu)。2. 掌握利用用OpenGGL
31、編寫動(dòng)畫畫效果的方法法。二:實(shí)驗(yàn)內(nèi)容掌握VC中的文文檔視圖架構(gòu)構(gòu)及動(dòng)畫程序序編寫。三:實(shí)驗(yàn)要求通過本實(shí)驗(yàn),掌掌握利用OppenGL編編寫動(dòng)畫效果果的方法。四:實(shí)驗(yàn)程序?qū)嶒?yàn)步驟144與上述實(shí)驗(yàn)驗(yàn)1相同5.添加Staar類在Star.hh中添加以下下代碼#pragmaa once#includde #includde #includde class SStarpublic: Star(void); innt m_nn; innt m_ssign;/變形符:增加,-11:減少 doouble m_raddiusCeenter; doouble m_raddiusMiiddle; doouble m_
32、raddiusCoorner; GLLfloatt m_reedCentter,m_greennCenteer,m_bblueCeenter; GLLfloatt m_reedMidddle,m_greennMiddlle,m_bblueMiiddle; GLLfloatt m_reedCornner,m_greennCorneer,m_bblueCoorner; GLLdoublle m_aangle;/旋轉(zhuǎn)角度度 GLLdoublle m_ppoint2633;/每個(gè)頂點(diǎn)點(diǎn)坐標(biāo)值 GLLfloatt m_coolor2263;/每個(gè)頂點(diǎn)點(diǎn)顏色值 vooid mbb_adjuustGLffl
33、oat(GLflooat& ff,GLflloat mmin,GLLfloatt max); vooid mbb_calcculateePointt(voidd);/計(jì)算頂點(diǎn)點(diǎn)坐標(biāo)值 vooid mbb_draww(voidd);/繪制圖形形 vooid mbb_nexttFramee(voidd);/計(jì)算下一一幀public: Staar(voiid); 在Star.ccpp中添加加以下代碼: #incluude SStdAfxx.h#includde Sttar.h/ 構(gòu)造函數(shù)數(shù):初始化各各個(gè)成員變量量Star:SStar(vvoid) m_rradiussCenteer=2.00; /
34、中心球球半徑 m_rradiussMiddlle=2.8828; / 中間球球半徑,這里里2sqrt(2)2.8288 m_rradiussCorneer=3.4464; / 角上球球半徑,這里里2sqrt(3)3.4644 m_rredCennter=11.0f; / 中心球球點(diǎn)顏色 m_ggreenCCenterr=0.0ff; m_bblueCeenter=1.0f; m_rredMidddle=00.0f; / 中間球球點(diǎn)顏色 m_ggreenMMiddlee=1.0ff; m_bblueMiiddle=0.0f; m_rredCorrner=00.0f; / 角上球球點(diǎn)顏色 m_gg
35、reenCCornerr=0.0ff; m_bblueCoorner=1.0f; m_aangle=45.0; / 旋轉(zhuǎn)角角度 mb_calcuulatePPoint( ); m_nn=0; / 變形計(jì)數(shù)器器 m_ssign=11; / 變形符號(hào): 1: 增增加; -11: 減小 / 構(gòu)造造函數(shù)Staar結(jié)束/ 析構(gòu)函數(shù)數(shù)Star:Star(void) / 析構(gòu)構(gòu)函數(shù)Sttar結(jié)束/ 值調(diào)整函函數(shù):強(qiáng)制使使得參數(shù)f的的值位于區(qū)間間min, max內(nèi)void Sttar:mmb_adjjustGLLfloatt(GLflloat& f, GLLfloatt min, GLflloat mmax)
36、 if (fmaax) f=maax; / 函數(shù)數(shù)mb_addjustGGLfloaat結(jié)束/ 計(jì)算頂點(diǎn)點(diǎn)的坐標(biāo)值和和顏色值void Sttar:mmb_callculattePoinnt(voiid) intt i, jj; intt id1 =00, 2, 6, 8, 1, 33, 5, 7; intt id2 =99, 11, 14, 16, 110, 122, 13, 15; intt signn1 =-1, 1, -1, 11, 0, -1, 1, 0; intt signn2 = 1, 1, -1, -11, 1, 0, 0, -11; forr (i=00, j=44; i44;
37、 i+, j+) / 下面00.577是是“sqrt(3)/3”的近似值 m_poointiid1i0=0.5777*m_raadiusCCornerr*signn1i; m_poointiid1i1=0.5777*m_raadiusCCornerr*signn2i; m_poointiid1i2=0.5777*m_raadiusCCornerr; m_cooloriid1i0=m_reddCorneer; m_cooloriid1i1=m_greeenCorrner; m_cooloriid1i2=m_bluueCornner; / 下下面0.7007是“sqrt(2)/2”的近似值 m_p
38、oointiid1j0=0.7077*m_raadiusMMiddlee*signn1j; m_poointiid1j1=0.7077*m_raadiusMMiddlee*signn2j; m_poointiid1j2=0.7077*m_raadiusMMiddlee; m_cooloriid1j0=m_reddMiddlle; m_cooloriid1j1=m_greeenMidddle; m_cooloriid1j2=m_bluueMidddle; / forr循環(huán)結(jié)束 m_ppoint40=0.0; m_ppoint41=0.0; m_ppoint42=m_raadiusCCenterr
39、; m_ccolor40=m_reedCentter; m_ccolor41=m_grreenCeenter; m_ccolor42=m_bllueCennter; forr (i=99; i117; i+) m_poointii2=0.0; forr (i=00, j=44; i44; i+, j+) / 下面00.707是是“sqrt(2)/2”的近似值 m_poointiid2i0=0.7077*m_raadiusMMiddlee*signn1i; m_poointiid2i1=0.7077*m_raadiusMMiddlee*signn2i; m_cooloriid2i0=m_redd
40、Middlle; m_cooloriid2i1=m_greeenMidddle; m_cooloriid2i2=m_bluueMidddle; m_poointiid2j0=m_raddiusCeenter*sign11j; m_poointiid2j1=m_raddiusCeenter*sign22j; m_cooloriid2j0=m_reddCenteer; m_cooloriid2j1=m_greeenCennter; m_cooloriid2j2=m_bluueCentter; / forr循環(huán)結(jié)束 forr (i=00, j=117; i9; i+, j+) m_poointjj0
41、=m_poiinti0; m_poointjj1=m_poiinti1; m_poointjj2=-m_poointii2; m_coolorjj0=m_collori0; m_coolorjj1=m_collori1; m_coolorjj2=m_collori2; / forr循環(huán)結(jié)束 / 函數(shù)數(shù)mb_caalculaatePoiint結(jié)束/ 繪制圖形形void Sttar:mmb_draaw(voiid) intt i, jj, k, m; intt id338= 0, 0, 1, 44, 3, 6, 4, 8, / 上表表面三角形映映射關(guān)系 3, 4, 4, 55, 6, 7, 7,
42、5, 4, 1, 2, 22, 4, 4, 8, 4 ; intt facee499= 0, 1, 2, 9, 100, 11, 17, 18, 119, / 側(cè)面與與表面的頂點(diǎn)點(diǎn)映射關(guān)系 0, 3, 6, 9, 122, 14, 17, 20, 223, 6, 7, 8, 114, 155, 16, 23, 24, 225, 8, 5, 2, 116, 133, 11, 25, 22, 119 ; glBBegin(GL_TRRIANGLLES); for (i=0; i8; i+) / 上上表面 for (j=0; j3; j+) m=idji; glCollor3f (m_colorrm
43、00, m_colorrm11, m_colorrm22); glVerrtex3dd(m_poointmm0, m_poointmm1, m_poointmm2); / for循循環(huán)結(jié)束 for (k=0; k4; k+) / 四四個(gè)側(cè)面 for (i=0; i8; i+) for (j=0; j3; j+) m=faccekidji; glCollor3f (m_colorrm00, m_colorrm11, m_colorrm22); glVerrtex3dd(m_poointmm0, m_poointmm1, m_poointmm2); / for循循環(huán)結(jié)束 for (i=0; i8;
44、 i+) / 下下表面 for (j=0; jnMax) m_siign=-11; if (m_n3360) m_anngle=00.0; mb_calcuulatePPoint( ); / 函數(shù)數(shù)mb_neextFraame結(jié)束6在COpeenGLPllatVieew類開頭添添加#includde Starr.h在view中添添加一個(gè)WMM_TIMEER函數(shù) voidd COpeenGLPllatVieew:OnnTimerr(UINTT_PTR nIDEvvent)/ TODDO: 在此此添加消息處處理程序代碼碼和/或調(diào)用默認(rèn)認(rèn)值 COppenGLPPlatDooc* pDDoc=Geet
45、Docuument(); ASSSERT_VVALID(pDoc); if(!pDocc) retturn; pDooc-m_star.mb_neextFraame(); Invvalidaate();CView:OnTiimer(nnIDEveent);在COpenGGLPlattDoc類中中添加m_sstar變量量:public:Star m_sstar;7.在vieww中的OnCCreatee函數(shù)中添加加時(shí)間觸發(fā):int COppenGLPPlatViiew:OnCrreate(LPCREEATESTTRUCT lpCreeateSttruct)if (CVView:OnCreeate(
46、lpCreeateSttruct) = -1)returrn -1;/ TODDO: 在在此添加您專專用的創(chuàng)建代代碼. SeetTimeer(1,333,NULLL);returnn 0;8.在vieww中的OnDDestrooy函數(shù)中添添加代碼:KillTimmer(1);9.在OpennGLPlaatVieww.cpp中中OnDraaw函數(shù)中添添加以下代碼碼void CMMy4Vieew:OnDrraw(CDC* pDC)CMy4Dooc* pDocc = GettDocumment();ASSERTT_VALIID(pDoc);if (!pDoc)returrn;wglMakkeCurr
47、rent(pDC-m_hDDC,m_hRCC);glCleaarColoor(1.0f,1.0f,1.0f,1.0f);glCleaar(GL_COOLOR_BBUFFERR_BIT|GL_DEEPTH_BBUFFERR_BIT);glEnabble(GL_COOLOR_MMATERIIAL);glEnabble(GL_LIIGHTINNG);glEnabble(GL_LIIGHT0); glEEnablee(GL_AUUTO_NOORMAL);glEnabble(GL_NOORMALIIZE);glEnabble(GL_DEEPTH_TTEST);glDeptthFuncc(GL_LEESS
48、); glMMatrixxMode(GL_MOODELVIIEW); glLLoadIddentitty(); /設(shè)設(shè)置光源參數(shù)數(shù)GLfloaat lightt_posiition=1.0f,1.0f,1.0f,0.0f;GLfloaat lightt_ambiient=0.22f,0.2f,0.2f,0.2f;GLfloaat lightt_difffuse=0.55f,0.5f,0.2f,0.2f;GLfloaat lightt_speccular=0.5f,0.5f,0.5f,0.2f;glLighhtfv(GL_LIIGHT0,GL_POOSITIOON,lightt_posiition);glLighhtfv(GL_LIIGHT0,GL
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 愛情故事記錄約定
- 產(chǎn)品質(zhì)量保證書讓消費(fèi)者信任你的產(chǎn)品
- 道路施工期間進(jìn)度計(jì)劃
- 窗簾軟裝購買合同
- 石材護(hù)理保養(yǎng)合同
- 個(gè)人借款合同范本電子版
- 房屋買賣合同標(biāo)準(zhǔn)范本樣式
- 服務(wù)器采購合同
- 預(yù)購合同的合同價(jià)款支付規(guī)定
- 自然人之間房屋買賣合同的風(fēng)險(xiǎn)評(píng)估
- 列車車門故障應(yīng)急處理方案
- 2024年度-Pitstop教程去水印
- 2024年02月天津市口腔醫(yī)院派遣制人員招考聘用40人筆試歷年(2016-2023年)真題薈萃帶答案解析
- 聲明書:個(gè)人婚姻狀況聲明
- 幼兒園年檢整改專項(xiàng)方案
- 新管徑流速流量對照表
- 20以內(nèi)退位減法口算練習(xí)題100題30套(共3000題)
- 咯血病人做介入手術(shù)后的護(hù)理
- 境外投資環(huán)境分析報(bào)告
- 便攜式氣體檢測儀使用方法課件
- 《壓力平衡式旋塞閥》課件
評(píng)論
0/150
提交評(píng)論