Shuffy

不断的学习,不断的思考,才能不断的进步.Let's do better together!
posts - 102, comments - 43, trackbacks - 0, articles - 19

        本文是整个系列文章的最后一篇,将创建一个完整的虚拟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);        
}

4,创建各个具体物件的代码:


void CCY457OpenGLView::DrawPentagonTable()
{
    glBegin(GL_TRIANGLES);
    
//Table Top
    glNormal3f(0.0f,1.0f,0.0f);
    
//Light Brown
    glColor3f(0.7f,0.6f,0.55f);
    glVertex3f(
-0.75f,0.3f,-0.05f);
    glVertex3f(
-0.05f,0.3f,-0.05f);
    glVertex3f(
-0.75f,0.3f,-0.45f);
    glVertex3f(
-0.75f,0.3f,-0.45f);
    glVertex3f(
-0.05f,0.3f,-0.05f);
    glVertex3f(
-0.45f,0.3f,-0.75f);
    glVertex3f(
-0.45f,0.3f,-0.75f);
    glVertex3f(
-0.05f,0.3f,-0.05f);
    glVertex3f(
-0.05f,0.3f,-0.75f);
    
//Table Front
    glColor3f(0.9f,0.9f,0.8f);
    glVertex3f(
-0.75f,0.25f,-0.45f);
    glVertex3f(
-0.75f,0.3f,-0.45f);
    glVertex3f(
-0.45f,0.3f,-0.75f);
    glVertex3f(
-0.75f,0.25f,-0.45f);
    glVertex3f(
-0.45f,0.3f,-0.75f);
    glVertex3f(
-0.45f,0.25f,-0.75f);
    glEnd();
    glDisable(GL_LIGHTING);
    glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);
    glPolygonOffset(
1.0f,-3.0f);
    glEnable(GL_POLYGON_OFFSET_LINE);
    
