《基于MFC的OpenGL编程》Part 19 Creating a Virtual Reality Walkthrough Application

 本文是整个系列文章的最后一篇,将创建一个完整的虚拟office应用程序(如图所示)来做为ending.



1,在CCY457OpenGLView类中加入下述变量,用来保存office内各个物体的显示列表

复制代码
    //Display List Names
    GLuint m_SceneList;
    GLuint m_ComputerList;
    GLuint m_ChairList;
    GLuint m_BlindsList;
    GLuint m_MonitorList;
    GLuint m_BooksList;
    GLuint m_PhoneList;
    GLuint m_DoorList;
复制代码
2,创建房间内部场景

复制代码

//Create the Display List for the Scene
void CCY457OpenGLView::CreateSceneList()
{
    m_SceneList = glGenLists(1);
    glNewList(m_SceneList, GL_COMPILE);
    /******************Setup Lighting**********************/
    SetupLighting();
    /***************Draw the Scene*************************/
    //Draw the Walls
    DrawWalls();            
    //Draw the Wall Tops, Sides and Desks
    DrawWallTopsAndSides();
    //Draw the desks
    DrawDesks();
    //Draw the computers
    DrawComputers();    
    //Draw the Chairs
    DrawChairs();
    //Draw the Blinds
    DrawBlinds();
    //Draw Phones
    DrawPhones();
    //Draw Floor and Ceiling
    DrawFloorAndCeiling();
    glEndList();
}
复制代码
3,从Obj文件中加载各个物件的3D模型

复制代码
//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("Data/models/computer.obj");
    if(!scalefactor) 
    {
        scalefactor = glmUnitize(object1);
    } 
    else 
    {
        glmScale(object1, scalefactor);
    }
    glmScale(object1, 1.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("Data/models/chair04.obj");
    if(!scalefactor) 
    {
        scalefactor = glmUnitize(object2);
    } 
    else 
    {
        glmScale(object2, scalefactor);
    }
    glmScale(object2, 2.5);    
    /* build a display list */
    m_ChairList = glmList(object2, GLM_SMOOTH);
    /* nuke it, we don't need it anymore */
    glmDelete(object2);    
    //Load Blinds Object From File
    GLMmodel *object3;
    scalefactor = 0.0;
    object3 = glmReadOBJ("Data/models/blinds.obj");
    if(!scalefactor) 
    {
        scalefactor = glmUnitize(object3);
    } 
    else 
    {
        glmScale(object3, scalefactor);
    }
    glmScale(object3, 1.0);    
    /* build a display list */
    m_BlindsList = glmList(object3, GLM_SMOOTH);
    /* nuke it, we don't need it anymore */
    glmDelete(object3);    
    //Load Books Object from file
    GLMmodel *object4;
    scalefactor = 0.0;
    object4 = glmReadOBJ("Data/models/books.obj");
    if(!scalefactor) 
    {
        scalefactor = glmUnitize(object4);
    } 
    else 
    {
        glmScale(object4, scalefactor);
    }
    glmScale(object4, 1.2);    
    /* build a display list */
    m_BooksList = glmList(object4, GLM_SMOOTH);
    /* nuke it, we don't need it anymore */
    glmDelete(object4);    
    //Load Monitor from file
    GLMmodel *object5;
    scalefactor = 0.0;
    object5 = glmReadOBJ("Data/models/samsung.obj");
    if(!scalefactor) 
    {
        scalefactor = glmUnitize(object5);
    } 
    else 
    {
        glmScale(object5, scalefactor);
    }
    glmScale(object5, 0.20);    
    /* 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("Data/models/phone.obj");
    if(!scalefactor) 
    {
        scalefactor = glmUnitize(object6);
    } 
    else 
    {
        glmScale(object6, scalefactor);
    }
    glmScale(object6, 0.08);    
    /* build a display list */
    m_PhoneList = glmList(object6, GLM_SMOOTH);
    /* nuke it, we don't need it anymore */
    glmDelete(object6);        
}
复制代码

本文转自Phinecos(洞庭散人)博客园博客,原文链接http://www.cnblogs.com/phinecos/archive/2008/11/07/1328998.html,如需转载请自行联系原作者
上一篇:对中文语法的编程语言的质疑与回应


下一篇:类似微信通讯录界面的排序方法及中文转拼音的方法