//MAKEFILE # To use this Makefile, just type make. That's it. CC = gcc LDLIBS = -L /usr/X11R6/lib -lGL -lGLU -lglut -lXmu -lX11 -lXi -lm INCLUDE = -I /usr/X11R6/include -I /usr/X11R6/include/GL executable: $(CC) -g $(INCLUDE) -o $I town $I town.c $(LDLIBS) -Wall ------------------------------------------------------------------------- //town.h /*type definitions*/ typedef GLfloat xyPoint[2]; typedef int xyPointInt[2]; typedef GLdouble xyzPoint[3]; typedef GLfloat color3f[3]; typedef GLfloat color4f[4]; typedef GLfloat matrix[16]; ------------------------------------------------------------------------- //town.c #include #include #include #include #include #include #include #include "town.h" #define AXIS 0 #define HOUSE 0 #define PYRAMID 0 #define ORTHO 0 #define PROJECT 1 #define VIEW_TOP 0 #define VIEW_FRONT 1 #define VIEW_LEFT 2 #define VIEW_RIGHT 3 #define VIEW_BACK 4 #define MENU_TV 0 #define MENU_FV 1 #define MENU_LV 2 #define MENU_RV 3 #define MENU_BV 4 void setWindowVals(xyPoint size, xyPoint pos, char * name); void initSystem(color4f winColor, xyPoint startDisp, xyPoint endDisp, float ptSize); void keyboardReader(unsigned char key, int x, int y); void display(); void menu_function(int ID); void defineMenu(); void drawHouseOne(float h1, float h2, float h3, float r1, float r2, float r3, float centerx, float centerz); void drawHouseTwo(float h1, float h2, float h3, float r1, float r2, float r3, float centerx, float centerz); void drawHouseThree(float h1, float h2, float h3, float r1, float r2, float r3, float centerx, float centerz); int viewType = ORTHO; int orthoSelection = VIEW_TOP; int selected = AXIS; int showAll = 0; int xPos = 0; int zRot = 0; int zPos = 0; matrix * coordinateSystem; matrix system_one = {1.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0}; matrix system_two = {1.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0}; matrix system_zero = {1.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0}; int wallsize = 40; /* int main(int argc, char **argv) * This function initializes the board, glut, the window, the GL system * the menu, the gl matrices, and then calls the glutMainLoop*/ int main(int argc, char **argv){ xyPoint startDisplay = {0.0,0.0};//location to start the display at xyPoint endDisplay = {500.0,500.0};//location to finish the display at color4f winBGColor = {0.6, 0.6, 0.6, 1.0};//window background color xyPoint windowSize = {500, 500};//size of the window xyPoint windowLoc = {0, 0};//location on screen of the window float ptsize = 0.5;//the point size char * windowName = "Town";//name of the window /*initiate interaction with the local window system*/ glutInit(&argc, argv); /*initialize the window variables*/ setWindowVals(windowSize, windowLoc, windowName); /*initialize the system*/ initSystem(winBGColor, startDisplay, endDisplay, ptsize); defineMenu(); glutMainLoop(); } /* setWindowVals(xyPoint size, xyPoint pos, char * name) * Set the variables for the window*/ void setWindowVals(xyPoint size, xyPoint pos, char * name){ /*set number and type of buffers*/ glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); /*set the window size*/ glutInitWindowSize(size[0], size[1]); /*position the window*/ glutInitWindowPosition(pos[0], pos[1]); /*actually create the window*/ glutCreateWindow(name); } /* initSystem(color4f winColor, color3f drawColor, xyPoint startDisp, xyPoint endDisp, float ptSize) * This function initializes all of display variables*/ void initSystem(color4f winColor, xyPoint startDisp, xyPoint endDisp, float ptSize){ /*set the background color*/ glClearColor(winColor[0], winColor[1], winColor[2], winColor[3]); /*clear the window*/ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //display(); glMatrixMode(GL_MODELVIEW); /*set the point size*/ glPointSize(ptSize); /*set the callback functions*/ glutDisplayFunc(display); glutKeyboardFunc(keyboardReader); } /* void keyboardReader(unsigned char key, int x, int y) * this function handles all keyboard interaction*/ void keyboardReader(unsigned char key, int x, int y){ /*start the walkthrough*/ if ((key == 'G') || (key == 'g')){ zPos = 0; xPos = 0; zRot = 0; viewType = PROJECT; display(); } /*turn left*/ if ((key == 'L') || (key == 'l')){ zRot = zRot + 3; display(); } /*turn right*/ if ((key == 'R') || (key == 'r')){ zRot++; display(); } /*move camera back*/ if ((key == 'B') || (key == 'b')){ if(fmod(zRot, 4) == 0){ xPos++; }else if(fmod(zRot, 4) == 1){ zPos++; }else if(fmod(zRot, 4) == 2){ xPos--; }else if(fmod(zRot, 4) == 3){ zPos--; } display(); } /*move camera forward*/ if ((key == 'F') || (key == 'f')){ if(fmod(zRot, 4) == 0){ xPos--; }else if(fmod(zRot, 4) == 1){ zPos--; }else if(fmod(zRot, 4) == 2){ xPos++; }else if(fmod(zRot, 4) == 3){ zPos++; } display(); } /*quit*/ if ((key == 'Q') || (key == 'q')){ printf("Quit\n"); exit(1); } } /* void display() * This function handles the drawing of the objects and coordinate lines*/ void display(){ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_PROJECTION); /*set the viewing area*/ if(viewType == ORTHO){ glDisable(GL_DEPTH_TEST); glLoadIdentity(); if(orthoSelection == VIEW_BACK || orthoSelection == VIEW_LEFT){ glOrtho(600, -900, -600, 900, 600, -900); } else{ glOrtho(-600, 900, -600, 900, -600, 900); } }else{ glEnable(GL_DEPTH_TEST); glLoadIdentity(); /*set the portion of the world to display*/ gluPerspective(90, 1, 0.1, 3000); } glMatrixMode(GL_MODELVIEW); glLoadIdentity(); /*set the camera position for the orthogonal view*/ if(viewType == ORTHO){ switch (orthoSelection){ case VIEW_TOP : { printf("Top View\n"); gluLookAt(0.0, 100.0, 0.0, 0.0, 0.0, 0.0, 0, 0, -1); break; } case VIEW_FRONT : { printf("Front View\n"); gluLookAt(0.0, 20.0, 100.0, 0.0, 0.0, 0.0, 0, 1, 0); break; } case VIEW_RIGHT : { printf("Right View\n"); gluLookAt(100.0, 20.0, 0.0, 0.0, 0.0, 0.0, 0, 1, 0); break; } case VIEW_LEFT : { printf("Left View\n"); gluLookAt(-100.0, 20.0, 0.0, 0.0, 0.0, 0.0, 0, 1, 0); break; } case VIEW_BACK : { printf("Back View\n"); gluLookAt(0.0, 20.0, -100.0, 0.0, 0.0, 0.0, 0, 1, 0); break; } } } else{ /*set the camera position*/ gluLookAt(0,wallsize/2,0,wallsize,0,0,0,1,0); glRotatef(90 * zRot, 0, 1, 0); glTranslatef(xPos, 0, zPos); } /*draw the grass*/ glPushMatrix(); glColor3f(0.0,1.0,0.0); glBegin(GL_POLYGON); glVertex3f(-300.0, -0.9, -600.0); glVertex3f(600.0, -0.9, -600.0); glVertex3f(600.0, -0.9, 300.0); glVertex3f(-300.0, -0.9, 300.0); glEnd(); glPopMatrix(); /*draw roads*/ glColor3f(0.0,0.5,0.0); glBegin(GL_POLYGON); glVertex3f(-300.0, 0.0, -20.0); glVertex3f(600.0, 0.0, -20.0); glVertex3f(600.0, 0.0, 20.0); glVertex3f(-300.0, 0.0, 20.0); glEnd(); glColor3f(0.0,0.0,0.5); glBegin(GL_POLYGON); glVertex3f(-300.0, 0.0, -290.0); glVertex3f(600.0, 0.0, -290.0); glVertex3f(600.0, 0.0, -330.0); glVertex3f(-300.0, 0.0, -330.0); glEnd(); glColor3f(0.5,0.0,0.0); glBegin(GL_POLYGON); glVertex3f(-20.0, 0.0, 300.0); glVertex3f(20.0, 0.0, 300.0); glVertex3f(20.0, 0.0, -600.0); glVertex3f(-20.0, 0.0, -600.0); glEnd(); glColor3f(0.0,0.5,0.5); glBegin(GL_POLYGON); glVertex3f(290.0, 0.0, 300.0); glVertex3f(330.0, 0.0, 300.0); glVertex3f(330.0, 0.0, -600.0); glVertex3f(290.0, 0.0, -600.0); glEnd(); glColor3f(0.5, 0.0,0.5); glBegin(GL_POLYGON); glVertex3f(580, 0, 300); glVertex3f(600, 0, 300); glVertex3f(600, 0, -600); glVertex3f(580, 0, -600); glEnd(); glColor3f(0.5, 0.5,0.0); glBegin(GL_POLYGON); glVertex3f(-280, 0, 300); glVertex3f(-300, 0, 300); glVertex3f(-300, 0, -600); glVertex3f(-280, 0, -600); glEnd(); glColor3f(0.5, 0.5,0.5); glBegin(GL_POLYGON); glVertex3f(-300, 0, 280); glVertex3f(600, 0, 280); glVertex3f(600, 0, 300); glVertex3f(-300, 0, 300); glEnd(); glColor3f(0.0, 0.0,0.0); glBegin(GL_POLYGON); glVertex3f(-300, 0, -580); glVertex3f(600, 0, -580); glVertex3f(600, 0, -600); glVertex3f(-300, 0, -600); glEnd(); /*END draw roads*/ /*block one*/ drawHouseOne(0.3, 0.6, 1.0, 1.0, 0.3,0.2, 80, 80); drawHouseOne(0.4, 0.4, 1.0, 1.0, 0.4,0.3, 160, 80); drawHouseOne(0.6, 0.8, 1.0, 1.0, 0.5,0.6, 240, 80); drawHouseOne(0.5, 0.4, 1.0, 1.0, 0.6,0.4, 80, 160); drawHouseOne(0.4, 0.8, 1.0, 1.0, 0.7,0.6, 160, 160); drawHouseOne(0.3, 0.7, 1.0, 1.0, 0.8,0.5, 240, 160); drawHouseOne(0.7, 0.5, 1.0, 1.0, 0.3,0.4, 80, 240); drawHouseOne(0.6, 0.2, 1.0, 1.0, 0.7,0.3, 160, 240); drawHouseOne(0.3, 0.3, 1.0, 1.0, 0.4,0.3, 240, 240); /*block two*/ drawHouseThree(1.0, 0.2, 1.0, 1.0, 0.0,0.0, 50, -100); drawHouseThree(0.0, 0.3, 1.0, 1.0, 0.0,0.0, 130, -100); drawHouseThree(0.0, 0.4, 1.0, 1.0, 0.0,0.0, 210, -100); drawHouseThree(1.0, 0.5, 1.0, 1.0, 0.0,0.0, 50, -180); drawHouseThree(0.0, 0.6, 1.0, 1.0, 0.0,0.0, 130, -180); drawHouseThree(0.0, 0.7, 1.0, 1.0, 0.0,0.0, 210, -180); drawHouseThree(1.0, 0.4, 1.0, 1.0, 0.0,0.0, 50, -260); drawHouseThree(0.0, 0.2, 1.0, 1.0, 0.0,0.0, 130, -260); drawHouseThree(0.0, 0.3, 1.0, 1.0, 0.0,0.0, 210, -260); /*block three*/ drawHouseTwo(1.0, 0.0, 1.0, 1.0, 0.2,0.0, 50, -400); drawHouseTwo(0.0, 0.0, 1.0, 1.0, 0.3,0.0, 130, -400); drawHouseTwo(0.0, 0.0, 1.0, 1.0, 0.4,0.0, 210, -400); drawHouseTwo(1.0, 0.0, 1.0, 1.0, 0.5,0.0, 50, -480); drawHouseTwo(0.0, 0.0, 1.0, 1.0, 0.6,0.0, 130, -480); drawHouseTwo(0.0, 0.0, 1.0, 1.0, 0.2,0.0, 210, -480); drawHouseTwo(1.0, 0.0, 1.0, 1.0, 0.3,0.0, 50, -560); drawHouseTwo(0.0, 0.0, 1.0, 1.0, 0.4,0.0, 130, -560); drawHouseTwo(0.0, 0.0, 1.0, 1.0, 0.5,0.0, 210, -560); /*block four*/ drawHouseTwo(1.0, 0.2, 1.0, 1.0, 0.0,0.0, -100, 50); drawHouseThree(0.0, 0.3, 1.0, 1.0, 0.0,0.0, -180, 50); drawHouseTwo(0.0, 0.2, 1.0, 1.0, 0.0,0.0, -260, 50); drawHouseThree(1.0, 0.2, 1.0, 1.0, 0.0,0.0, -100, 130); drawHouseTwo(0.0, 0.3, 1.0, 1.0, 0.0,0.0, -180, 130); drawHouseTwo(0.0, 0.3, 1.0, 1.0, 0.0,0.0, -260, 130); drawHouseThree(1.0, 0.4, 1.0, 1.0, 0.0,0.0, -100, 210); drawHouseTwo(0.0, 0.5, 1.0, 1.0, 0.0,0.0, -180, 210); drawHouseThree(0.0, 0.4, 1.0, 1.0, 0.0,0.0, -260, 210); /*block five*/ drawHouseThree(1.0, 0.0, 1.0, 1.0, 0.4,0.0, -100, -100); drawHouseOne(0.0, 0.0, 1.0, 1.0, 0.4,0.0, -150, -80); drawHouseOne(0.0, 0.0, 1.0, 1.0, 0.5,0.0, -230, -80); drawHouseTwo(1.0, 0.0, 1.0, 1.0, 0.6,0.0, -100, -180); drawHouseTwo(0.0, 0.0, 1.0, 1.0, 0.7,0.0, -180, -180); drawHouseThree(0.0, 0.0, 1.0, 1.0, 0.8,0.0, -260, -180); drawHouseThree(1.0, 0.0, 1.0, 1.0, 0.8,0.0, -100, -260); drawHouseTwo(0.0, 0.0, 1.0, 1.0, 0.3,0.0, -180, -260); drawHouseThree(0.0, 0.0, 1.0, 1.0, 0.3,0.0, -260, -260); /*block six*/ drawHouseThree(1.0, 0.0, 1.0, 1.0, 0.0,0.3, -100, -400); drawHouseTwo(0.0, 0.0, 1.0, 1.0, 0.0,0.4, -180, -400); drawHouseThree(0.0, 0.0, 1.0, 1.0, 0.0,0.5, -260, -400); drawHouseOne(1.0, 0.0, 1.0, 1.0, 0.0,0.6, -70, -460); drawHouseThree(0.0, 0.0, 1.0, 1.0, 0.0,0.7, -180, -480); drawHouseTwo(0.0, 0.0, 1.0, 1.0, 0.0,0.3, -260, -480); drawHouseTwo(1.0, 0.0, 1.0, 1.0, 0.0,0.4, -100, -560); drawHouseTwo(0.0, 0.0, 1.0, 1.0, 0.0,0.5, -180, -560); drawHouseThree(0.0, 0.0, 1.0, 1.0, 0.0,0.6, -260, -560); /*block seven*/ drawHouseOne(1.0, 0.0, 1.0, 1.0, 0.0,0.0, 380, 70); drawHouseTwo(0.3, 0.0, 1.0, 1.0, 0.0,0.0, 430, 50); drawHouseThree(0.5, 0.0, 1.0, 1.0, 0.0,0.0, 510, 50); drawHouseOne(1.0, 0.0, 1.0, 1.0, 0.0,0.0, 380, 150); drawHouseTwo(0.4, 0.0, 1.0, 1.0, 0.0,0.0, 430, 130); drawHouseThree(0.2, 0.0, 1.0, 1.0, 0.0,0.0, 510, 130); drawHouseOne(1.0, 0.0, 1.0, 1.0, 0.0,0.0, 380, 230); drawHouseTwo(0.3, 0.0, 1.0, 1.0, 0.0,0.0, 430, 210); drawHouseThree(0.4, 0.0, 1.0, 1.0, 0.0,0.0, 510, 210); /*block eight*/ drawHouseThree(1.0, 0.0, 1.0, 1.0, 0.0,0.3, 350, -100); drawHouseThree(0.0, 0.0, 1.0, 1.0, 0.0,0.2, 430, -100); drawHouseThree(0.0, 0.0, 1.0, 1.0, 0.0,0.3, 510, -100); drawHouseThree(1.0, 0.0, 1.0, 1.0, 0.0,0.8, 350, -180); drawHouseTwo(0.0, 0.0, 1.0, 1.0, 0.0,0.8, 430, -180); drawHouseTwo(0.0, 0.0, 1.0, 1.0, 0.0,0.7, 510, -180); drawHouseTwo(1.0, 0.0, 1.0, 1.0, 0.0,0.5, 350, -260); drawHouseTwo(0.0, 0.0, 1.0, 1.0, 0.0,0.4, 430, -260); drawHouseTwo(0.0, 0.0, 1.0, 1.0, 0.0,0.3, 510, -260); /*block nine*/ drawHouseThree(1.3, 0.0, 1.0, 1.0, 0.0,0.0, 350, -400); drawHouseOne(0.4, 0.0, 1.0, 1.0, 0.0,0.0, 460, -380); drawHouseThree(0.0, 0.5, 1.0, 1.0, 0.0,0.0, 510, -400); drawHouseOne(1.0, 0.6, 1.0, 1.0, 0.0,0.0, 380, -460); drawHouseThree(0.0, 0.7, 1.0, 1.0, 0.0,0.0, 430, -480); drawHouseOne(0.0, 0.8, 1.0, 1.0, 0.0,0.0, 540, -460); drawHouseThree(1.0, 0.9, 1.0, 1.0, 0.0,0.0, 350, -560); drawHouseOne(0.0, 0.5, 1.0, 1.0, 0.0,0.0, 460, -540); drawHouseThree(0.0, 0.0, 1.0, 1.0, 0.0,0.0, 510, -560); /*draw the image*/ glutSwapBuffers(); } /*Function defineMenu() * * This function defines the main menu for the program and attaches * * values to each of the choices*/ void defineMenu(){ int sub; sub = glutCreateMenu(menu_function); glutAddMenuEntry("Top View", MENU_TV); glutAddMenuEntry("Front View", MENU_FV); glutAddMenuEntry("Left View", MENU_LV); glutAddMenuEntry("Right View", MENU_RV); glutAddMenuEntry("Back View", MENU_BV); glutAttachMenu(GLUT_LEFT_BUTTON); } /* Function menu_function(int ID) * * This is the callback function for the menu. It handles all menu * * interaction*/ void menu_function(int ID){ switch(ID){ case MENU_TV: { orthoSelection = VIEW_TOP; viewType = ORTHO; display(); break; } case MENU_FV: { orthoSelection = VIEW_FRONT; viewType = ORTHO; display(); break; } case MENU_LV: { orthoSelection = VIEW_LEFT; viewType = ORTHO; display(); break; } case MENU_RV: { orthoSelection = VIEW_RIGHT; viewType = ORTHO; display(); break; } case MENU_BV: { orthoSelection = VIEW_BACK; viewType = ORTHO; display(); break; } } } /*draws the first house type*/ /* Function drawHouseOne(float h1, h2, h3, r1, r2, r3, centerx, centerz){ * This function draws the first house type*/ void drawHouseOne(float h1, float h2, float h3, float r1, float r2, float r3, float centerx, float centerz){ glPushMatrix(); /*translate to appropriate location*/ glTranslatef(centerx, 0, centerz); /*set the house color*/ glColor3f(h1, h2, h3); /*draw the house*/ glRotatef(-90, 1, 0, 0); glTranslatef(0.0, 0.0, wallsize/2); glutSolidCube(wallsize); /*set the roof color*/ glColor3f(r1, r2, r3); /*draw the roof*/ glTranslatef(0.0, 0.0, wallsize/2); glRotatef(45, 0, 0, 1); glutSolidCone(wallsize/sqrt(2), wallsize/sqrt(2), 4.0, 3.0); /*un-translate the system*/ glTranslatef(-centerx, 0, -centerz); glPopMatrix(); } /* Function void drawHouseTwo(float h1, h2, h3, r1, r2, r3, centerx, centerz) * This function draws the second house type*/ void drawHouseTwo(float h1, float h2, float h3, float r1, float r2, float r3, float centerx, float centerz){ glPushMatrix(); /*set the house at the right location*/ glTranslatef(centerx, 0, centerz); /*set the wall color*/ glColor3f(h1, h2, h3); /*put up the walls*/ glBegin(GL_POLYGON); glVertex3f(0.0, 0.0, 0.0); glVertex3f(wallsize*1.5, 0.0, 0.0); glVertex3f(wallsize*1.5, wallsize, 0.0); glVertex3f(0.0, wallsize, 0.0); glEnd(); glBegin(GL_POLYGON); glVertex3f(0.0, 0.0, wallsize); glVertex3f(wallsize*1.5, 0.0, wallsize); glVertex3f(wallsize*1.5, wallsize, wallsize); glVertex3f(0.0, wallsize, wallsize); glEnd(); glBegin(GL_POLYGON); glVertex3f(wallsize*1.5, 0.0, 0.0); glVertex3f(wallsize*1.5, wallsize, 0.0); glVertex3f(wallsize*1.5, wallsize, wallsize); glVertex3f(wallsize*1.5, 0.0, wallsize); glEnd(); glBegin(GL_POLYGON); glVertex3f(0.0, 0.0, 0.0); glVertex3f(0.0, 0.0, wallsize); glVertex3f(0.0, wallsize, wallsize); glVertex3f(0.0, wallsize, 0.0); glEnd(); glBegin(GL_POLYGON); glVertex3f(0.0, 0.0, 0.0); glVertex3f(0.0, 0.0, wallsize); glVertex3f(wallsize*1.5, 0.0, wallsize); glVertex3f(wallsize*1.5, 0.0, 0.0); glEnd(); /*set the roof color*/ glColor3f(r1, r2, r3); /*put up the roof*/ glBegin(GL_POLYGON); glVertex3f(0.0, wallsize, 0.0); glVertex3f(0.0, wallsize, wallsize); glVertex3f(wallsize*1.5/2, wallsize*1.5, wallsize/2); glEnd(); glBegin(GL_POLYGON); glVertex3f(0.0, wallsize, wallsize); glVertex3f(wallsize*1.5, wallsize, wallsize); glVertex3f(wallsize*1.5/2, wallsize*1.5, wallsize/2); glEnd(); glBegin(GL_POLYGON); glVertex3f(wallsize*1.5, wallsize, 0.0); glVertex3f(wallsize*1.5, wallsize, wallsize); glVertex3f(wallsize*1.5/2, wallsize*1.5, wallsize/2); glEnd(); glBegin(GL_POLYGON); glVertex3f(0.0, wallsize, 0.0); glVertex3f(wallsize*1.5, wallsize, 0.0); glVertex3f(wallsize*1.5/2, wallsize*1.5, wallsize/2); glEnd(); /*un-translate the matrix*/ glTranslatef(-centerx, 0, -centerz); glPopMatrix(); } /* Function void drawHouseThree(float h1, h2, h3, r1, r2, r3, centerx, centerz) * This function draws the third house type*/ void drawHouseThree(float h1, float h2, float h3, float r1, float r2, float r3, float centerx, float centerz){ glPushMatrix(); /*set the house in the right place*/ glTranslatef(centerx, 0, centerz); /*set the wall color*/ glColor3f(h1, h2, h3); /*put up the walls*/ glBegin(GL_POLYGON); glVertex3f(0.0, 0.0, 0.0); glVertex3f(wallsize*1.5, 0.0, 0.0); glVertex3f(wallsize*1.5, wallsize, 0.0); glVertex3f(0.0, wallsize, 0.0); glEnd(); glBegin(GL_POLYGON); glVertex3f(wallsize*1.5, 0.0, 0.0); glVertex3f(wallsize*1.5, wallsize, 0.0); glVertex3f(wallsize*1.5, wallsize, wallsize*.75); glVertex3f(wallsize*1.5, 0.0, wallsize*.75); glEnd(); glBegin(GL_POLYGON); glVertex3f(wallsize*1.5, wallsize, wallsize*.75); glVertex3f(wallsize*1.5, 0.0, wallsize*.75); glVertex3f(wallsize*.75, 0.0, wallsize*.75); glVertex3f(wallsize*.75, wallsize, wallsize*.75); glEnd(); glBegin(GL_POLYGON); glVertex3f(wallsize*.75, 0.0, wallsize*.75); glVertex3f(wallsize*.75, wallsize, wallsize*.75); glVertex3f(wallsize*.75, wallsize, wallsize*1.5); glVertex3f(wallsize*.75, 0.0, wallsize*1.5); glEnd(); glBegin(GL_POLYGON); glVertex3f(0.0, 0.0, wallsize*1.5); glVertex3f(0.0, wallsize, wallsize*1.5); glVertex3f(wallsize*.75, wallsize, wallsize*1.5); glVertex3f(wallsize*.75, 0.0, wallsize*1.5); glEnd(); glBegin(GL_POLYGON); glVertex3f(0.0, 0.0, 0.0); glVertex3f(0.0, wallsize, 0.0); glVertex3f(0.0, wallsize, wallsize*1.5); glVertex3f(0.0, 0.0, wallsize*1.5); glEnd(); /*set the roof color*/ glColor3f(r1, r2, r3); /*put up the roof*/ glBegin(GL_POLYGON); glVertex3f(wallsize*1.5, wallsize, 0.0); glVertex3f(wallsize*1.5, wallsize, wallsize*.75); glVertex3f(wallsize*(0.75 + .75/2), wallsize*1.5, wallsize*.75/2); glEnd(); glBegin(GL_POLYGON); glVertex3f(0.0, wallsize, 0.0); glVertex3f(wallsize*1.5, wallsize, 0.0); glVertex3f(wallsize*(0.75 + .75/2), wallsize*1.5, wallsize*.75/2); glVertex3f(wallsize*.75/2, wallsize*1.5, wallsize*.75/2); glEnd(); glBegin(GL_POLYGON); glVertex3f(0.0, wallsize, 0.0); glVertex3f(0.0, wallsize, wallsize*1.5); glVertex3f(wallsize*.75/2, wallsize*1.5, wallsize*(0.75 + .75/2)); glVertex3f(wallsize*.75/2, wallsize*1.5, wallsize*.75/2); glEnd(); glBegin(GL_POLYGON); glVertex3f(0.0, wallsize, wallsize*1.5); glVertex3f(wallsize*.75/2, wallsize*1.5, wallsize*(0.75 + .75/2)); glVertex3f(wallsize*.75, wallsize, wallsize*1.5); glEnd(); glBegin(GL_POLYGON); glVertex3f(wallsize*.75/2, wallsize*1.5, wallsize*(0.75 + .75/2)); glVertex3f(wallsize*.75/2, wallsize*1.5, wallsize*.75/2); glVertex3f(wallsize*.75, wallsize, wallsize*.75); glVertex3f(wallsize*.75, wallsize, wallsize*1.5); glEnd(); glBegin(GL_POLYGON); glVertex3f(wallsize*.75, wallsize, wallsize*.75); glVertex3f(wallsize*.75/2, wallsize*1.5, wallsize*.75/2); glVertex3f(wallsize*(0.75 + .75/2), wallsize*1.5, wallsize*.75/2); glVertex3f(wallsize*1.5, wallsize, wallsize*.75); glEnd(); /*un-translate the matrix*/ glTranslatef(-centerx, 0, -centerz); glPopMatrix(); }