//Front Edge
    glBegin(GL_POLYGON);
    glColor3f(
0.0f,0.0f,0.0f);
    glVertex3f(
-0.75f,0.25f,-0.45f);
    glVertex3f(
-0.75f,0.3f,-0.45f);
    glVertex3f(
-0.45f,0.3f,-0.75f);
    glVertex3f(
-0.45f,0.25f,-0.75f);
    glEnd();
    glEnable(GL_LIGHTING);
    glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);
    glEnable(GL_POLYGON_OFFSET_LINE);
}
void CCY457OpenGLView::DrawWalls()
{
    
//Draw the Walls for which Front Faces can be culled
    
//Cull Front Faces
    
//Enable Culling
    glEnable(GL_CULL_FACE);
    
//Cull Front Faces        
    glCullFace(GL_FRONT);    
    glBegin(GL_TRIANGLES);
    
//Draw the Back Wall
    
//Define Back Wall Normal
    glNormal3f(0.0f,0.0f,1.0f);
    
//Define Back Wall Material - Light Grey
    glColor3f(0.75f,0.75f,0.75f);
    
//Back Wall Triangles
    glVertex3f(0.0f,0.0f,0.0f);
    glVertex3f(
0.0f,1.0f,0.0f);
    glVertex3f(
-5.5f,1.0f,0.0f);
    glVertex3f(
0.0f,0.0f,0.0f);
    glVertex3f(
-5.5f,1.0f,0.0f);
    glVertex3f(
-5.5f,0.0f,0.0f);    
    
//Back Wall Thickness
    glVertex3f(-0.0f,0.0f,-0.05f);
    glVertex3f(
-0.0f,1.0f,-0.05f);
    glVertex3f(
-5.5f,1.0f,-0.05f);
    glVertex3f(
-0.0f,0.0f,-0.05f);
    glVertex3f(
-5.5f,1.0f,-0.05f);
    glVertex3f(
-5.5f,0.0f,-0.05f);    
    
//Draw the Right Wall
    
//Define Right Wall Normal
    glNormal3f(1.0f,0.0f,0.0f);
    
//Define Right Wall Material - Light Brown
    glColor3f(0.7f,0.6f,0.55f);
    
//Right Wall Triangles
    glVertex3f(0.0f,0.0f,-0.05f);
    glVertex3f(
0.0f,0.0f,-2.95f);
    glVertex3f(
0.0f,0.6f,-0.05f);
    glVertex3f(
0.0f,0.0f,-2.95f);
    glVertex3f(
0.0f,0.6f,-2.95f);
    glVertex3f(
0.0f,0.6f,-0.05f);
    
//Right Wall Thickness
    glVertex3f(-0.05f,0.0f,-0.05f);
    glVertex3f(
-0.05f,0.0f,-2.95f);
    glVertex3f(
-0.05f,0.6f,-0.05f);
    glVertex3f(
-0.05f,0.0f,-2.95f);
    glVertex3f(
-0.05f,0.6f,-2.95f);
    glVertex3f(
-0.05f,0.6f,-0.05f);
    
//Draw the Left Wall
    
//Define Left Wall Normal
    glNormal3f(-1.0f,0.0f,0.0f);
    
//Left Wall Triangles
    glVertex3f(-5.5f,0.0f,-0.05f);
    glVertex3f(
-5.5f,1.0f,-0.05f);
    glVertex3f(
-5.5f,1.0f,-2.95f);
glVertex3f(
-5.5f,0.0f,-0.05f);
    glVertex3f(
-5.5f,1.0f,-2.95f);
    glVertex3f(
-5.5f,0.0f,-2.95f);
    
//Left Wall Thickness
    glVertex3f(-5.45f,0.0f,-0.05f);
    glVertex3f(
-5.45f,1.0f,-0.05f);
    glVertex3f(
-5.45f,1.0f,-2.95f);
    glVertex3f(
-5.45f,0.0f,-0.05f);
    glVertex3f(
-5.45f,1.0f,-2.95f);
    glVertex3f(
-5.45f,0.0f,-2.95f);
    glEnd();
    
//Draw the Pillar
    
//Cull Back Faces for Pillar
    glCullFace(GL_BACK);
    
//Right
    glBegin(GL_POLYGON);        
    glVertex3f(
-3.2f,0.0f,-1.5f);
    glVertex3f(
-3.2f,1.0f,-1.5f);
    glVertex3f(
-3.2f,1.0f,-1.0f);
    glVertex3f(
-3.2f,0.0f,-1.0f);
    glEnd();
    
//Left
    glBegin(GL_POLYGON);
    glVertex3f(
-3.7f,0.0f,-1.5f);
    glVertex3f(
-3.7f,0.0f,-1.0f);
    glVertex3f(
-3.7f,1.0f,-1.0f);
    glVertex3f(
-3.7f,1.0f,-1.5f);
    glEnd();
    
//Front
    glBegin(GL_POLYGON);
    glVertex3f(
-3.2f,0.0f,-1.5f);
    glVertex3f(
-3.7f,0.0f,-1.5f);
    glVertex3f(
-3.7f,1.0f,-1.5f);
    glVertex3f(
-3.2f,1.0f,-1.5f);
    glEnd();
    
//Back
    glBegin(GL_POLYGON);
    glVertex3f(
-3.2f,0.0f,-1.0f);
    glVertex3f(
-3.2f,1.0f,-1.0f);
    glVertex3f(
-3.7f,1.0f,-1.0f);
    glVertex3f(
-3.7f,0.0f,-1.0f);
    glEnd();
    
//Draw the edges
    glColor3f(0.0f,0.0f,0.0f);
    glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);
    
//Right
    glBegin(GL_POLYGON);        
    glVertex3f(
-3.2f,0.0f,-1.5f);
    glVertex3f(
-3.2f,1.0f,-1.5f);
    glVertex3f(
-3.2f,1.0f,-1.0f);
    glVertex3f(
-3.2f,0.0f,-1.0f);
    glEnd();
    
//Left
    glBegin(GL_POLYGON);
    glVertex3f(
-3.7f,0.0f,-1.5f);
    glVertex3f(
-3.7f,0.0f,-1.0f);
    glVertex3f(
-3.7f,1.0f,-1.0f);
    glVertex3f(
-3.7f,1.0f,-1.5f);
    glEnd();
    
//Front
    glBegin(GL_POLYGON);
    glVertex3f(
-3.2f,0.0f,-1.5f);
    glVertex3f(
-3.7f,0.0f,-1.5f);
    glVertex3f(
-3.7f,1.0f,-1.5f);
    glVertex3f(
-3.2f,1.0f,-1.5f);
    glEnd();
    glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
    glColor3f(
0.7f,0.6f,0.55f);
    
//Draw the walls for which No faces can be culled
    glDisable(GL_CULL_FACE);
    glBegin(GL_TRIANGLES);
    
//Draw the Front Right Wall            
    
//Define Front Right Wall Normal
    glNormal3f(0.0f,0.0f,-1.0f);
    
