【正文】
CCY457OpenGLView::OnShadingmodelSmooth()CView::OnTimer(nIDEvent)。InvalidateRect(NULL,m_yRotm_yRotm_xRotm_xRot{CCY457OpenGLView::OnTimer(UINT==//繞x,y軸旋轉(zhuǎn)的角度,隨時(shí)間不斷變化m_xRot,一個(gè)簡(jiǎn)單Demo1,:OpenGL支持兩種顏色模式:RGBA和顏色索引模式,本文關(guān)注于前者。glutWireSphere(,20,20)。Moon//Draw)。,glRotatef((GLfloat)glutWireSphere(,20,20)。Planet//DrawglRotatef((GLfloat)(360*HourOfDay)/,orbitintheglPushMatrix()。)。,glRotatef((GLfloat)orbitintheglutWireSphere(,20,20)。Sun//DrawCCY457OpenGLView::RenderSceneCView::OnTimer(nIDEvent)。InvalidateRect(NULL,=HourOfDay++。365)if(HourOfDay=DayOfYear++。365)if(DayOfYear{CCY457OpenGLView::OnTimer(UINT}5,在OnTimer函數(shù)中,通過(guò)增加變量DayOfYear 和 HourOfDay的值來(lái)控制地球和月球的位置,并且調(diào)用InvalidateRect來(lái)刷新界面。}DWORD}DWORDreturnreturn)==(ElapsedTimeinMSSinceLastRender()。eTimevoidcalculationsintframeFramesPerSecond//)。GetParentFrame()SetWindowText(FramesPerSecond()(const),%d%sstring,string[256]。0。updateFrame++updateFrame(1615。updateFramestaticsecond)everyisredrawseverytheOnlyvoidlike.voidifownwithReplacesthe//framerateplacesdefaultprocessing//postPostRenderScene//m_ElapsedTime。m_previousElapsedTimeratetherendersinceelapsedcalculatetimenextwithistime,thetodothingvery//1/2//about(this15titleupdate//ProcessingPost)。::SwapBuffers(buffersSwap//itstoTellglPopMatrix()。glPushMatrix()。GL_DEPTH_BUFFER_BITGL_COLOR_BUFFER_BITdepthamp。theClear30ElapsedTimeinMSSinceLastRender()iftimeget=insystemGetASSERT_VALID(pDoc)。=CCY457OpenGLDoc*pDC){void}3,為了計(jì)算幀速率,修改OnCreate函數(shù),在其中獲取窗口標(biāo)題,從標(biāo)題中去掉”Untitled”字樣,并啟動(dòng)定時(shí)器;4,同樣為了計(jì)算幀速率,修改OnDraw函數(shù)如下,在其中用glPushMatrix 和 glPopMatrix將RenderScene函數(shù)包裹起來(lái),從而確保動(dòng)畫會(huì)正確運(yùn)行。=1。DayOfYear并在構(gòu)造函數(shù)中進(jìn)行初始化:CCY457OpenGLView::CCY457OpenGLView(){intintTitlem_WindowTitle。m_previousElapsedTime。m_StartTime,timing//For)并且Link—Object/library 2,為了計(jì)算繪制用時(shí),:lltimersforFrame RateFrame rate is nothing but the number of frames that can be rendered per second. The higher this rate, the smoother the animation. In order to calculate the frame rate we retrieve the system time (using the Windows multimedia API function timeGetTime()) before the rendering is performed and after the buffer is swapped. The difference between the two values is the elapsed time to render one frame. Thus we can calculate the frame rate for a given application.1,我們需要調(diào)用timeGetTime()函數(shù),:include 本文中將對(duì)第5篇文章的太陽(yáng)系模型進(jìn)行修改,加入一些動(dòng)畫效果。}0 0 0 (請(qǐng)您對(duì)文章做出評(píng)價(jià))光榮在于平淡,艱巨因?yàn)槁L(zhǎng)《基于MFC的OpenGL編程》Part 7 Animation CView::OnMouseMove(nFlags,m_MouseDownPoint=point。pointtheInvalidateRect(NULL,FALSE)。view//Redrawm_xAngle+=()/。anglesobject//Increment{(GetCapture()==this)thehaveif//defaultand/orcodemessageAdd//{CPointCOpenGLView::OnMouseMove(UINTpoint)。ReleaseCapture()。callherehandleryourTODO:point)nFlags,}voidCView::OnLButtonDown(nFlags,m_MouseDownPoint=point。defaultand/orcodemessageAdd//{CPointCOpenGLView::OnLButtonDown(UINTnFlags)。CView::OnKeyDown(nChar,break。keysthebreak。m_xPosm_xPosVK_RIGHT:break。m_xPosm_xPosVK_LEFT:break。m_yPosm_yPosVK_DOWN:break。m_yPosm_yPosVK_UP:switchdefaultand/orcodemessageAdd//{UINTUINTCOpenGLView::OnKeyDown(UINTglutWireCube()。glRotatef(m_yAngle,glRotatef(m_xAngle,m_yPos,glLoadIdentity()。(){}3,加入繪制代碼:voidm_yAnglem_xAnglem_yPosm_xPos并在構(gòu)造函數(shù)中初始化:CCY457OpenGLView::CCY457OpenGLView(){CPointGLfloatGLfloatGLfloatGLfloat2,: 1,首先在CCY457OpenGLView類中為WM_KEYDOWN,光榮在于平淡,艱巨因?yàn)槁L(zhǎng)《基于MFC的OpenGL編程》Part 6 Keyboard and Mouse Control glPopMatrix()。glutWireSphere(,20,20)。glTranslatef(,)。//DrawglRotatef(6,)。glPushMatrix()。PlanetglutWireSphere(,20,20)。glTranslatef(,)。SunCCY457OpenGLView::RenderScene}}1 0 0 (請(qǐng)您對(duì)文章做出評(píng)價(jià))光榮在于平淡,艱巨因?yàn)槁L(zhǎng)《基于MFC的OpenGL編程》Part 5 Transformations Rotations, Translations and Scaling Transformations Translation, Rotation and Scaling Translation is nothing but moving along an arbitrary axis. Rotation is spinning about an arbitrary axis. Scaling is increase or decrease in size along an arbitrary axis. One important point to remember is that OpenGL uses a right hand coordinate system where Zve goes into the Screen. An object said to be undergoing a transformation could be undergoing a translation, rotation and/or scaling. Understanding how different types of transformations work together is very important. 本文將對(duì)地球進(jìn)行建模,讓其圍繞著太陽(yáng),此外它還會(huì)有月球伴隨,而在下文中將會(huì)加入對(duì)鼠標(biāo)和鍵盤的事件響應(yīng)機(jī)制。)。,glVertex3f(,glVertex3f(,)。,glBegin(GL_POLYGON)。FaceglEnd()。,)。,)。,glVertex3f(glVertex3f(,//Top)。glVertex3f(,glVertex3f(,)。glBegin(GL_POLYGON)。FaceglEnd()。,)。)。glVertex3f(,glVertex3f(,//Left,)。,)。glVertex3f(glVertex3f(,glBegin(GL_POLYGON)。FaceglEnd()。glVertex3f(,)。glVertex3f(,)。//FrontglPolygonMode(GL_FRONT_AND_BACK,{if(m_bSimpleCube)individuallythebyaglutWireIcosahedron()。{if(m_bIcosahedron)Icosahedron//Draw}a50)。,aglutWireCube()。{if(m_bCube)Cu