-// compile this program using:\r
-// gcc -O3 -Wall -std=c99 -o scene scene.c bitmap.c -lglut\r
-// Or, with cygwin: (-mno-cygwin is only so the executable runs from windows)\r
-// gcc -mno-cygwin -O3 -Wall -std=c99 -o scene scene.c bitmap.c -lglut32 -lglu32 -lopengl32\r
-// Or, use make via the supplied Makefile: (For cygwin, install the package for make)\r
-// make\r
+/**\r
+ * CITS2231 Graphics Scene Editor\r
+ * @author Ashley Tyndall (20915779)\r
+ */\r
\r
#include <stdlib.h>\r
#include <stdio.h>\r
#include <math.h>\r
#include <GL/gl.h>\r
#include <GL/glut.h>\r
+#include <time.h>\r
\r
#include "bitmap.h"\r
+#include "globals.h"\r
+#include "helper.h"\r
+#include "types.h"\r
+#include "scene.h"\r
+\r
+/**\r
+ * Event hander for main menu events\r
+ * @param id ID of menu item selected\r
+ */\r
+void processMainEvents(int id) {\r
+ switch (id) {\r
+ case M_ROTATE_MOVE_CAMERA:\r
+ // Do stuff\r
+ break;\r
\r
-// Type definitions for vertex-coordinates, normals, texture-coordinates, \r
-// and triangles (via the indices of 3 vertices).\r
-typedef GLfloat vertex[3];\r
-typedef GLfloat normal[3];\r
-typedef GLfloat texCoord[2];\r
-typedef GLint vertexIndex;\r
-typedef vertexIndex triangle[3];\r
-\r
-// A type for a mesh\r
-typedef struct { \r
- int nVertices; // The number of vertices in the mesh\r
- vertex* vertices; // Array with coordinates of vertices\r
- normal* normals; // Array with normals of vertices\r
- texCoord* texCoords; // Array with texture-coordinates of vertices\r
- int nTriangles; // The number of triangles in the mesh\r
- triangle* triangles; // Array of trangles via 3 indices into "vertices"\r
-} mesh;\r
-\r
-#define NMESH 54 // The number of meshes (in the models-textures dir)\r
-mesh* meshes[NMESH]; // An array of pointers to the meshes - see getMesh\r
-\r
-// A type for a 2D texture, with height and width in pixels\r
-typedef struct {\r
- int height;\r
- int width;\r
- GLubyte *rgbData; // Array of bytes with the colour data for the texture\r
-} texture;\r
-\r
-#define NTEXTURE 30 // The number of textures (in the models-textures dir)\r
-texture* textures[NTEXTURE]; // An array of texture pointers - see getTexture\r
-\r
-typedef struct { \r
- // You'll need to add scale, rotation, material, mesh number, etc.,\r
- // to this structure\r
- float x,y,z;\r
-} SceneObject;\r
-\r
-#define MAXOBJECTS 256\r
-SceneObject sceneObjs[MAXOBJECTS]; // An array with details of the objects in a scene\r
-int nObjects=0; // How many objects there are in the scene currently.\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(1);\r
-} \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
-}\r
+ case M_POSITION_SCALE:\r
+ // Do stuff\r
+ break;\r
\r
-// The following works for the supplied .x files\r
-// but probably not for .x files from other sources.\r
-mesh* loadMesh(char* fileName) {\r
- mesh* m = malloc(sizeof (mesh));\r
- FILE* fp = fopen(fileName, "r");\r
- char line[256] = "";\r
- int lineBuffSize = 256;\r
-\r
- if(fp == NULL) fileErr(fileName);\r
-\r
- while(strcmp(line,"Mesh {\r\n") != 0 && strcmp(line,"Mesh {\n") != 0 )\r
- fgets(line, lineBuffSize, fp);\r
-\r
- fscanf(fp, "%d;\n", &(m->nVertices));\r
- m->vertices = malloc(m->nVertices * sizeof(vertex));\r
- for(int i=0; i < m->nVertices; i++)\r
- fscanf(fp, "%f; %f; %f;%*[,;]\n", &(m->vertices[i][0]), &(m->vertices[i][1]), &(m->vertices[i][2]) );\r
-\r
- fscanf(fp, "%d;\n", &(m->nTriangles));\r
- m->triangles = malloc(m->nTriangles * sizeof(triangle));\r
- for(int i=0; i < m->nTriangles; i++)\r
- fscanf(fp, "%*d; %d, %d, %d;%*[;,]", m->triangles[i], m->triangles[i]+1, m->triangles[i]+2);\r
-\r
- while(strcmp(line," MeshNormals {\r\n") != 0 && strcmp(line," MeshNormals {\n") != 0)\r
- fgets(line, lineBuffSize, fp);\r
-\r
- fgets(line, lineBuffSize, fp);\r
- m->normals = malloc(m->nVertices * sizeof(normal));\r
- for(int i=0; i < m->nVertices; i++)\r
- fscanf(fp, "%f; %f; %f;%*[;,]\n",\r
- &(m->normals[i][0]), &(m->normals[i][1]), &(m->normals[i][2]));\r
-\r
- while(strcmp(line,"MeshTextureCoords {\r\n") != 0 && strcmp(line,"MeshTextureCoords {\n") != 0)\r
- fgets(line, lineBuffSize, fp);\r
-\r
- fgets(line, lineBuffSize, fp);\r
- m->texCoords = malloc(m->nVertices * sizeof(texCoord));\r
- for(int i=0; i < m->nVertices; i++)\r
- fscanf(fp, "%f;%f;%*[,;]\n", &(m->texCoords[i][0]), &(m->texCoords[i][1]) );\r
- fclose(fp);\r
- \r
- return m;\r
-}\r
+ case M_ROTATION_TEXTURE_SCALE:\r
+ // Do stuff\r
+ break;\r
\r
-char dataDir[200]; // Stores the directory name for the meshes and textures.\r
+ case M_EXIT:\r
+ exit(EXIT_SUCCESS);\r
\r
-// getMesh(i) loads mesh[i] if it isn't already loaded. \r
-// You must call getMesh(i) at least once before using mesh[i].\r
-// [You may want to add to this function.]\r
-void getMesh(int i) { // getMesh(i) loads mesh[i] if it isn't already loaded. \r
- char fileName[220];\r
- if(i>=NMESH || i<0) {\r
- printf("Error in getMesh - wrong model number");\r
- exit(1);\r
- }\r
- if(meshes[i] != NULL)\r
- return;\r
- sprintf(fileName, "%s/model%d.x", dataDir, i+1);\r
- meshes[i] = loadMesh(fileName);\r
+ }\r
}\r
\r
-// getTexture(i) loads texture i if it isn't already loaded.\r
-// After calling getTexture(i), you can make texture i the current texture using\r
-// glBindTexture(GL_TEXTURE_2D, i); (Use i=0 to return to the default plain texture.)\r
-// You can then scale the texture via: (See the textbook, section 8.8.3.)\r
-// glMatrixMode(GL_TEXTURE); \r
-// You must call getTexture(i) at least once before using texture i.\r
-void getTexture(int i) { // getTexture(i) loads texture i if it isn't already loaded.\r
- char fileName[220];\r
- if(i<1 || i>NTEXTURE) {\r
- printf("Error in getTexture - wrong texture number");\r
- exit(1);\r
- }\r
- if(textures[i-1] != NULL)\r
- return;\r
- sprintf(fileName, "%s/texture%d.bmp", dataDir, i);\r
+/**\r
+ * Event hander for materials menu events\r
+ * @param id ID of menu item selected\r
+ */\r
+void processMaterialEvents(int id) {\r
+ switch (id) {\r
+ case M_MATERIAL_ALL_RGB:\r
+ // Do stuff\r
+ break;\r
\r
- textures[i-1] = loadTexture(fileName);\r
+ case M_MATERIAL_AMBIENT_RGB:\r
+ // Do stuff\r
+ break;\r
\r
- glBindTexture(GL_TEXTURE_2D, i);\r
+ case M_MATERIAL_DIFFUSE_RGB:\r
+ // Do stuff\r
+ break;\r
\r
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, textures[i-1]->width, textures[i-1]->height,\r
- 0, GL_RGB, GL_UNSIGNED_BYTE, textures[i-1]->rgbData);\r
- gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB, textures[i-1]->width, textures[i-1]->height, GL_RGB, \r
- GL_UNSIGNED_BYTE, textures[i-1]->rgbData);\r
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);\r
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);\r
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);\r
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);\r
+ case M_MATERIAL_SPECULAR_RGB:\r
+ // Do stuff\r
+ break;\r
\r
- glBindTexture(GL_TEXTURE_2D, 0); // Back to default texture\r
-}\r
+ case M_MATERIAL_ALL_ADSS:\r
+ // Do stuff\r
+ break;\r
\r
-// Menu enum\r
-enum menu {\r
- // Main menu\r
- ROTATE_MOVE_CAMERA,\r
- POSITION_SCALE,\r
- ROTATION_TEXTURE_SCALE,\r
- EXIT,\r
-\r
- // Material submenu\r
- MATERIAL_ALL_RGB,\r
- MATERIAL_AMBIENT_RGB,\r
- MATERIAL_DIFFUSE_RGB,\r
- MATERIAL_SPECULAR_RGB,\r
- MATERIAL_ALL_ADSS,\r
- MATERIAL_RED_ADSS,\r
- MATERIAL_GREEN_ADSS,\r
- MATERIAL_BLUE_ADSS,\r
-\r
- // Light submenu\r
- LIGHT_MOVE_LIGHT_1,\r
- LIGHT_RGBALL_LIGHT_1,\r
- LIGHT_MOVE_LIGHT_2,\r
- LIGHT_RGBALL_LIGHT_2\r
-};\r
-\r
-// Menu arrays\r
-const char *textureMenuEntries[NTEXTURE] = {\r
- "1 Plain", "2 Rust", "3 Concrete", "4 Carpet", "5 Beach Sand", \r
- "6 Rocky", "7 Brick", "8 Water", "9 Paper", "10 Marble", \r
- "11 Wood", "12 Scales", "13 Fur", "14 Denim", "15 Hessian",\r
- "16 Orange Peel", "17 Ice Crystals", "18 Grass", "19 Corrugated Iron", "20 Styrofoam",\r
- "21 Bubble Wrap", "22 Leather", "23 Camouflage", "24 Asphalt", "25 Scratched Ice",\r
- "26 Rattan", "27 Snow", "28 Dry Mud", "29 Old Concrete", "30 Leopard Skin"\r
-};\r
-\r
-const char *objectMenuEntries[NMESH] = {\r
- "1 Thin Dinosaur","2 Big Dog","3 Saddle Dinosaur", "4 Dragon", "5 Cleopatra", \r
- "6 Bone I", "7 Bone II", "8 Rabbit", "9 Long Dragon", "10 Buddha", \r
- "11 Sitting Rabbit", "12 Frog", "13 Cow", "14 Monster", "15 Sea Horse", \r
- "16 Head", "17 Pelican", "18 Horse", "19 Kneeling Angel", "20 Porsche I", \r
- "21 Truck", "22 Statue of Liberty", "23 Sitting Angel", "24 Metal Part", "25 Car", \r
- "26 Apatosaurus", "27 Airliner", "28 Motorbike", "29 Dolphin", "30 Spaceman", \r
- "31 Winnie the Pooh", "32 Shark", "33 Crocodile", "34 Toddler", "35 Fat Dinosaur", \r
- "36 Chihuahua", "37 Sabre-toothed Tiger", "38 Lioness", "39 Fish", "40 Horse (head down)", \r
- "41 Horse (head up)", "42 Skull", "43 Fighter Jet I", "44 Toad", "45 Convertible", \r
- "46 Porsche II", "47 Hare", "48 Vintage Car", "49 Fighter Jet II", "50 Winged Monkey", \r
- "51 Chef", "52 Parasaurolophus", "53 Rooster", "54 T-rex"\r
-};\r
+ case M_MATERIAL_RED_ADSS:\r
+ // Do stuff\r
+ break;\r
\r
+ case M_MATERIAL_GREEN_ADSS:\r
+ // Do stuff\r
+ break;\r
\r
-\r
-void processMainEvents(int id) {\r
- switch (id) {\r
- case EXIT:\r
- exit(0);\r
+ case M_MATERIAL_BLUE_ADSS:\r
+ // Do stuff\r
+ break;\r
\r
}\r
}\r
\r
-void processObjectEvents(int id) {\r
+/**\r
+ * Event hander for light menu events\r
+ * @param id ID of menu item selected\r
+ */\r
+void processLightEvents(int id) {\r
+ switch (id) {\r
+ case M_LIGHT_MOVE_LIGHT_1:\r
+ // Do stuff\r
+ break;\r
\r
-}\r
+ case M_LIGHT_RGBALL_LIGHT_1:\r
+ // Do stuff\r
+ break;\r
\r
-void processMaterialEvents(int id) {\r
+ case M_LIGHT_MOVE_LIGHT_2:\r
+ // Do stuff\r
+ break;\r
\r
-}\r
-\r
-void processTextureEvents(int id) {\r
+ case M_LIGHT_RGBALL_LIGHT_2:\r
+ // Do stuff\r
+ break;\r
\r
+ }\r
}\r
\r
-void processGTextureEvents(int id) {\r
+/**\r
+ * Event hander for object menu events\r
+ * @param id ID of object selected\r
+ */\r
+void processObjectEvents(int id) {\r
\r
}\r
\r
-void processLightEvents(int id) {\r
+/**\r
+ * Event hander for texture menu events\r
+ * @param id ID of texutre selected\r
+ */\r
+void processTextureEvents(int id) {\r
\r
}\r
\r
+/**\r
+ * Event hander for ground texture menu events\r
+ * @param id ID of ground texture selected\r
+ */\r
+void processGTextureEvents(int id) {\r
\r
+}\r
\r
+/**\r
+ * Creates menu for program\r
+ */\r
void makeMenu() {\r
// Construct material menu\r
int materialMenu = glutCreateMenu(processMaterialEvents);\r
- glutAddMenuEntry("All R/G/B", MATERIAL_ALL_RGB);\r
- glutAddMenuEntry("Ambient R/G/B", MATERIAL_AMBIENT_RGB);\r
- glutAddMenuEntry("Diffuse R/G/B", MATERIAL_DIFFUSE_RGB);\r
- glutAddMenuEntry("Specular R/G/B", MATERIAL_SPECULAR_RGB);\r
- glutAddMenuEntry("All Amb/Diff/Spec/Shine", MATERIAL_ALL_ADSS);\r
- glutAddMenuEntry("Red Amb/Diff/Spec/Shine", MATERIAL_RED_ADSS);\r
- glutAddMenuEntry("Green Amb/Diff/Spec/Shine", MATERIAL_GREEN_ADSS);\r
- glutAddMenuEntry("Blue Amb/Diff/Spec/Shine", MATERIAL_BLUE_ADSS);\r
+ glutAddMenuEntry("All R/G/B", M_MATERIAL_ALL_RGB);\r
+ glutAddMenuEntry("Ambient R/G/B", M_MATERIAL_AMBIENT_RGB);\r
+ glutAddMenuEntry("Diffuse R/G/B", M_MATERIAL_DIFFUSE_RGB);\r
+ glutAddMenuEntry("Specular R/G/B", M_MATERIAL_SPECULAR_RGB);\r
+ glutAddMenuEntry("All Amb/Diff/Spec/Shine", M_MATERIAL_ALL_ADSS);\r
+ glutAddMenuEntry("Red Amb/Diff/Spec/Shine", M_MATERIAL_RED_ADSS);\r
+ glutAddMenuEntry("Green Amb/Diff/Spec/Shine", M_MATERIAL_GREEN_ADSS);\r
+ glutAddMenuEntry("Blue Amb/Diff/Spec/Shine", M_MATERIAL_BLUE_ADSS);\r
\r
// Construct light menu\r
int lightMenu = glutCreateMenu(processLightEvents);\r
- glutAddMenuEntry("Move Light 1", LIGHT_MOVE_LIGHT_1);\r
- glutAddMenuEntry("R/G/B/All Light 1", LIGHT_RGBALL_LIGHT_1);\r
- glutAddMenuEntry("Move Light 2", LIGHT_MOVE_LIGHT_2);\r
- glutAddMenuEntry("R/G/B/All Light 2", LIGHT_RGBALL_LIGHT_2);\r
-\r
- // Construct add object submenus\r
- int objectMenuEntriesSize = sizeof(objectMenuEntries) / sizeof(objectMenuEntries[0]);\r
- int menuNumber = objectMenuEntriesSize / 10 + 1;\r
- int addObjectSubmenu[menuNumber-1];\r
-\r
- for( int i = 0; i < menuNumber; i++ ) {\r
- addObjectSubmenu[i] = glutCreateMenu(processObjectEvents);\r
- int startNum = i*11 - (i-1);\r
- for ( int j = startNum - 1; j < (startNum+9); j++ ) {\r
- if ( j == objectMenuEntriesSize ) break; // Detect if we've reached the end of the array\r
- glutAddMenuEntry( objectMenuEntries[j], j );\r
+ glutAddMenuEntry("Move Light 1", M_LIGHT_MOVE_LIGHT_1);\r
+ glutAddMenuEntry("R/G/B/All Light 1", M_LIGHT_RGBALL_LIGHT_1);\r
+ glutAddMenuEntry("Move Light 2", M_LIGHT_MOVE_LIGHT_2);\r
+ glutAddMenuEntry("R/G/B/All Light 2", M_LIGHT_RGBALL_LIGHT_2);\r
+\r
+ // Construct object menu\r
+ int objectMenu = makeSubmenuFromArray( objectMenuEntries, NMESH, processObjectEvents );\r
+\r
+ // Construct texture / ground texture menus\r
+ int textureMenu = makeSubmenuFromArray( textureMenuEntries, NTEXTURE, processTextureEvents );\r
+ int gTextureMenu = makeSubmenuFromArray( textureMenuEntries, NTEXTURE, processGTextureEvents );\r
+\r
+ // Construct main menu\r
+ glutCreateMenu(processMainEvents);\r
+ //glutAddMenuEntry("Rotate/Move Camera", M_ROTATE_MOVE_CAMERA);\r
+ //glutAddSubMenu("Add object", objectMenu);\r
+ //glutAddMenuEntry("Position/Scale", M_POSITION_SCALE);\r
+ //glutAddMenuEntry("Rotation/Texture Scale", M_ROTATION_TEXTURE_SCALE);\r
+ //glutAddSubMenu("Material", materialMenu);\r
+ //glutAddSubMenu("Texture", textureMenu);\r
+ //glutAddSubMenu("Ground texture", gTextureMenu);\r
+ //glutAddSubMenu("Lights", lightMenu);\r
+ glutAddMenuEntry("Exit", M_EXIT);\r
+\r
+ // Bind to right mouse button\r
+ glutAttachMenu(GLUT_RIGHT_BUTTON);\r
+}\r
+\r
+/**\r
+ * Called when window is resized\r
+ * @param w New width\r
+ * @param h New height\r
+ */\r
+void windowReshape(int w, int h) {\r
+ glViewport(0, 0, (GLsizei) w, (GLsizei) h);\r
+ /*glMatrixMode(GL_PROJECTION);\r
+ glLoadIdentity();\r
+ if (w <= h) \r
+ glFrustum(near, far, near*(GLfloat)h/(GLfloat)w,\r
+ far*(GLfloat)h/(GLfloat)w, -100, 100);\r
+ else\r
+ glFrustum(near*(GLfloat)w/(GLfloat)h,\r
+ far*(GLfloat)w/(GLfloat)h, near, far, nearClip, farClip);\r
+ glMatrixMode(GL_MODELVIEW);\r
+ glLoadIdentity();*/\r
+}\r
+\r
+/**\r
+ * Called when mouse event occurs\r
+ * @param btn Mouse button\r
+ * @param state State of mouse button\r
+ * @param x Mouse x position\r
+ * @param y Mouse y position\r
+ */\r
+void mouse(int button, int state, int x, int y) {\r
+ if (button == GLUT_LEFT_BUTTON) {\r
+ if (state == GLUT_DOWN) {\r
+ moving = 1;\r
+ startx = x;\r
+ starty = y;\r
+ }\r
+ if (state == GLUT_UP) {\r
+ moving = 0;\r
}\r
}\r
-\r
- // Construct add object menu\r
- int addObjectMenu = glutCreateMenu(processObjectEvents);\r
- for ( int i = 0; i < menuNumber; i++ ) {\r
- char name[10]; // buffer to hold name\r
- int startNum = i*11 - (i-1);\r
- int endNum = startNum + 9;\r
- if ( i == menuNumber - 1 ) { // We're on the last one\r
- endNum = startNum + 3;\r
+ if (button == GLUT_MIDDLE_BUTTON) {\r
+ if (state == GLUT_DOWN) {\r
+ lightMoving = 1;\r
+ lightStartX = x;\r
+ lightStartY = y;\r
+ }\r
+ if (state == GLUT_UP) {\r
+ lightMoving = 0;\r
}\r
- sprintf(name, "%d-%d", startNum, endNum);\r
- glutAddSubMenu( name, addObjectSubmenu[i] );\r
}\r
+}\r
\r
+/**\r
+ * Keybord event handler\r
+ * w/s increase/decrease the z\r
+ * a/d increase/decrease the x\r
+ * q/e increase/decrease the y\r
+ * z/x increase/decrease the angle\r
+ * @param key Key pressed\r
+ * @param x x co-ordinate of mouse\r
+ * @param y y co-ordinate of mouse\r
+ */\r
+void keyboard(unsigned char key, int x, int y) {\r
+ switch(key) {\r
+ case 'w':\r
+ camz = camz - 1;\r
+ break;\r
+ case 'a':\r
+ camx = camx - 1;\r
+ break;\r
+ case 's':\r
+ camz = camz + 1;\r
+ break;\r
+ case 'd':\r
+ camx = camx + 1;\r
+ break;\r
+ case 'q':\r
+ camy = camy + 1;\r
+ break;\r
+ case 'e':\r
+ camy = camy - 1;\r
+ break;\r
+ case 'z':\r
+ rot = rot + 1;\r
+ break;\r
+ case 'x':\r
+ rot = rot - 1;\r
+ break;\r
+ }\r
+ printf("Camera is now at (%f, %f, %f), angle %f\n", camx, camy, camz, rot);\r
+ glutPostRedisplay();\r
+}\r
\r
- int mainMenu = glutCreateMenu(processMainEvents);\r
-\r
- glutAddMenuEntry("Rotate/Move Camera", ROTATE_MOVE_CAMERA);\r
- glutAddSubMenu("Add object", addObjectMenu);\r
- glutAddMenuEntry("Position/Scale", POSITION_SCALE);\r
- glutAddMenuEntry("Rotation/Texture Scale", ROTATION_TEXTURE_SCALE);\r
- //material\r
- \r
- \r
+/**\r
+ * Called when motion event occurs\r
+ * @param x Mouse x position\r
+ * @param y Mouse y position\r
+ */\r
+void motion(int x, int y) {\r
+ if (moving) {\r
+ angle = angle + (x - startx);\r
+ angle2 = angle2 + (y - starty);\r
+ startx = x;\r
+ starty = y;\r
+ glutPostRedisplay();\r
+ }\r
+ if (lightMoving) {\r
+ lightAngle += (x - lightStartX)/40.0;\r
+ lightHeight += (lightStartY - y)/20.0;\r
+ lightStartX = x;\r
+ lightStartY = y;\r
+ glutPostRedisplay();\r
+ }\r
+}\r
\r
- glutSetMenu(mainMenu);\r
- glutAddSubMenu("Material", materialMenu);\r
+/**\r
+ * Display function\r
+ */\r
+void display() {\r
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);\r
+ glLoadIdentity();\r
+ //gluLookAt(\r
+ // 0.0, 0.0, 30.0, /* eye is at (x,y,z) */\r
+ // 0.0, 0.0, 0.0, /* center is at (x,y,z) */\r
+ // 0.0, 1.0, 0.0 /* up is in postivie Y direction */\r
+ // );\r
+\r
+ //glTranslatef(camx, camy, camz);\r
\r
- //texture\r
- //ground texture\r
- //lights\r
+ // **NOTE: Currently this rotation function is all that moves the camera off\r
+ // the flat surface. Need to integrate function into gluLookAt\r
+ //glRotatef(rot, 1.0, 0.0, 0.0);\r
\r
+ /* Reposition the light source. */\r
+ lightPosition[0] = 12*cos(lightAngle);\r
+ lightPosition[1] = lightHeight;\r
+ lightPosition[2] = 12*sin(lightAngle);\r
+ lightPosition[3] = 0.0;\r
\r
- glutAddMenuEntry("Exit", EXIT);\r
+ glPushMatrix();\r
\r
- glutAttachMenu(GLUT_RIGHT_BUTTON);\r
-}\r
+ /* Perform scene rotations based on user mouse input. */\r
+ glRotatef(angle, 0.0, 1.0, 0.0);\r
+ glRotatef(angle2, 1.0, 0.0, 0.0); //**NOTE: Only one degree of freedom\r
\r
-void display() {\r
- // You probably want to change both of the following.\r
- glClear(GL_COLOR_BUFFER_BIT);\r
- glFlush();\r
-}\r
+ glLightfv(GL_LIGHT0, GL_POSITION, lightPosition);\r
\r
-char *dirDefault1 = "models-textures"; \r
-char *dirDefault2 = "/cslinux/examples/CITS2231/project-files/models-textures";\r
-int main(int argc, char **argv) {\r
+ drawFloor();\r
\r
- if(argc>1)\r
- strcpy(dataDir, argv[1]);\r
- else if(opendir(dirDefault1))\r
- strcpy(dataDir, dirDefault1);\r
- else if(opendir(dirDefault2))\r
- strcpy(dataDir, dirDefault2);\r
- else fileErr(dirDefault1);\r
+ drawLine();\r
+ \r
+ // Draw teapot for a test object\r
+ glPushMatrix();\r
+ glTranslatef(0.0, 1.0, 0.0); // **NOTE: Teapot does not rest on surface\r
+ glColor3f(0.5, 0.5, 0.5);\r
+ glutSolidTeapot(10);\r
+ glPopMatrix();\r
+\r
+ // Draw a white ball over the light source\r
+ glPushMatrix();\r
+ glDisable(GL_LIGHTING);\r
+ glColor3f(1.0, 1.0, 1.0);\r
+ glTranslatef(lightPosition[0], lightPosition[1], lightPosition[2]);\r
+ glutSolidSphere(1.0, 50, 50);\r
+ glEnable(GL_LIGHTING);\r
+ glPopMatrix();\r
+\r
+ glPopMatrix();\r
+\r
+ glutSwapBuffers();\r
+}\r
\r
- for(int i=0; i<NMESH; i++) meshes[i]=NULL;\r
- for(int i=0; i<NTEXTURE; i++) textures[i]=NULL;\r
+/**\r
+ * init function; sets initial OpenGL state\r
+ */\r
+void init() {\r
+ //glMatrixMode(GL_PROJECTION);\r
+ //glLoadIdentity();\r
+\r
+ //gluPerspective(\r
+ // 60.0, /* field of view in degree */\r
+ // 1.0, /* aspect ratio */\r
+ // nearClip, /* Z near */\r
+ // farClip /* Z far */\r
+ // );\r
+ \r
+ glMatrixMode(GL_MODELVIEW);\r
+ glLoadIdentity();\r
+\r
+ glLightfv(GL_LIGHT0, GL_POSITION, light0_pos);\r
+ glLightfv(GL_LIGHT0, GL_AMBIENT, ambient0);\r
+ glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse0);\r
+ glLightfv(GL_LIGHT0, GL_SPECULAR, specular0);\r
+ glLightModelfv(GL_LIGHT_MODEL_AMBIENT, glightmodel);\r
+ glEnable(GL_LIGHT0);\r
+ glEnable(GL_LIGHTING);\r
+ glEnable(GL_COLOR_MATERIAL);\r
+ glColorMaterial( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE );\r
+ glMaterialfv( GL_FRONT_AND_BACK, GL_SPECULAR, specular0);\r
+ glMaterialfv( GL_FRONT_AND_BACK, GL_EMISSION, emission0);\r
\r
- // The following is enough to run the program, but you'll\r
- // need to change it significantly.\r
+ \r
\r
- glutInit(&argc, argv);\r
- glutCreateWindow("Scene Editor");\r
- glutDisplayFunc(display);\r
+}\r
\r
- makeMenu();\r
- glutMainLoop();\r
+/**\r
+ * Main function\r
+ * @param argc Number of arguments\r
+ * @param argv Array of arguments\r
+ * @return Program exit code\r
+ */\r
+int main(int argc, char **argv) {\r
+ if(argc>1)\r
+ strcpy(dataDir, argv[1]);\r
+ else if(opendir(dirDefault1))\r
+ strcpy(dataDir, dirDefault1);\r
+ else if(opendir(dirDefault2))\r
+ strcpy(dataDir, dirDefault2);\r
+ else fileErr(dirDefault1);\r
+\r
+ for(int i=0; i<NMESH; i++) meshes[i]=NULL;\r
+ for(int i=0; i<NTEXTURE; i++) textures[i]=NULL;\r
+\r
+ glutInit(&argc, argv);\r
+\r
+ glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);\r
+\r
+ glutInitWindowSize(500, 500);\r
+ glutCreateWindow("Scene Editor");\r
+\r
+ glShadeModel(GL_SMOOTH); // Enables Smooth Shading\r
+ glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // Black Background\r
+ glClearDepth(1.0f); // Depth Buffer Setup\r
+ glEnable(GL_DEPTH_TEST); // Enables Depth Testing\r
+ glDepthFunc(GL_LEQUAL); // the type\r
+ glEnable(GL_CULL_FACE);\r
+ glEnable(GL_TEXTURE_2D);\r
+ glLineWidth(1.0);\r
+\r
+ glMatrixMode(GL_PROJECTION);\r
+ gluPerspective( /* field of view in degree */ 40.0,\r
+ /* aspect ratio */ 1.0,\r
+ /* Z near */ 20.0, /* Z far */ 100.0);\r
+ glMatrixMode(GL_MODELVIEW);\r
+ gluLookAt(0.0, 8.0, 60.0, /* eye is at (0,8,60) */\r
+ 0.0, 8.0, 0.0, /* center is at (0,8,0) */\r
+ 0.0, 1.0, 0.); /* up is in postivie Y direction */\r
+\r
+ glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);\r
+\r
+ glutReshapeFunc(windowReshape);\r
+ glutDisplayFunc(display);\r
+ glutMouseFunc(mouse);\r
+ glutKeyboardFunc(keyboard);\r
+ glutMotionFunc(motion);\r
+\r
+ makeMenu();\r
+\r
+ init();\r
+\r
+ glutMainLoop();\r
}\r