//Front Right Wall Triangles
    glVertex3f(0.0f,0.0f,-3.0f);
    glVertex3f(
-3.5f,0.0f,-3.0f);
    glVertex3f(
0.0f,0.6f,-3.0f);
    glVertex3f(
-3.5f,0.0f,-3.0f);
    glVertex3f(
-3.5f,0.6f,-3.0f);
    glVertex3f(
0.0f,0.6f,-3.0f);
    
//Front Right Wall Thickness
    glVertex3f(0.0f,0.0f,-2.95f);
    glVertex3f(
-3.5f,0.0f,-2.95f);
    glVertex3f(
0.0f,0.6f,-2.95f);
    glVertex3f(
-3.5f,0.0f,-2.95f);
    glVertex3f(
-3.5f,0.6f,-2.95f);
    glVertex3f(
0.0f,0.6f,-2.95f);
    
//Draw the Front Left Wall
    
//Front Left Wall Triangles
    glVertex3f(-4.0f,0.0f,-3.0f);
    glVertex3f(
-5.5f,0.0f,-3.0f);
    glVertex3f(
-4.0f,0.6f,-3.0f);
    glVertex3f(
-5.5f,0.0f,-3.0f);
    glVertex3f(
-5.5f,0.6f,-3.0f);
    glVertex3f(
-4.0f,0.6f,-3.0f);
    
