• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            Shuffy

            不斷的學習,不斷的思考,才能不斷的進步.Let's do better together!
            posts - 102, comments - 43, trackbacks - 0, articles - 19

                    本文將介紹如何從Obj文件格式中創建3D對象,我們使用的是Nate Millerobj格式加載類。

            This would be very useful to create large Virtual Reality applications as we could make use of the readily available 3D model files or make use of modeling tools to create these models and load them instead of creating them programatically. The .obj format is a very simple and popular format and files of other types such 3D Studio (.3ds) can be exported to this format or converted using tools such as 3D Exploration. This .obj loading code cannot read textures, it can only also read .mtl files in addition to the .obj file and thus make use of material data too.

            1, Nate Millerobj文件加載類,其完整源代碼可以從http://www.pobox.com/~ndr處下載。

            Glm頭文件

            2, 在第17篇的基礎上,CCY457OpenGLView類中加入下述變量,用來表示不同物體類型

                GLuint m_MonitorList; //顯示器
                GLuint m_ChairList; //椅子
                GLuint m_PotList; //花瓶
                GLuint m_ComputerList; //計算機
                int m_nObjectNo;

            2, InitializeOpenGL函數中加入對LoadModelsFromFiles的調用

            3, 繪制函數修改如下:

            void CCY457OpenGLView::RenderScene ()
            {
            //繪制函數
                
            //Position Camera
                gluLookAt(m_PosX,m_PosY,m_PosZ,m_DirX,m_DirY,m_DirZ,0.0f,1.0f,0.0f);
                
            //Draw the Scene
                
            //Draw the floor
                
            // Draw the ground, we do manual shading to a darker green
                
            // in the background to give the illusion of depth
                glEnable(GL_TEXTURE_2D);
                glBindTexture(GL_TEXTURE_2D, m_Texture[
            3]);
                glBegin(GL_POLYGON);
                glColor3ub(
            0,255,0);
                glTexCoord2f(
            0.0f0.0f);
                glVertex3f(
            -2.0f0.0f0.0f);
                glTexCoord2f(
            1.0f0.0f);
                glVertex3f(
            2.0f,0.0f0.0f);
                glColor3ub(
            0,100,0);    
                glTexCoord2f(
            1.0f1.0f);
                glVertex3f(
            2.0f0.0f-2.0f);
                glTexCoord2f(
            0.0f1.0f);
                glVertex3f(
            -2.0f,0.0f-2.0f);
                glEnd();
                glDisable(GL_TEXTURE_2D);
                
            //Draw the Cube
                
            // Save the matrix state and do the rotations
                glPushMatrix();
                glTranslatef(
            -1.0f,0.6f,-1.0f);
                
            // Draw jet at new orientation, put light in correct position
                
            // before rotating the jet
                glRotatef(m_xRot,1.0f,0.0f,0.0f);
                glRotatef(m_yRot,
            0.0f,1.0f,0.0f);
                DrawCube(FALSE);
                
            // Restore original matrix state
                glPopMatrix();    
                
            // Get ready to draw the shadow and the ground
                
            // First disable lighting and save the projection state
                glDisable(GL_DEPTH_TEST);
                glDisable(GL_LIGHTING);
                glPushMatrix();
                
            // Multiply by shadow projection matrix
                glMultMatrixf((GLfloat *)m_ShadowMat);
                glTranslatef(
            -1.0f,0.6f,-1.0f);
                glRotatef(m_xRot,
            1.0f,0.0f,0.0f);
                glRotatef(m_yRot,
            0.0f,1.0f,0.0f);
                
            // Pass true to indicate drawing shadow
                DrawCube(TRUE);    
                
            // Restore the projection to normal
                glPopMatrix();
                
            // Restore lighting state variables
                glEnable(GL_DEPTH_TEST);
                
            // Draw the light source
                glPushMatrix();
                glTranslatef(
            1.5f,1.5f,-1.0f);
                glColor3ub(
            255,255,0);
                glutSolidSphere(
            0.01f,10,10);
                glPopMatrix();
                glEnable(GL_LIGHTING);
            }
            void CCY457OpenGLView::DrawCube (BOOL bShadow)
            {
                
            // Set material color, note we only have to set to black
                
            // for the shadow once
                if(!bShadow)
                {
                    
            switch (m_nObjectNo)
                    {
                    
            case 0: glCallList(m_ChairList);
                        
            break;
                    
            case 1: glCallList(m_PotList);
                        
            break;
                    
            case 2: glCallList(m_ComputerList);
                        
            break;
                    
            case 3: glCallList(m_MonitorList);
                        
            break;
                    
            case 4: DrawCubeTex();
                        
            break;
                    }
                }
                
            else
                {
                    glColor3ub(
            0,0,0);
                    
            switch (m_nObjectNo)
                    {
                    
            case 0: glCallList(m_ChairList);
                        
            break;
                    
            case 1: glCallList(m_PotList);
                        
            break;
                    
            case 2: glCallList(m_ComputerList);
                        
            break;
                    
            case 3: glCallList(m_MonitorList);
                        
            break;
                    
            case 4: DrawCubeNoTex();
                        
            break;    
                    }
                }
            }

            4, 加載Obj文件的具體實現代碼:

            //Load all the Models from the Files of type .obj
            void CCY457OpenGLView::LoadModelsFromFiles()
            {
                GLfloat scalefactor 
            = 0.0;
                
            //Load Computer from file
                GLMmodel *object1;
                object1 
            = glmReadOBJ("models/computer.obj");
                
            if(!scalefactor) 
                {
                    scalefactor 
            = glmUnitize(object1);
                } 
                
            else 
                {
                    glmScale(object1, scalefactor);
                }
                glmScale(object1, 
            2.5);    
                
            /* build a display list */
                m_ComputerList 
            = glmList(object1, GLM_SMOOTH);
                
            /* nuke it, we don't need it anymore */
                glmDelete(object1);    
                
            //Load Chair From File
                GLMmodel *object2;
                scalefactor 
            = 0.0;
                object2 
            = glmReadOBJ("models/chair04.obj");
                
            if(!scalefactor) 
                {
                    scalefactor 
            = glmUnitize(object2);
                } 
                
            else 
                {
                    glmScale(object2, scalefactor);
                }
                glmScale(object2, 
            5.0);    
                
            /* build a display list */
                m_ChairList 
            = glmList(object2, GLM_SMOOTH);
                
            /* nuke it, we don't need it anymore */
                glmDelete(object2);    
                
            //Load Monitor from file
                GLMmodel *object5;
                scalefactor 
            = 0.0;
                object5 
            = glmReadOBJ("models/samsung.obj");
                
            if(!scalefactor) 
                {
                    scalefactor 
            = glmUnitize(object5);
                } 
                
            else 
                {
                    glmScale(object5, scalefactor);
                }
                glmScale(object5, 
            0.5);    
                
            /* build a display list */
                m_MonitorList 
            = glmList(object5, GLM_SMOOTH);
                
            /* nuke it, we don't need it anymore */
                glmDelete(object5);    
                
            //Load Phone Object from file
                GLMmodel *object6;
                scalefactor 
            = 0.0;
                object6 
            = glmReadOBJ("models/plant2.obj");
                
            if(!scalefactor) 
                {
                    scalefactor 
            = glmUnitize(object6);
                } 
                
            else 
                {
                    glmScale(object6, scalefactor);
                }
                glmScale(object6, 
            0.5);    
                
            /* build a display list */
                m_PotList 
            = glmList(object6, GLM_SMOOTH);
                
            /* nuke it, we don't need it anymore */
                glmDelete(object6);        
            }

             

            作者:洞庭散人

            出處:http://phinecos.cnblogs.com/    

            本文版權歸作者和博客園共有,歡迎轉載,但未經作者同意必須保留此段聲明,且在文章頁面明顯位置給出原文連接,否則保留追究法律責任的權利。
            原文鏈接:http://www.cnblogs.com/phinecos/archive/2008/11/07/1328957.html
            久久久久久久波多野结衣高潮 | 亚洲国产视频久久| 午夜精品久久久久久| 国产69精品久久久久久人妻精品| 国产A三级久久精品| 精品国产乱码久久久久久郑州公司| 7777久久久国产精品消防器材| 人妻丰满AV无码久久不卡| 狠色狠色狠狠色综合久久| 久久精品国产清自在天天线| 伊人久久大香线蕉无码麻豆| 久久青青草原综合伊人| 久久精品国产亚洲AV久| 久久午夜综合久久| 精品一区二区久久| 九九精品99久久久香蕉| 亚洲国产成人精品无码久久久久久综合 | 亚洲国产成人久久笫一页| 精品综合久久久久久97超人| 中文字幕日本人妻久久久免费 | 久久夜色精品国产网站| 亚洲精品tv久久久久| 亚洲午夜无码AV毛片久久| 久久强奷乱码老熟女| 久久久久人妻一区精品| 国产—久久香蕉国产线看观看| 久久精品国产第一区二区三区| 久久精品国产亚洲av麻豆图片| 久久人妻无码中文字幕| 色欲av伊人久久大香线蕉影院| 亚洲色大成网站www久久九| 久久婷婷国产剧情内射白浆 | 国产精品久久成人影院| 亚洲综合精品香蕉久久网97 | 亚洲中文字幕无码久久2020| 99国产欧美精品久久久蜜芽| 国产成人久久久精品二区三区 | 国内精品伊人久久久久av一坑| 久久久青草久久久青草| 2021国产精品久久精品| 日韩亚洲国产综合久久久|