-int moving, startx, starty;\r
-int lightMoving = 0, lightStartX, lightStartY;\r
-\r
-enum {\r
- MISSING, EXTENSION, ONE_DOT_ONE\r
-};\r
-int polygonOffsetVersion;\r
-\r
-static GLdouble bodyWidth = 3.0;\r
-/* *INDENT-OFF* */\r
-static GLfloat body[][2] = { {0, 3}, {1, 1}, {5, 1}, {8, 4}, {10, 4}, {11, 5},\r
- {11, 11.5}, {13, 12}, {13, 13}, {10, 13.5}, {13, 14}, {13, 15}, {11, 16},\r
- {8, 16}, {7, 15}, {7, 13}, {8, 12}, {7, 11}, {6, 6}, {4, 3}, {3, 2},\r
- {1, 2} };\r
-static GLfloat arm[][2] = { {8, 10}, {9, 9}, {10, 9}, {13, 8}, {14, 9}, {16, 9},\r
- {15, 9.5}, {16, 10}, {15, 10}, {15.5, 11}, {14.5, 10}, {14, 11}, {14, 10},\r
- {13, 9}, {11, 11}, {9, 11} };\r
-static GLfloat leg[][2] = { {8, 6}, {8, 4}, {9, 3}, {9, 2}, {8, 1}, {8, 0.5}, {9, 0},\r
- {12, 0}, {10, 1}, {10, 2}, {12, 4}, {11, 6}, {10, 7}, {9, 7} };\r
-static GLfloat eye[][2] = { {8.75, 15}, {9, 14.7}, {9.6, 14.7}, {10.1, 15},\r
- {9.6, 15.25}, {9, 15.25} };\r
-static GLfloat lightPosition[4];\r
-static GLfloat lightColor[] = {0.8, 1.0, 0.8, 1.0}; /* green-tinted */\r
-static GLfloat skinColor[] = {0.1, 1.0, 0.1, 1.0}, eyeColor[] = {1.0, 0.2, 0.2, 1.0};\r
-/* *INDENT-ON* */\r
-\r
-/* Nice floor texture tiling pattern. */\r
-static char *circles[] = {\r
- "....xxxx........",\r
- "..xxxxxxxx......",\r
- ".xxxxxxxxxx.....",\r
- ".xxx....xxx.....",\r
- "xxx......xxx....",\r
- "xxx......xxx....",\r
- "xxx......xxx....",\r
- "xxx......xxx....",\r
- ".xxx....xxx.....",\r
- ".xxxxxxxxxx.....",\r
- "..xxxxxxxx......",\r
- "....xxxx........",\r
- "................",\r
- "................",\r
- "................",\r
- "................",\r
-};\r
-\r
-static void\r
-makeFloorTexture(void)\r
-{\r
- GLubyte floorTexture[16][16][3];\r
- GLubyte *loc;\r
- int s, t;\r
-\r
- /* Setup RGB image for the texture. */\r
- loc = (GLubyte*) floorTexture;\r
- for (t = 0; t < 16; t++) {\r
- for (s = 0; s < 16; s++) {\r
- if (circles[t][s] == 'x') {\r
- /* Nice green. */\r
- loc[0] = 0x1f;\r
- loc[1] = 0x8f;\r
- loc[2] = 0x1f;\r
- } else {\r
- /* Light gray. */\r
- loc[0] = 0xaa;\r
- loc[1] = 0xaa;\r
- loc[2] = 0xaa;\r
- }\r
- loc += 3;\r
- }\r
- }\r
-\r
- glPixelStorei(GL_UNPACK_ALIGNMENT, 1);\r
-\r
- if (useMipmaps) {\r
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,\r
- GL_LINEAR_MIPMAP_LINEAR);\r
- gluBuild2DMipmaps(GL_TEXTURE_2D, 3, 16, 16,\r
- GL_RGB, GL_UNSIGNED_BYTE, floorTexture);\r
- } else {\r
- if (linearFiltering) {\r
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);\r
- } else {\r
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);\r
- }\r
- glTexImage2D(GL_TEXTURE_2D, 0, 3, 16, 16, 0,\r
- GL_RGB, GL_UNSIGNED_BYTE, floorTexture);\r
- }\r
-}\r
-\r
-enum {\r
- X, Y, Z, W\r
-};\r
-enum {\r
- A, B, C, D\r
-};\r
-\r
-/* Create a matrix that will project the desired shadow. */\r
-void\r
-shadowMatrix(GLfloat shadowMat[4][4],\r
- GLfloat groundplane[4],\r
- GLfloat lightpos[4])\r
-{\r
- GLfloat dot;\r
-\r
- /* Find dot product between light position vector and ground plane normal. */\r
- dot = groundplane[X] * lightpos[X] +\r
- groundplane[Y] * lightpos[Y] +\r
- groundplane[Z] * lightpos[Z] +\r
- groundplane[W] * lightpos[W];\r
-\r
- shadowMat[0][0] = dot - lightpos[X] * groundplane[X];\r
- shadowMat[1][0] = 0.f - lightpos[X] * groundplane[Y];\r
- shadowMat[2][0] = 0.f - lightpos[X] * groundplane[Z];\r
- shadowMat[3][0] = 0.f - lightpos[X] * groundplane[W];\r
-\r
- shadowMat[X][1] = 0.f - lightpos[Y] * groundplane[X];\r
- shadowMat[1][1] = dot - lightpos[Y] * groundplane[Y];\r
- shadowMat[2][1] = 0.f - lightpos[Y] * groundplane[Z];\r
- shadowMat[3][1] = 0.f - lightpos[Y] * groundplane[W];\r
-\r
- shadowMat[X][2] = 0.f - lightpos[Z] * groundplane[X];\r
- shadowMat[1][2] = 0.f - lightpos[Z] * groundplane[Y];\r
- shadowMat[2][2] = dot - lightpos[Z] * groundplane[Z];\r
- shadowMat[3][2] = 0.f - lightpos[Z] * groundplane[W];\r
-\r
- shadowMat[X][3] = 0.f - lightpos[W] * groundplane[X];\r
- shadowMat[1][3] = 0.f - lightpos[W] * groundplane[Y];\r
- shadowMat[2][3] = 0.f - lightpos[W] * groundplane[Z];\r
- shadowMat[3][3] = dot - lightpos[W] * groundplane[W];\r
-\r
+/* Near and far parameters */\r
+GLfloat near = -100;\r
+GLfloat far = 100;\r
+\r
+/* Zoom factor for mouse movements */\r
+GLfloat zoomFactor = 1.0;\r
+\r
+/* Recursion level for floor drawing */\r
+int drawFloorRecurse = 5;\r
+\r
+/* Size of floor, from -n to n */\r
+int floorSize = 100;\r
+\r
+/* Light 0 parameters */\r
+GLfloat diffuse0[] = {1.0, 1.0, 1.0, 1.0};\r
+GLfloat ambient0[] = {0.0, 0.0, 0.0, 1.0};\r
+GLfloat specular0[] = {1.0, 1.0, 1.0, 1.0};\r
+GLfloat emission0[] = {0.0, 0.0, 0.0, 0.0};\r
+GLfloat light0_pos[] ={1.0, 1.0, 0,0, 1.0};\r
+GLfloat glightmodel[] = {0.2,0.2,0.2,1};\r
+\r
+\r
+/**\r
+ * Prints out error message when file cannot be read\r
+ * @param fileName Name of file that could not be read\r
+ */\r
+void fileErr(char* fileName) {\r
+ printf("Error reading file: %s\n", fileName);\r
+ printf("If not in the CSSE labs, you will need to include the directory containing\n");\r
+ printf("the models on the command line, or put it in the same folder as the exectutable.");\r
+ exit(EXIT_FAILURE);\r
+} \r
+\r
+/**\r
+ * Reads .bmp texture files and converts them to a texture object\r
+ * @param fileName .bmp texture file\r
+ * @return texture object\r
+ */\r
+texture* loadTexture(char *fileName) {\r
+ texture* t = malloc(sizeof (texture));\r
+ BITMAPINFO *info;\r
+\r
+ t->rgbData = LoadDIBitmap(fileName, &info);\r
+ t->height=info->bmiHeader.biHeight;\r
+ t->width=info->bmiHeader.biWidth;\r
+\r
+ return t;\r