//Front Left Wall Thickness
    glVertex3f(-4.0f,0.0f,-2.95f);
    glVertex3f(
-5.5f,0.0f,-2.95f);
    glVertex3f(
-4.0f,0.6f,-2.95f);
    glVertex3f(
-5.5f,0.0f,-2.95f);
    glVertex3f(
-5.5f,0.6f,-2.95f);
    glVertex3f(
-4.0f,0.6f,-2.95f);
    glEnd();
}
void CCY457OpenGLView::DrawWallTopsAndSides()
{
    
//Cull Back Faces
    glEnable(GL_CULL_FACE);
    glCullFace(GL_BACK);
    glBegin(GL_TRIANGLES);
    
//Define Normals
    glNormal3f(0.0f,1.0f,0.0f);
    
//Define Material - Light Brown    
    glColor3f(0.7f,0.6f,0.55f);
    
//Back Wall Top
    glVertex3f(0.0f,1.0f,0.0f);
    glVertex3f(
0.0f,1.0f,-0.05f);
    glVertex3f(
-5.5f,1.0f,0.0f);
    glVertex3f(
0.0f,1.0f,-0.05f);
    glVertex3f(
-5.5f,1.0f,-0.05f);
    glVertex3f(
-5.5f,1.0f,0.0f);
    
//Right Wall Top
    glVertex3f(0.0f,0.6f,-0.05f);
    glVertex3f(
-0.05f,0.6f,-2.95f);
    glVertex3f(
-0.05f,0.6f,-0.05f);
glVertex3f(
0.0f,0.6f,-0.05f);
    glVertex3f(
0.0f,0.6f,-2.95f);
    glVertex3f(
-0.05f,0.6f,-2.95f);
    
//Left Wall Top
    glVertex3f(-5.45f,1.0f,-0.05f);
    glVertex3f(
-5.5f,1.0f,-2.95f);
    glVertex3f(
-5.5f,1.0f,-0.05f);
glVertex3f(
-5.45f,1.0f,-0.05f);
    glVertex3f(
-5.45f,1.0f,-2.95f);
    glVertex3f(
-5.5f,1.0f,-2.95f);
    
//Left Wall Side
    glNormal3f(0.0f,0.0f,-1.0f);
    glVertex3f(
-5.45f,1.0f,-2.95f);
    glVertex3f(
-5.5f,0.0f,-2.95f);
    glVertex3f(
-5.5f,1.0f,-2.95f);
    glVertex3f(
-5.45f,1.0f,-2.95f);
    glVertex3f(
-5.45f,0.0f,-2.95f);
    glVertex3f(
-5.5f,0.0f,-2.95f);
    
//Front Right Wall Top
    glVertex3f(0.0f,0.6f,-2.95f);
    glVertex3f(
0.0f,0.6f,-3.0f);
    glVertex3f(
-3.5f,0.6f,-2.95f);
    glVertex3f(
0.0f,0.6f,-3.0f);
    glVertex3f(
-3.5f,0.6,-3.0f);
    glVertex3f(
-3.5f,0.6f,-2.95f);
    
//Front Left Wall Top
    glVertex3f(-4.0f,0.6,-2.95f);
    glVertex3f(
-4.0f,0.6f,-3.0f);
    glVertex3f(
-5.5f,0.6f,-2.95f);
    glVertex3f(
-4.0f,0.6f,-3.0f);
    glVertex3f(
-5.5f,0.6,-3.0f);
    glVertex3f(
-5.5f,0.6f,-2.95f);
    
//Front Right Wall Left Side
    glNormal3f(-1.0f,0.0f,0.0f);
    glVertex3f(
-3.5f,0.6f,-2.95f);
    glVertex3f(
-3.5f,0.6f,-3.0f);
    glVertex3f(
-3.5f,0.0f,-2.95f);
    glVertex3f(
-3.5f,0.6f,-3.0f);
    glVertex3f(
-3.5f,0.0f,-3.0f);
    glVertex3f(
-3.5f,0.0f,-2.95f);
    
//Front Right Wall Right Side
    glNormal3f(1.0f,0.0f,0.0f);
    glVertex3f(
0.0f,0.0f,-3.0f);
    glVertex3f(
0.0f,0.6f,-2.95f);
    glVertex3f(
0.0f,0.0f,-2.95f);
    glVertex3f(
0.0f,0.0f,-3.0f);
    glVertex3f(
0.0f,0.6f,-3.0f);
    glVertex3f(
0.0f,0.6f,-2.95f);
    
//Front Left Wall Side
    glNormal3f(1.0f,0.0f,0.0f);
    glVertex3f(
-4.0f,0.6f,-3.0f);
    glVertex3f(
-4.0f,0.6f,-2.95f);
    glVertex3f(
-4.0f,0.0f,-3.0f);
    glVertex3f(
-4.0f,0.6f,-2.95f);
    glVertex3f(
-4.0f,0.0f,-2.95f);
    glVertex3f(
-4.0f,0.0f,-3.0f);
}
void CCY457OpenGLView::DrawDesks()
{
    
//Desks
    
//Draw the Front Long Desk
    glNormal3f(0.0f,1.0f,0.0f);
    
//Brown
    glColor3f(0.7f,0.6f,0.55f);
    glVertex3f(
-3.5f,0.3f,-2.55f);
    glVertex3f(
-0.75f,0.3f,-2.55f);
    glVertex3f(
-3.5f,0.3f,-2.95f);
    glVertex3f(
-3.5f,0.3f,-2.95f);
    glVertex3f(
-0.75f,0.3f,-2.55f);
    glVertex3f(
-0.75f,0.3f,-2.95f);
    
//Draw the Front Long Desk Thickness
    glVertex3f(-3.5f,0.25f,-2.55f);
    glVertex3f(
-0.75f,0.25f,-2.55f);
    glVertex3f(
-3.5f,0.25f,-2.95f);
    glVertex3f(
-3.5f,0.25f,-2.95f);
    glVertex3f(
-0.75f,0.25f,-2.55f);
    glVertex3f(
-0.75f,0.25f,-2.95f);
    
//Draw the Front Long Desk Front 
    glNormal3f(0.0f,0.0f,1.0f);
    glColor3f(
0.9f,0.9f,0.8f);
    glVertex3f(
-0.75f,0.25f,-2.55f);
    glVertex3f(
-0.75f,0.3f,-2.55f);
    glVertex3f(
-3.5f,0.25f,-2.55f);
    glVertex3f(
-3.5f,0.25f,-2.55f);
    glVertex3f(
-0.75f,0.3f,-2.55f);
    glVertex3f(
-3.5f,0.3f,-2.55f);
    
//Draw the Front Long Desk Side 
    glNormal3f(-1.0f,0.0f,0.0f);
    glVertex3f(
-3.5f,0.25f,-2.55f);
    glVertex3f(
-3.5f,0.3f,-2.55f);
    glVertex3f(
-3.5f,0.25f,-2.95f);
    glVertex3f(
-3.5f,0.25f,-2.95f);
    glVertex3f(
-3.5f,0.3f,-2.55f);
    glVertex3f(
-3.5f,0.3f,-2.95f);
    
//Draw the Front Short Desk
    glNormal3f(0.0f,1.0f,0.0f);
    glColor3f(
0.7f,0.6f,0.55f);
    glVertex3f(
-4.75f,0.3f,-2.55f);
    glVertex3f(
-4.0f,0.3f,-2.55f);
    glVertex3f(
-4.75f,0.3f,-2.95f);
    glVertex3f(
-4.75f,0.3f,-2.95f);
    glVertex3f(
-4.0f,0.3f,-2.55f);
    glVertex3f(
-4.0f,0.3f,-2.95f);
    
//Draw the Front Short Desk Thickness
    glVertex3f(-4.75f,0.25f,-2.55f);
    glVertex3f(
-4.0f,0.25f,-2.55f);
    glVertex3f(
-4.75f,0.25f,-2.95f);
    glVertex3f(
-4.75f,0.25f,-2.95f);
    glVertex3f(
-4.0f,0.25f,-2.55f);
    glVertex3f(
-4.0f,0.25f,-2.95f);
    
//Draw the Front Short Desk Front Thickness
    glNormal3f(0.0f,0.0f,1.0f);
    glColor3f(
0.9f,0.9f,0.8f);
    glVertex3f(
-4.0f,0.25f,-2.55f);
    glVertex3f(
-4.0f,0.3f,-2.55f);
    glVertex3f(
-4.75f,0.3f,-2.55f);
    glVertex3f(
-4.0f,0.25f,-2.55f);
    glVertex3f(
-4.75f,0.3f,-2.55f);
    glVertex3f(
-4.75f,0.25f,-2.55f);
    
//Draw the Front Short Desk Side Thickness
    glNormal3f(1.0f,0.0f,0.0f);
    glColor3f(
0.9f,0.9f,0.8f);
    glVertex3f(
-4.0f,0.25f,-2.95f);
    glVertex3f(
-4.0f,0.3f,-2.95f);
    glVertex3f(
-4.0f,0.3f,-2.55f);
glVertex3f(
-4.0f,0.25f,-2.95f);
    glVertex3f(
-4.0f,0.3f,-2.55f);
    glVertex3f(
-4.0f,0.25f,-2.55f);
    
//Draw the Right Middle Desk 
    glNormal3f(0.0f,1.0f,0.0f);
    glColor3f(
0.7f,0.6f,0.55f);
    glVertex3f(
-0.45f,0.3f,-0.75f);
    glVertex3f(
-0.05f,0.3f,-0.75f);
    glVertex3f(
-0.45f,0.3f,-2.25f);
    glVertex3f(
-0.45f,0.3f,-2.25f);
    glVertex3f(
-0.05f,0.3f,-0.75f);
    glVertex3f(
-0.05f,0.3f,-2.25f);
    
//Draw the Right Middle Desk Thickness
    glVertex3f(-0.45f,0.25f,-0.75f);
    glVertex3f(
-0.05f,0.25f,-0.75f);
    glVertex3f(
-0.45f,0.25f,-2.25f);
    glVertex3f(
-0.45f,0.25f,-2.25f);
    glVertex3f(
-0.05f,0.25f,-0.75f);
    glVertex3f(
-0.05f,0.25f,-2.25f);
    
//Draw the Right Middle Desk Front
    glNormal3f(-1.0f,0.0f,0.0f);
    glColor3f(
0.9f,0.9f,0.8f);
    glVertex3f(
-0.45f,0.25f,-0.75f);
    glVertex3f(
-0.45f,0.3f,-0.75f);
    glVertex3f(
-0.45f,0.25f,-2.25f);
    glVertex3f(
-0.45f,0.25f,-2.25f);
    glVertex3f(
-0.45f,0.3f,-0.75f);
    glVertex3f(
-0.45f,0.3f,-2.25f);
    
//Draw the Left Middle Desk 
    glNormal3f(0.0f,1.0f,0.0f);
    glColor3f(
0.7f,0.6f,0.55f);
    glVertex3f(
-5.45f,0.3f,-1.15f);
    glVertex3f(
-5.05f,0.3f,-1.15f);
    glVertex3f(
-5.45f,0.3f,-2.25f);
    glVertex3f(
-5.45f,0.3f,-2.25f);
    glVertex3f(
-5.05f,0.3f,-1.15f);
    glVertex3f(
-5.05f,0.3f,-2.25f);
    
//Draw the Left Middle Desk Thickness
    glVertex3f(-5.45f,0.25f,-1.15f);
    glVertex3f(
-5.05f,0.25f,-1.15f);
    glVertex3f(
-5.45f,0.25f,-2.25f);
    glVertex3f(
-5.45f,0.25f,-2.25f);
    glVertex3f(
-5.05f,0.25f,-1.15f);
    glVertex3f(
-5.05f,0.25f,-2.25f);
    
//Draw the Left Middle Desk Front Portion
    glNormal3f(1.0f,0.0f,0.0f);
    glColor3f(
0.9f,0.9f,0.8f);
    glVertex3f(
-5.05f,0.25f,-1.15f);
    glVertex3f(
-5.05f,0.3f,-2.25f);
    glVertex3f(
-5.05f,0.3f,-1.15f);
    glVertex3f(
-5.05f,0.25f,-1.15f);
    glVertex3f(
-5.05f,0.25f,-2.25f);
    glVertex3f(
-5.05f,0.3f,-2.25f);
    
//Draw the Back Wall Desk
    glNormal3f(0.0f,1.0f,0.0f);
    glColor3f(
0.7f,0.6f,0.55f);
    glVertex3f(
-5.45f,0.3f,-0.05f);
    glVertex3f(
-0.75f,0.3f,-0.05f);
    glVertex3f(
-5.45f,0.3f,-0.45f);
    glVertex3f(
-5.45f,0.3f,-0.45f);
    glVertex3f(
-0.75f,0.3f,-0.05f);
    glVertex3f(
-0.75f,0.3f,-0.45f);
    
//Draw the Back Wall Desk Thickness
    glVertex3f(-5.45f,0.25f,-0.05f);
    glVertex3f(
-0.75f,0.25f,-0.05f);
    glVertex3f(
-5.45f,0.25f,-0.45f);
    glVertex3f(
-5.45f,0.25f,-0.45f);
    glVertex3f(
-0.75f,0.25f,-0.05f);
    glVertex3f(
-0.75f,0.25f,-0.45f);
    
//Draw the Back Wall Desk Front Thickness
    glNormal3f(0.0f,0.0f,-1.0f);
    glColor3f(
0.9f,0.9f,0.8f);
    glVertex3f(
-0.75f,0.25f,-0.45f);
    glVertex3f(
-5.45f,0.25f,-0.45f);
    glVertex3f(
-5.45f,0.3f,-0.45f);
    glVertex3f(
-0.75f,0.25f,-0.45f);
    glVertex3f(
-5.45f,0.3f,-0.45f);
    glVertex3f(
-0.75f,0.3f,-0.45f);
    glEnd();
    
//Desk Front and Side Edges
    glDisable(GL_LIGHTING);
    glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);
    glPolygonOffset(
1.0f,-3.0f);
    glEnable(GL_POLYGON_OFFSET_LINE);
    glEnable(GL_POLYGON_SMOOTH);
    
