版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
虛擬現(xiàn)實(shí)與系統(tǒng)仿真實(shí)驗(yàn)指導(dǎo)書(shū)2013.2實(shí)驗(yàn)一基于MFC的基本OpenGL應(yīng)用程序生成謝謝閱讀一:實(shí)驗(yàn)?zāi)康?.熟悉VC++2005集成開(kāi)發(fā)環(huán)境;2.熟悉基本MFC應(yīng)用程序的生成;3.掌握基于MFC的基本OpenGL應(yīng)用程序生成。二:實(shí)驗(yàn)內(nèi)容1.建立基于MFC的基本OpenGL應(yīng)用程序;2.配置應(yīng)用程序,添加OpenGL鏈接庫(kù)文件;3.建立OpenGL的基本環(huán)境。三:實(shí)驗(yàn)背景知識(shí)OpenGLOpenGL為計(jì)算機(jī)動(dòng)畫(huà)感謝閱讀提供由圖形生成圖像幀的工具。MFC提供的圖形用戶界面程序設(shè)計(jì)技術(shù)可以編寫(xiě)人機(jī)交互程感謝閱讀序,OpenGL技術(shù)可以進(jìn)行各種圖形繪制。四:實(shí)驗(yàn)步驟1.文件->新建->項(xiàng)目選擇MFC應(yīng)用程序輸入名稱OpenGLPlat感謝閱讀2.右擊項(xiàng)目名,選擇屬性,再選擇鏈接器中的輸入選項(xiàng),附加依賴感謝閱讀項(xiàng):opengl32.lib;glu32.lib;glaux.lib感謝閱讀3.選擇類視圖模式,右擊View,再添加變量和頭文件精品文檔放心下載或直接在View頭文件中添加變量:protected:HGLRCm_hRC;添加包含OpenGL頭文件的語(yǔ)句:在COpenGLPlatView.cpp中添加代碼#include<gl/gl.h>#include<gl/glu.h>#include<gl/glaux.h>4.右擊屬性消息按鈕選擇WM_CREATE添加在intCOpenGLPlatView::OnCreate(LPCREATESTRUCTlpCreateStruct)函數(shù)中添加代碼謝謝閱讀//添加新的代碼開(kāi)始CClientDCdc(this);PIXELFORMATDESCRIPTORpfd;memset(&pfd,0,sizeof(PIXELFORMATDESCRIPTOR));感謝閱讀pfd.nSize=sizeof(PIXELFORMATDESCRIPTOR);謝謝閱讀pfd.nVersion=1;pfd.dwFlags=PFD_DRAW_TO_WINDOW|精品文檔放心下載PFD_SUPPORT_OPENGL|PFD_DOUBLEBUFFER;pfd.iPixelType=PFD_TYPE_RGBA;精品文檔放心下載pfd.cColorBits=24;pfd.cDepthBits=32;intpixelFormat=ChoosePixelFormat(dc.m_hDC,&pfd);感謝閱讀SetPixelFormat(dc.m_hDC,pixelFormat,&pfd);感謝閱讀m_hRC=wglCreateContext(dc.m_hDC);感謝閱讀return0;右擊屬性消息按鈕選擇WM_DESTROY添加voidCOpenGLPlatView::OnDestroy()函數(shù)中添加代碼謝謝閱讀//添加新的代碼開(kāi)始wglMakeCurrent(NULL,NULL);謝謝閱讀wglDeleteContext(m_hRC);m_hRC=NULL;右擊屬性消息按鈕選擇WM_SIZE添加voidCOpenGLPlatView::OnSize(UINTnType,intcx,intcy)函數(shù)中添加代碼謝謝閱讀//添加新的代碼開(kāi)始CClientDCdc(this);wglMakeCurrent(dc.m_hDC,m_hRC);精品文檔放心下載glMatrixMode(GL_PROJECTION);謝謝閱讀glLoadIdentity();doubled=10;doublen=100;glOrtho(-cx/n,cx/n,-cy/n,cy/n,-d,d);謝謝閱讀glMatrixMode(GL_MODELVIEW);精品文檔放心下載glViewport(0,0,cx,cy);wglMakeCurrent(NULL,NULL);謝謝閱讀5.在OpenGLPlatView.cpp中OnDraw函數(shù)中添加以下代碼:感謝閱讀voidCMy1View::OnDraw(CDC*pDC)//把”/*pDC*/”改成pDC感謝閱讀{COpenGLPlatDoc*pDoc=GetDocument();感謝閱讀ASSERT_VALID(pDoc);if(!pDoc)return;//TODO:在此處為本機(jī)數(shù)據(jù)添加繪制代碼wglMakeCurrent(pDC->m_hDC,m_hRC);謝謝閱讀glClearColor(1.0f,1.0f,1.0f,1.0f);謝謝閱讀glClearDepth(1.0);glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);謝謝閱讀glEnable(GL_COLOR_MATERIAL);感謝閱讀glEnable(GL_LIGHTING);glEnable(GL_LIGHT0);glEnable(GL_AUTO_NORMAL);glEnable(GL_NORMALIZE);glEnable(GL_DEPTH_TEST);glDepthFunc(GL_LESS);glMatrixMode(GL_MODELVIEW);感謝閱讀glLoadIdentity();glColor3f(1.0f,0.0f,0.0f);謝謝閱讀glRotated(60.0,1.0,1.0,1.0);//茶壺謝謝閱讀auxWireTeapot(3.0);SwapBuffers(pDC->m_hDC);wglMakeCurrent(NULL,NULL);精品文檔放心下載五:實(shí)驗(yàn)結(jié)果實(shí)驗(yàn)二OpenGL基本圖形元素和模型變換一:實(shí)驗(yàn)?zāi)康?.掌握二次曲面的繪制函數(shù)及其應(yīng)用方法。2.掌握基本實(shí)體模型的繪制函數(shù)及其應(yīng)用方法。二:實(shí)驗(yàn)內(nèi)容1.學(xué)習(xí)二次曲面的繪制函數(shù)及其應(yīng)用方法。2.學(xué)習(xí)基本實(shí)體模型的繪制函數(shù)及其應(yīng)用方法。三:實(shí)驗(yàn)背景知識(shí)OpenGL精品文檔放心下載實(shí)體模型在OpenGL精品文檔放心下載多邊形的方法實(shí)現(xiàn)對(duì)這些二次曲面和基本實(shí)體模型的繪制。感謝閱讀四:實(shí)驗(yàn)程序?qū)嶒?yàn)步驟1~4與上述實(shí)驗(yàn)1相同5在OpenGLPlatView.cpp中OnDraw函數(shù)中添加以下代碼:謝謝閱讀wglMakeCurrent(pDC->m_hDC,m_hRC);謝謝閱讀glMatrixMode(GL_MODELVIEW);精品文檔放心下載//二次曲面glColor3f(1.0f,0.0f,0.0f);感謝閱讀GLUquadric*qd=gluNewQuadric();//創(chuàng)建二次曲面對(duì)象精品文檔放心下載gluQuadricDrawStyle(qd,GLU_FILL);//設(shè)置二次曲面對(duì)象繪制模式GLU_LINE;GLU_SILHOUETTE;GLU_POINT感謝閱讀glLoadIdentity();glRotated(-105.0,1.0,0.0,0.0);感謝閱讀glTranslated(-6.0,0.0,-2.0);精品文檔放心下載gluCylinder(qd,2.0,1.0,4.0,30,4);//(圓臺(tái),下底面半徑,上底面半徑,圓臺(tái)高度,繞z軸分割瓣數(shù),感謝閱讀繞z軸方向?qū)訑?shù))glLoadIdentity();glTranslated(-6.0,0.0,-2.0);精品文檔放心下載gluDisk(qd,1.0,2.0,30,4);//平面圓盤(pán)(,內(nèi)圓半徑,外圓半徑,扇形瓣數(shù),環(huán)的個(gè)數(shù))精品文檔放心下載//...gluPartialDisk(qd,1.0,2.0,10,4,0,75);//謝謝閱讀始角,圖形張開(kāi)的角度)//...gluSphere(qd,2.0,30,6);//球(,球的半徑,分割的瓣數(shù),分割的層次)精品文檔放心下載auxSolidTetrahedron(4.0);//實(shí)體模型auxWireTeapot();auxSolidTeapot();感謝閱讀//auxWireSphere(3.0);auxSolidSphere(3.0);謝謝閱讀//auxWireCube(4.0);auxSolidCube(4.0);感謝閱讀//auxWireBox(3.0,4.0,5.0);auxSolidBox(3.0,4.0,5.0);感謝閱讀//auxWireTorus(1.0,3.0);//圓環(huán)auxSolidTorus(1.0,3.0);精品文檔放心下載//auxWireCylinder(2.0,4.0);auxSolidCylinder(2.0,4.0);精品文檔放心下載//auxWireIcosahedron(4.0);auxSolidIcosahedron(4.0);//二十面體謝謝閱讀//auxWireOctahedron(4.0);auxSolidOctahedron(4.0);//八面體感謝閱讀//auxWireTetrahedron(4.0);auxSolidTetrahedron(4.0);//四面體感謝閱讀//auxWireDodecahedron(4.0);auxSolidDodecahedron(4.0);//十二面體精品文檔放心下載//auxWireCone(2.0,4.0);auxSolidCone(2.0,4.0);//圓錐體感謝閱讀SwapBuffers(pDC->m_hDC);//雙緩沖精品文檔放心下載wglMakeCurrent(NULL,NULL);謝謝閱讀實(shí)驗(yàn)三光照與材質(zhì)一:實(shí)驗(yàn)?zāi)康模?.掌握利用OpenGL編寫(xiě)繪制具有真實(shí)感效果的圖形方法。謝謝閱讀2.掌握添加光源和設(shè)置顏色材料屬性的方法。二:實(shí)驗(yàn)內(nèi)容:1.掌握添加光源的實(shí)現(xiàn)方法。2.掌握設(shè)置顏色和材料屬性的方法。三:實(shí)驗(yàn)要求OpenGL編寫(xiě)繪制具有真實(shí)感謝閱讀感效果的圖形。四:實(shí)驗(yàn)程序?qū)嶒?yàn)步驟1~4與上述實(shí)驗(yàn)1相同5在OpenGLPlatView.cpp中OnDraw函數(shù)中添加以下代碼:謝謝閱讀wglMakeCurrent(pDC->m_hDC,m_hRC);精品文檔放心下載glClearColor(1.0f,1.0f,1.0f,1.0f);感謝閱讀glClearDepth(1.0);glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);感謝閱讀glEnable(GL_COLOR_MATERIAL);謝謝閱讀glEnable(GL_LIGHTING);glEnable(GL_LIGHT0);glEnable(GL_AUTO_NORMAL);glEnable(GL_NORMALIZE);glEnable(GL_DEPTH_TEST);glDepthFunc(GL_LESS);//設(shè)置模型變換矩陣glMatrixMode(GL_MODELVIEW);謝謝閱讀glLoadIdentity();//設(shè)置光源參數(shù)GLfloatlight_position[]={1.0f,1.0f,1.0f,0.0f};謝謝閱讀GLfloatlight_ambient[]={0.2f,0.2f,0.2f,0.2f};謝謝閱讀GLfloatlight_diffuse[]={0.5f,0.5f,0.2f,0.2f};感謝閱讀GLfloatlight_specular[]={0.5f,0.5f,0.5f,0.2f};精品文檔放心下載glLightfv(GL_LIGHT0,GL_POSITION,light_position);謝謝閱讀glLightfv(GL_LIGHT0,GL_AMBIENT,light_ambient);謝謝閱讀glLightfv(GL_LIGHT0,GL_DIFFUSE,light_diffuse);精品文檔放心下載glLightfv(GL_LIGHT0,GL_SPECULAR,light_specular);謝謝閱讀//設(shè)置材質(zhì)參數(shù)GLfloatmaterial_ambient[]={0.2f,0.2f,0.2f,0.2f};感謝閱讀GLfloatmaterial_diffuse[]={0.2f,0.8f,0.4f,0.8f};感謝閱讀GLfloatmaterial_specular[]={0.2f,0.8f,0.4f,0.8f};精品文檔放心下載GLfloatmaterial_emission[]={0.2f,0.2f,0.2f,1.0f};精品文檔放心下載GLfloatmaterial_shiness[]={10.0f};謝謝閱讀glMaterialfv(GL_BACK,GL_AMBIENT,material_ambient);//FRONT_AND_BACK感謝閱讀glMaterialfv(GL_BACK,GL_DIFFUSE,material_diffuse);感謝閱讀glMaterialfv(GL_BACK,GL_SPECULAR,material_specular);精品文檔放心下載glMaterialfv(GL_BACK,GL_EMISSION,material_emission);感謝閱讀glMaterialfv(GL_BACK,GL_SHININESS,material_shiness);感謝閱讀glColor3f(1.0f,0.0f,0.0f);//紅色謝謝閱讀glRotated(60.0,1.0,1.0,1.0);精品文檔放心下載auxSolidTeapot(2.0);SwapBuffers(pDC->m_hDC);//雙緩沖謝謝閱讀wglMakeCurrent(NULL,NULL);感謝閱讀實(shí)驗(yàn)結(jié)果:實(shí)驗(yàn)四紋理映射一:實(shí)驗(yàn)?zāi)康?.掌握二維紋理映射方法。2.掌握利用OpenGL編寫(xiě)繪制具有真實(shí)感效果的圖形方法。感謝閱讀二:實(shí)驗(yàn)內(nèi)容掌握二維紋理映射方法。三:實(shí)驗(yàn)要求通過(guò)本實(shí)驗(yàn),掌握掌握二維紋理映射方法。四:實(shí)驗(yàn)程序?qū)嶒?yàn)步驟1~4與上述實(shí)驗(yàn)1相同5在OpenGLPlatView.cpp中OnDraw函數(shù)中添加以下代碼:謝謝閱讀wglMakeCurrent(pDC->m_hDC,m_hRC);精品文檔放心下載glClearColor(1.0f,1.0f,1.0f,1.0f);謝謝閱讀glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);精品文檔放心下載glEnable(GL_COLOR_MATERIAL);謝謝閱讀glEnable(GL_LIGHTING);glEnable(GL_LIGHT0);glEnable(GL_AUTO_NORMAL);glEnable(GL_NORMALIZE);glEnable(GL_DEPTH_TEST);glDepthFunc(GL_LESS);glMatrixMode(GL_MODELVIEW);感謝閱讀glLoadIdentity();//設(shè)置光源參數(shù)GLfloatlight_position[]={1.0f,1.0f,1.0f,0.0f};感謝閱讀GLfloatlight_ambient[]={0.2f,0.2f,0.2f,0.2f};謝謝閱讀GLfloatlight_diffuse[]={0.5f,0.5f,0.2f,0.2f};謝謝閱讀GLfloatlight_specular[]={0.5f,0.5f,0.5f,0.2f};謝謝閱讀glLightfv(GL_LIGHT0,GL_POSITION,light_position);精品文檔放心下載glLightfv(GL_LIGHT0,GL_AMBIENT,light_ambient);感謝閱讀glLightfv(GL_LIGHT0,GL_DIFFUSE,light_diffuse);精品文檔放心下載glLightfv(GL_LIGHT0,GL_SPECULAR,light_specular);精品文檔放心下載//設(shè)置材質(zhì)參數(shù)GLfloatmaterial_ambient[]={0.2f,0.2f,0.2f,0.2f};感謝閱讀GLfloatmaterial_diffuse[]={0.2f,0.8f,0.4f,0.8f};精品文檔放心下載GLfloatmaterial_specular[]={0.2f,0.8f,0.4f,0.8f};精品文檔放心下載GLfloatmaterial_emission[]={0.2f,0.2f,0.2f,1.0f};謝謝閱讀GLfloatmaterial_shiness[]={10.0f};精品文檔放心下載glMaterialfv(GL_BACK,GL_AMBIENT,material_ambient);//FRONT_AND_BACK謝謝閱讀glMaterialfv(GL_BACK,GL_DIFFUSE,material_diffuse);感謝閱讀glMaterialfv(GL_BACK,GL_SPECULAR,material_specular);精品文檔放心下載glMaterialfv(GL_BACK,GL_EMISSION,material_emission);精品文檔放心下載glMaterialfv(GL_BACK,GL_SHININESS,material_shiness);精品文檔放心下載glRotated(80.0,1.0,1.0,1.0);精品文檔放心下載AUX_RGBImageRec*picture=auxDIBImageLoad(_T("C:\\tsIcon.bmp"));//(此處圖片路徑為C盤(pán)根目錄下)感謝閱讀if(picture!=NULL){glEnable(GL_TEXTURE_2D);glPixelStorei(GL_UNPACK_ALIGNMENT,1);謝謝閱讀glTexImage2D(GL_TEXTURE_2D,//二維紋理感謝閱讀0,//紋理層次3,//顏色分量個(gè)數(shù)picture->sizeX,//紋理寬度picture->sizeY,//紋理高度0,//紋理邊框?qū)挾龋ɑ颍〨L_RGB,//像素?cái)?shù)據(jù)格式GL_UNSIGNED_BYTE,//像素?cái)?shù)據(jù)類型picture->data);//存儲(chǔ)圖象數(shù)據(jù)glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT);//循環(huán)感謝閱讀glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_REPEAT);精品文檔放心下載glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);謝謝閱讀glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);謝謝閱讀glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MODULATE);//GL_DECAL,GL_謝謝閱讀}glBegin(GL_QUADS);glColor3f(0.0,1.0,0.0);glTexCoord2d(-2.0,-2.0);glVertex3d(-2.5,-2.5,3);感謝閱讀glTexCoord2d(-2.0,2.0);glVertex3d(2.5,-2.5,3);感謝閱讀glTexCoord2d(2.0,2.0);glVertex3d(2.5,2.5,3);謝謝閱讀glTexCoord2d(2.0,-2.0);glVertex3d(-2.5,2.5,3);感謝閱讀glColor3f(1.0,1.0,0.0);glTexCoord2d(0.0,0.0);glVertex3d(-2.5,2.5,0);精品文檔放心下載glTexCoord2d(0.0,1.0);glVertex3d(2.5,2.5,0);感謝閱讀glTexCoord2d(1.0,1.0);glVertex3d(2.5,2.5,3);謝謝閱讀glTexCoord2d(1.0,0.0);glVertex3d(-2.5,2.5,3);精品文檔放心下載glColor3f(1.0,0.0,1.0);glTexCoord2d(0.4,0.4);glVertex3d(-2.5,-2.5,0);精品文檔放心下載glTexCoord2d(0.4,0.6);glVertex3d(-2.5,-2.5,3);感謝閱讀glTexCoord2d(0.6,0.6);glVertex3d(-2.5,2.5,3);精品文檔放心下載glTexCoord2d(0.4,0.4);glVertex3d(-2.5,2.5,0);精品文檔放心下載glEnd();SwapBuffers(pDC->m_hDC);//雙緩沖精品文檔放心下載wglMakeCurrent(NULL,NULL);謝謝閱讀實(shí)驗(yàn)五基于OpenGL的動(dòng)畫(huà)編程一:實(shí)驗(yàn)?zāi)康?.掌握VC中的文檔視圖架構(gòu)。2.掌握利用OpenGL編寫(xiě)動(dòng)畫(huà)效果的方法。二:實(shí)驗(yàn)內(nèi)容掌握VC中的文檔視圖架構(gòu)及動(dòng)畫(huà)程序編寫(xiě)。三:實(shí)驗(yàn)要求通過(guò)本實(shí)驗(yàn),掌握利用OpenGL編寫(xiě)動(dòng)畫(huà)效果的方法。精品文檔放心下載四:實(shí)驗(yàn)程序?qū)嶒?yàn)步驟1~4與上述實(shí)驗(yàn)1相同5.添加Star類在Star.h中添加以下代碼#pragmaonce#include<gl/GL.h>#include<gl/GLU.h>#include<gl/GLAux.h>classStar{public:Star(void);intm_n;intm_sign;//變形符:增加,-1:減少doublem_radiusCenter;doublem_radiusMiddle;doublem_radiusCorner;GLfloatm_redCenter,m_greenCenter,m_blueCenter;精品文檔放心下載GLfloatm_redMiddle,m_greenMiddle,m_blueMiddle;感謝閱讀GLfloatm_redCorner,m_greenCorner,m_blueCorner;感謝閱讀GLdoublem_angle;//旋轉(zhuǎn)角度GLdoublem_point[26][3];//每個(gè)頂點(diǎn)坐標(biāo)值感謝閱讀GLfloatm_color[26][3];//每個(gè)頂點(diǎn)顏色值謝謝閱讀voidmb_adjustGLfloat(GLfloat&f,GLfloatmin,GLfloatmax);謝謝閱讀voidmb_calculatePoint(void);//計(jì)算頂點(diǎn)坐標(biāo)值謝謝閱讀voidmb_draw(void);//繪制圖形voidmb_nextFrame(void);//計(jì)算下一幀謝謝閱讀public:~Star(void);};在Star.cpp中添加以下代碼:#include"StdAfx.h"#include"Star.h"http://構(gòu)造函數(shù):初始化各個(gè)成員變量Star::Star(void){m_radiusCenter=2.0;//中心球半徑感謝閱讀m_radiusMiddle=2.828;//中間球半徑,這里2×sqrt(2)≈2.828精品文檔放心下載m_radiusCorner=3.464;//角上球半徑,這里2×sqrt(3)≈3.464謝謝閱讀m_redCenter=1.0f;//中心球點(diǎn)顏色m_greenCenter=0.0f;m_blueCenter=1.0f;m_redMiddle=0.0f;//中間球點(diǎn)顏色m_greenMiddle=1.0f;m_blueMiddle=0.0f;m_redCorner=0.0f;//角上球點(diǎn)顏色m_greenCorner=0.0f;m_blueCorner=1.0f;m_angle=45.0;//旋轉(zhuǎn)角度mb_calculatePoint();m_n=0;//變形計(jì)數(shù)器m_sign=1;//變形符號(hào):1:增加;-1:減小感謝閱讀}//構(gòu)造函數(shù)Star結(jié)束//析構(gòu)函數(shù)Star::~Star(void){}//析構(gòu)函數(shù)~Star結(jié)束//值調(diào)整函數(shù):強(qiáng)制使得參數(shù)f的值位于區(qū)間[min,max]內(nèi)謝謝閱讀voidStar::mb_adjustGLfloat(GLfloat&f,GLfloatmin,GLfloatmax)謝謝閱讀{if(f<min)f=min;if(f>max)f=max;}//函數(shù)mb_adjustGLfloat結(jié)束//計(jì)算頂點(diǎn)的坐標(biāo)值和顏色值voidStar::mb_calculatePoint(void)精品文檔放心下載{inti,j;intid1[]={0,2,6,8,1,3,5,7};感謝閱讀intid2[]={9,11,14,16,10,12,13,15};謝謝閱讀intsign1[]={-1,1,-1,1,0,-1,1,0};精品文檔放心下載intsign2[]={1,1,-1,-1,1,0,0,-1};感謝閱讀for(i=0,j=4;i<4;i++,j++){//下面0.577是“sqrt(3)/3”的近似值謝謝閱讀m_point[id1[i]][0]=0.577*m_radiusCorner*sign1[i];精品文檔放心下載m_point[id1[i]][1]=0.577*m_radiusCorner*sign2[i];精品文檔放心下載m_point[id1[i]][2]=0.577*m_radiusCorner;精品文檔放心下載m_color[id1[i]][0]=m_redCorner;感謝閱讀m_color[id1[i]][1]=m_greenCorner;感謝閱讀m_color[id1[i]][2]=m_blueCorner;謝謝閱讀//下面0.707是“sqrt(2)/2”的近似值m_point[id1[j]][0]=0.707*m_radiusMiddle*sign1[j];精品文檔放心下載m_point[id1[j]][1]=0.707*m_radiusMiddle*sign2[j];謝謝閱讀m_point[id1[j]][2]=0.707*m_radiusMiddle;謝謝閱讀m_color[id1[j]][0]=m_redMiddle;精品文檔放心下載m_color[id1[j]][1]=m_greenMiddle;精品文檔放心下載m_color[id1[j]][2]=m_blueMiddle;感謝閱讀}//for循環(huán)結(jié)束m_point[4][0]=0.0;m_point[4][1]=0.0;m_point[4][2]=m_radiusCenter;精品文檔放心下載m_color[4][0]=m_redCenter;精品文檔放心下載m_color[4][1]=m_greenCenter;精品文檔放心下載m_color[4][2]=m_blueCenter;感謝閱讀for(i=9;i<17;i++)m_point[i][2]=0.0;for(i=0,j=4;i<4;i++,j++){//下面0.707是“sqrt(2)/2”的近似值感謝閱讀m_point[id2[i]][0]=0.707*m_radiusMiddle*sign1[i];感謝閱讀m_point[id2[i]][1]=0.707*m_radiusMiddle*sign2[i];精品文檔放心下載m_color[id2[i]][0]=m_redMiddle;感謝閱讀m_color[id2[i]][1]=m_greenMiddle;感謝閱讀m_color[id2[i]][2]=m_blueMiddle;謝謝閱讀m_point[id2[j]][0]=m_radiusCenter*sign1[j];感謝閱讀m_point[id2[j]][1]=m_radiusCenter*sign2[j];感謝閱讀m_color[id2[j]][0]=m_redCenter;謝謝閱讀m_color[id2[j]][1]=m_greenCenter;謝謝閱讀m_color[id2[j]][2]=m_blueCenter;感謝閱讀}//for循環(huán)結(jié)束for(i=0,j=17;i<9;i++,j++){m_point[j][0]=m_point[i][0];謝謝閱讀m_point[j][1]=m_point[i][1];謝謝閱讀m_point[j][2]=-m_point[i][2];精品文檔放心下載m_color[j][0]=m_color[i][0];謝謝閱讀m_color[j][1]=m_color[i][1];謝謝閱讀m_color[j][2]=m_color[i][2];感謝閱讀}//for循環(huán)結(jié)束}//函數(shù)mb_calculatePoint結(jié)束//繪制圖形voidStar::mb_draw(void){inti,j,k,m;intid[3][8]={{0,0,1,4,3,6,4,8},//上表面三角形映射關(guān)系精品文檔放心下載{3,4,4,5,6,7,7,5},{4,1,2,2,4,4,8,4}};intface[4][9]={{0,1,2,9,10,11,17,18,19},//側(cè)面與表面的頂點(diǎn)映射關(guān)系精品文檔放心下載{0,3,6,9,12,14,17,20,23},{6,7,8,14,15,16,23,24,25},精品文檔放心下載{8,5,2,16,13,11,25,22,19}};glBegin(GL_TRIANGLES);for(i=0;i<8;i++)//上表面for(j=0;j<3;j++){m=id[j][i];glColor3f(m_color[m][0],m_color[m][1],m_color[m][2]);謝謝閱讀glVertex3d(m_point[m][0],m_point[m][1],m_point[m][2]);精品文檔放心下載}//for循環(huán)結(jié)束for(k=0;k<4;k++)//四個(gè)側(cè)面for(i=0;i<8;i++)for(j=0;j<3;j++){m=face[k][id[j][i]];glColor3f(m_color[m][0],m_color[m][1],m_color[m][2]);謝謝閱讀glVertex3d(m_point[m][0],m_point[m][1],m_point[m][2]);感謝閱讀}//for循環(huán)結(jié)束for(i=0;i<8;i++)//下表面for(j=0;j<3;j++){m=id[j][i]+17;glColor3f(m_color[m][0],m_color[m][1],m_color[m][2]);感謝閱讀glVertex3d(m_point[m][0],m_point[m][1],m_point[m][2]);謝謝閱讀}//for循環(huán)結(jié)束glEnd();}//函數(shù)mb_draw結(jié)束//計(jì)算下一幀旋轉(zhuǎn)角度以及頂點(diǎn)的坐標(biāo)值和顏色值voidStar::mb_nextFrame(void)感謝閱讀{intnMax=100;doubled=1.0/nMax;m_n+=m_sign;if(m_n>nMax)m_sign=-1;if(m_n<0)m_sign=1;m_radiusCenter+=(d*m_sign*1.0);感謝閱讀m_radiusMiddle-=(d*m_sign*2.0);謝謝閱讀m_radiusCorner+=(d*m_sign*3.0);感謝閱讀GLfloatdf=1.0f/nMax;m_redCenter-=(df*m_sign);//中心球點(diǎn)顏色謝謝閱讀mb_adjustGLfloat(m_redCenter,0.0f,1.0f);謝謝閱讀m_blueCenter-=(df*m_sign);謝謝閱讀mb_adjustGLfloat(m_blueCenter,0.0f,1.0f);精品文檔放心下載m_redCorner+=(df*m_sign);//角上球點(diǎn)顏色謝謝閱讀mb_adjustGLfloat(m_redCorner,0.0f,1.0f);精品文檔放心下載m_blueCorner=1.0f-m_redCorner;謝謝閱讀m_angle+=1.0;if(m_angle>360)m_angle=0.0;mb_calculatePoint();}//函數(shù)mb_nextFrame結(jié)束6.在COpenGLPlatView類開(kāi)頭添加#include"Star.h"在view中添加一個(gè)WM_TIMER函數(shù)voidCOpenGLPlatView::OnTimer(UINT_PTRnIDEvent)精品文檔放心下載{//TODO:在此添加消息處理程序代碼和/或調(diào)用默認(rèn)值謝謝閱讀COpenGLPlatDoc*pDoc=GetDocument();精品文檔放心下載ASSERT_VALID(pDoc);if(!pDoc)return;pDoc->m_star.mb_nextFrame();謝謝閱讀Invalidate();CView::OnTimer(nIDEvent);}在COpenGLPlatDoc類中添加m_star變量:精品文檔放心下載public:Starm_star;7.在view中的OnCreate函數(shù)中添加時(shí)間觸發(fā):精品文檔放心下載intCOpenGLPlatView::OnCreate(LPCREATESTRUCTlpCreateStruct)謝謝閱讀{if(CView::OnCreate(lpCreateStruct)==-1)精品文檔放心下載return-1;//TODO:在此添加您專用的創(chuàng)建代碼………..……….SetTimer(1,33,NULL);return0;}8.在view中的OnDestroy函數(shù)中添加代碼:精品文檔放心下載KillTimer(1);9.在OpenGLPlatView.cpp中OnDraw函數(shù)中添加以下代碼精品文檔放心下載voidCMy4View::OnDraw(CDC*pDC)精品文檔放心下載{CMy4Doc*pDoc=GetDocument();謝謝閱讀ASSERT_VALID(pDoc);if(!pDoc)return;wglMakeCurrent(pDC->m_hDC,m_hRC);謝謝閱讀glClearColor(1.0f,1.0f,1.0f,1.0f);謝謝閱讀glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);感謝閱讀glEnable(GL_COLOR_MATERIAL);感謝閱讀glEnable(GL_LIGHTING);glEnable(GL_LIGHT0);glEnable(GL_AUTO_NORMAL);glEnable(GL_NORMALIZE);glEnable(GL_DEPTH_TEST);glDepthFunc(GL_LESS);glMatrixMode(GL_MODELVIEW);謝謝閱讀glLoadIdentity();//設(shè)置光源參數(shù)GLfloatlight_position[]={1.0f,1.0f,1.0f,0.0f};精品文檔放心下載GLfloatlight_ambient[]={0.2f,0.2f,0.2f,0.2f};精品文檔放心下載GLfloatlight_diffuse[]={0.5f,0.5f,0.2f,0.2f
溫馨提示
- 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ì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 江蘇省南京市(2024年-2025年小學(xué)六年級(jí)語(yǔ)文)部編版小升初模擬(下學(xué)期)試卷及答案
- 《釵頭鳳陸游》課件
- 《上課影響價(jià)格的因素》課件
- 2024年綠色辦公裝修標(biāo)準(zhǔn)合同3篇
- 2024年貨車駕駛員辭職和解約合同
- 2024年物業(yè)公司維修工派遣協(xié)議
- 2024年茶具展會(huì)參展合同(展位面積與費(fèi)用)
- 2024年版連鎖加盟合同(餐飲業(yè))
- 2024年版權(quán)許可使用合同(獨(dú)家授權(quán))
- 2024張家港化工園區(qū)危險(xiǎn)品運(yùn)輸合同
- 2025蛇年帶橫批春聯(lián)對(duì)聯(lián)200副帶橫批
- 互聯(lián)網(wǎng)+創(chuàng)新商業(yè)模式考核試卷
- 江蘇省揚(yáng)州市梅嶺中學(xué)2023-2024學(xué)年七年級(jí)上學(xué)期期末地理試題(含答案)
- 克羅恩病病例分析
- 《冠心病》課件(完整版)
- DB43T 1694-2019 集體建設(shè)用地定級(jí)與基準(zhǔn)地價(jià)評(píng)估技術(shù)規(guī)范
- 高級(jí)技師電工培訓(xùn)
- 工程款代扣代付款協(xié)議書(shū)(2篇)
- 2024年湖北省高考化學(xué)試卷真題(含答案解析)
- 物業(yè)充電樁合作加盟協(xié)議書(shū)范文
- 機(jī)械工安全操作規(guī)程有哪些(11篇)
評(píng)論
0/150
提交評(píng)論