// William Fletcher Cole // wfcole@ucsc.edu 1161055 // Final Project : Human Motion as a Funtion of Body Parameters // window.c // Creates and monitors the window and drawing for the program. #include #include #include #include #include "window.h" #include "body.h" /******************** PROPERTIES ************************/ float lightx = 1.0; float lighty = 1.0; float lightz = 1.0; float roty = 0.0f; float zoomz = 0.0f; float height = 0.5; float beef = 0.5; float spread = 0.5; /******************** FUNCTIONS *************************/ // main(): // The entry point for the program int main(int argc, char** argv) { glutInit(&argc, argv); glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); glutInitWindowSize (SCREEN_WIDTH, SCREEN_HEIGHT); glutInitWindowPosition (SCREEN_XPOS, SCREEN_YPOS); glutCreateWindow (argv[0]); //glutMouseFunc(select_objects); glutReshapeFunc(reshape); init(); glutDisplayFunc(display); glutKeyboardFunc(keyboard); glutSpecialFunc(special_key); initialize_body(); glutMainLoop(); return 0; } // init(): // Setup lighting in the scene void init(void) { GLfloat ambient[] = { 0.0, 0.0, 0.0, 1.0 }; GLfloat diffuse[] = { 1.0, 1.0, 1.0, 1.0 }; GLfloat position[] = { lightx, lighty, lightz, 0.0 }; glEnable(GL_DEPTH_TEST); //glDepthFunc(GL_LESS); glEnable(GL_COLOR_MATERIAL); glLightfv(GL_LIGHT0, GL_AMBIENT, ambient); glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse); glLightfv(GL_LIGHT0, GL_POSITION, position); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); } // draw_scene(): // Draws the scene by calling the draw methods for all objects void draw_scene(int mode) { update_proportions(height, beef, spread); draw_body(mode, roty, zoomz); } // display(): // The auto-called glut display method void display(void) { gluLookAt(0.0, 0.0, 8.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0); GLint mode = GL_RENDER; glGetIntegerv(GL_RENDER_MODE, &mode); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glClearColor (0.0, 0.0, 0.0, 0.0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); draw_scene(GL_RENDER); glFlush(); glutSwapBuffers(); glutPostRedisplay(); } // reshape(): // Sets the perspective for the scene void reshape(int w, int h) { glViewport(0, 0, w, h); glMatrixMode (GL_PROJECTION); glLoadIdentity (); gluPerspective(60.0,1.0,0.5,100.0); } // special_key(): // Handles arrow key presses void special_key(int key, int x, int y) { switch (key) { case GLUT_KEY_UP: height += 0.1f; break; case GLUT_KEY_DOWN: height -= 0.1f; break; case GLUT_KEY_LEFT: beef -= 0.1f; break; case GLUT_KEY_RIGHT: beef += 0.1f; break; default: break; } glutPostRedisplay(); } // keyboard(): // Handles non-arrow key presses void keyboard(unsigned char key, int x, int y) { switch (key) { case 27: /* escape key*/ exit(0); break; case 'j': // jumping start set_jumping(1 - get_jumping()); break; case '2': spread += 0.1f; break; case '1': spread -= 0.1f; break; case 'a': roty += 1.0f; break; case 'd': roty -= 1.0f; break; case 'w': zoomz += 0.1f; break; case 's': zoomz -= 0.1f; break; default: break; } glutPostRedisplay(); }