//Front Desk Front
    glBegin(GL_POLYGON);
    glNormal3f(
0.0f,0.0f,1.0f);
    glColor3f(
0.0f,0.0f,0.0f);
    glVertex3f(
-0.75f,0.25f,-2.55f);
    glVertex3f(
-0.75f,0.3f,-2.55f);
    glVertex3f(
-3.5f,0.3f,-2.55f);
    glVertex3f(
-3.5f,0.25f,-2.55);
    glEnd();
    
//Front Desk Side
    glBegin(GL_POLYGON);
    glNormal3f(
-1.0f,0.0f,0.0f);
    glVertex3f(
-3.5f,0.25f,-2.55f);
    glVertex3f(
-3.5f,0.3f,-2.55f);
    glVertex3f(
-3.5f,0.3f,-2.95f);
    glVertex3f(
-3.5f,0.25f,-2.95f);
    glEnd();
    
//Right Desk Front
    glBegin(GL_POLYGON);
    glNormal3f(
-1.0f,0.0f,0.0f);
    glVertex3f(
-0.45f,0.25f,-0.75f);
    glVertex3f(
-0.45f,0.3f,-0.75f);
    glVertex3f(
-0.45f,0.3f,-2.25f);
    glVertex3f(
-0.45f,0.25f,-2.25f);
    glEnd();
    
//Draw the Front Short Desk Front Thickness
    glBegin(GL_POLYGON);
    glNormal3f(
0.0f,0.0f,1.0f);
    glVertex3f(
-4.0f,0.25f,-2.55f);
    glVertex3f(
-4.0f,0.3f,-2.55f);
    glVertex3f(
-4.75f,0.3f,-2.55f);
    glVertex3f(
-4.75f,0.25f,-2.55f);
    glEnd();
    
//Draw the Front Short Desk Side Thickness
    glBegin(GL_POLYGON);
    glNormal3f(
1.0f,0.0f,0.0f);
    glVertex3f(
-4.0f,0.25f,-2.95f);
    glVertex3f(
-4.0f,0.3f,-2.95f);
    glVertex3f(
-4.0f,0.3f,-2.55f);
    glVertex3f(
-4.0f,0.25f,-2.55f);
    glEnd();
    
//Draw the Left Middle Desk Front Portion
    glBegin(GL_POLYGON);
    glNormal3f(
1.0f,0.0f,0.0f);
    glVertex3f(
-5.05f,0.25f,-2.25f);
    glVertex3f(
-5.05f,0.3f,-2.25f);
    glVertex3f(
-5.05f,0.3f,-1.15f);
    glVertex3f(
-5.05f,0.25f,-1.15f);
    glEnd();
    
//Draw the back
    glBegin(GL_POLYGON);
    glNormal3f(
0.0f,0.0f,-1.0f);
    glVertex3f(
-0.75f,0.25f,-0.45f);
    glVertex3f(
-5.45f,0.25f,-0.45f);
    glVertex3f(
-5.45f,0.3f,-0.45f);
    glVertex3f(
-0.75f,0.3f,-0.45f);
    glEnd();
    glDisable(GL_POLYGON_OFFSET_LINE);
    glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);
    glEnable(GL_LIGHTING);
    glDisable(GL_POLYGON_SMOOTH);
    
//Computer Tables
    
//Draw the Back Computer Table
    DrawPentagonTable();
    
//Draw the Front Right Computer Table
    glPushMatrix();
    glTranslatef(
0.0f,0.0f,-3.00f);    
    glRotatef(
90.0f,0.0f,1.0f,0.0f);    
    DrawPentagonTable();
    glPopMatrix();
    
//Draw the Front Left Computer Table
    glPushMatrix();
    glTranslatef(
-5.5,0.0f,-3.0f);
    glRotatef(
180.0f,0.0f,1.0f,0.0f);    
    DrawPentagonTable();
    glPopMatrix();
}
void CCY457OpenGLView::DrawComputers()
{
    
//Computers    
    
//Draw the Back Left Corner Computer
    
//Set Color to Light Grey
    glColor3f(0.35,0.35f,0.35f);
    glPushMatrix();
    glTranslatef(
-0.5f,0.42f,-0.4f);
    glRotatef(
-90.0f,1.0f,0.0f,0.0f);
    glRotatef(
-145.0f,0.0f,0.0f,1.0f);
    glCallList(m_ComputerList);
    glPopMatrix();
    glPushMatrix();
    glTranslatef(
-2.0f,0.42f,-0.25f);
    glRotatef(
-90.0f,1.0f,0.0f,0.0f);
    glRotatef(
180.0f,0.0f,0.0f,1.0f);
    glCallList(m_ComputerList);
    glPopMatrix();
    glPushMatrix();
    glTranslatef(
-3.5f,0.42f,-0.25f);
    glRotatef(
-90.0f,1.0f,0.0f,0.0f);
    glRotatef(
180.0f,0.0f,0.0f,1.0f);
    glCallList(m_ComputerList);
    glPopMatrix();
    
//Front Left Computer 1
    glPushMatrix();
    glTranslatef(
-0.5f,0.42f,-2.6f);
    glRotatef(
-90.0f,1.0f,0.0f,0.0f);
    glRotatef(
-45.0f,0.0f,0.0f,1.0f);
    glCallList(m_ComputerList);
    glPopMatrix();
    
//Front Left Computer 2
    glPushMatrix();
    glTranslatef(
-2.0f,0.42f,-2.75f);
    glRotatef(
-90.0f,1.0f,0.0f,0.0f);
    glCallList(m_ComputerList);
    glPopMatrix();
    
//Front Right
    glPushMatrix();
    glTranslatef(
-5.1f,0.42f,-2.6);
    glRotatef(
-90.0f,1.0f,0.0f,0.0f);
    glRotatef(
45.0f,0.0f,0.0f,1.0f);
    glCallList(m_ComputerList);
    glPopMatrix();
}
void CCY457OpenGLView::DrawChairs()
{
    glColor3f(
0.28f,0.21f,0.0f);
    
//Back Left Chair
    glPushMatrix();
    glTranslatef(
-0.7f0.2f-0.7f);
    glRotatef(
-90.0f,1.0f,0.0f,0.0f);
    glRotatef(
10.0f,0.0f,0.0f,1.0f);                                
    glCallList(m_ChairList);
    glPopMatrix();
    
//Back Right 1
    glPushMatrix();
    glTranslatef(
-2.0f0.2f-0.7f);
    glRotatef(
-90.0f,1.0f,0.0f,0.0f);
    glRotatef(
-30.0f,0.0f,0.0f,1.0f);
    glCallList(m_ChairList);
    glPopMatrix();
    
//Back Right 2
    glPushMatrix();
    glTranslatef(
-3.5f0.2f-0.7f);
    glRotatef(
-90.0f,1.0f,0.0f,0.0f);
    glRotatef(
-30.0f,0.0f,0.0f,1.0f);
    glCallList(m_ChairList);
    glPopMatrix();
    
//Front Left 1
    glPushMatrix();
    glTranslatef(
-0.7f0.2f-2.3f);
    glRotatef(
-90.0f,1.0f,0.0f,0.0f);
    glRotatef(
110.0f,0.0f,0.0f,1.0f);
    glCallList(m_ChairList);
    glPopMatrix();
    
//Front Left 2
    glPushMatrix();
    glTranslatef(
-2.0f0.2f-2.3f);
    glRotatef(
-90.0f,1.0f,0.0f,0.0f);
    glRotatef(
150.0f,0.0f,0.0f,1.0f);
    glCallList(m_ChairList);    
    glPopMatrix();
    
//Front Right 
    glPushMatrix();
    glTranslatef(
-4.8f0.2f-2.3f);
    glRotatef(
-90.0f,1.0f,0.0f,0.0f);
    glRotatef(
-170.0f,0.0f,0.0f,1.0f);
    glCallList(m_ChairList);
    glPopMatrix();
}
void CCY457OpenGLView::DrawBlinds()
{
    glColor3f(
0.97f,0.84f,0.72f);
    
//Draw the Blinds Object 1
    glPushMatrix();
    glTranslatef(
-0.8f,0.7f,-0.1f);
    glRotatef(
-90.0f,1.0f,0.0f,0.0f);
    glCallList(m_BlindsList);
    glPopMatrix();
    
//Draw the Blinds Object 2
    glPushMatrix();
    glTranslatef(
-1.8f,0.7f,-0.1f);
    glRotatef(
-90.0f,1.0f,0.0f,0.0f);
    glCallList(m_BlindsList);
    glPopMatrix();
    
//Draw the Blinds Object 2
    glPushMatrix();
    glTranslatef(
-3.8f,0.7f,-0.1f);
    glRotatef(
-90.0f,1.0f,0.0f,0.0f);
    glCallList(m_BlindsList);
    glPopMatrix();
    
//Draw the Blinds Object 2
    glPushMatrix();
    glTranslatef(
-4.8f,0.7f,-0.1f);
    glRotatef(
-90.0f,1.0f,0.0f,0.0f);
    glCallList(m_BlindsList);
    glPopMatrix();
}
void CCY457OpenGLView::DrawPhones()
{
    
//Draw the phones
    glColor3f(0.49f,0.35,0.25f);
    glPushMatrix();
    glTranslatef(
-0.25f,0.35f,-1.5f);
    glRotatef(
-90.0f,1.0f,0.0f,0.0f);
    glRotatef(
-90.0f,0.0f,0.0f,1.0f);
    glCallList(m_PhoneList);
    glPopMatrix();
}
void CCY457OpenGLView::DrawFloorAndCeiling ()
{
    
//Draw Floor
    glEnable(GL_TEXTURE_2D);
    glCullFace(GL_BACK);
    glBindTexture(GL_TEXTURE_2D, m_Texture[
1]);
    
//Draw Ceiling
    glBegin(GL_POLYGON);
    glNormal3f(
0.0f,-1.0f,0.0f);
    glColor3f(
1.0f,1.0f,1.0f);
    glTexCoord2f(
0.0f,5.0f);
    glVertex3f(
0.0f,1.0f,-3.0f);
    glTexCoord2f(
0.0f,0.0f);
    glVertex3f(
0.0f,1.0f,0.0f);
    glTexCoord2f(
5.0f,0.0f);
    glVertex3f(
-5.5f,1.0f,0.0f);
    glTexCoord2f(
5.0f,5.0f);
    glVertex3f(
-5.5f,1.0f,-3.0f);
    glEnd();
    glBindTexture(GL_TEXTURE_2D, m_Texture[
0]);
    glBegin(GL_POLYGON);
    glNormal3f(
0.0f,1.0f,0.0f);
    glColor3f(
1.0f,1.0f,1.0f);
    glTexCoord2f(
0.0f,0.0f);
    glVertex3f(
0.0f,0.0f,-3.0f);
    glTexCoord2f(
20.0f,0.0f);
    glVertex3f(
-5.5f,0.0f,-3.0f);
    glTexCoord2f(
20.0f,20.0f);
    glVertex3f(
-5.5f,0.0f,0.0f);
    glTexCoord2f(
0.0f,20.0f);
    glVertex3f(
0.0f,0.0f,0.0f);
    glEnd();
    glDisable(GL_TEXTURE_2D);
}

 

作者:洞庭散人

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

本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
原文链接:http://www.cnblogs.com/phinecos/archive/2008/11/07/1328998.html

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理