#include #include "inputModule.h" #include "PLY.h" #include "stripper.h" extern PLYObject *ply; extern Stripper *stripper; static int motionMode; static int startX; static int startY; static GLfloat angle = 20; /* in degrees */ static GLfloat angle2 = 30; /* in degrees */ GLfloat current_pos[] = {0.0, 0.0, 5.0}; int box = 1; int wire = 0; int flat = 0; int triangles = 1; int withEdges = 0; int loops = 0; int tweakMode = 0; int drawMode = 1; int m3 = false; void readKeyboard(unsigned char key, int x, int y) { switch(key){ case 0x1B: case 'q': case 'Q': //kill(getpid(), SIGHUP); exit(0); break; case 'a': case 'A': stripper->makeDual(); break; case 'p': case 'P': stripper->preprocessBoundary(); break; case 'm': case 'M': stripper->findMatching(); break; case 'd': case 'D': drawMode = (drawMode + 1)%2; break; case 'j': case 'J': stripper->findJunctionsLoopsPaths(); stripper->connectJunctions(); break; case 'c': case 'C': stripper->dfsTraversal(); break; case 'e': case 'E': stripper->removeCutEdges(); break; case 'g': case 'G': m3 = !m3; break; case 'b': case 'B': box = (box + 1) % 2; break; case 'w': case 'W': wire = (wire + 1) % 2; break; case 't': case 'T': triangles = (triangles + 1) % 2; break; case 'f': case 'F': flat = (flat + 1) % 2; break; case 'i': case 'I': if (ply) ply->invertNormals(); break; case 'h': case 'H': printf("\tpress q/Q for quit\n"); printf("\tpress b/B to display Bounding Box\n"); printf("\tpress w/W to togle Wireframe rendering\n"); printf("\tpress f/F to toggle Flat shading\n"); printf("\tpress t/T to toggle Triangle rendering\n"); printf("\tpress e/E to toggle Edge rendering\n"); printf("\tpress i/I to Invert normals\n"); printf("\tpress r/R to Revert viewpoint to initial positions\n"); break; case 'r': case 'R': // reset initial view parameters angle = 20; angle2 = 30; current_pos[0] = 0.0; current_pos[1] = 0.0; current_pos[2] = 5.0; break; default: break; } glutPostRedisplay(); } void readSpecialKeys(int key, int x, int y) { switch(key){ case GLUT_KEY_UP: break; case GLUT_KEY_DOWN: break; case GLUT_KEY_RIGHT: break; case GLUT_KEY_LEFT: break; } glutPostRedisplay(); } void mouseButtHandler(int button, int state, int x, int y) { motionMode = 0; switch(button){ case GLUT_LEFT_BUTTON: if(state == GLUT_DOWN) { motionMode = 1; // Rotate object startX = x; startY = y; } break; case GLUT_MIDDLE_BUTTON: if(state == GLUT_DOWN) { motionMode = 2; // Translate object startX = x; startY = y; } break; case GLUT_RIGHT_BUTTON: if(state == GLUT_DOWN) { motionMode = 3; // Zoom startX = x; startY = y; } break; } glutPostRedisplay(); } void mouseMoveHandler(int x, int y) { switch(motionMode){ case 0: // No mouse button is pressed... return return; break; case 1: // Calculate the rotations angle = angle + (x - startX); angle2 = angle2 + (y - startY); startX = x; startY = y; break; case 2: // Calculate side displacement current_pos[0] = current_pos[0] - (x - startX)/100.0; current_pos[1] = current_pos[1] - (y - startY)/100.0; startX = x; startY = y; break; case 3: // Come closer or further away current_pos[2] = current_pos[2] - (y - startY)/40.0; startX = x; startY = y; break; } glutPostRedisplay(); } void setUserView() { glLoadIdentity(); glTranslatef(-current_pos[0], current_pos[1], -current_pos[2]); glRotatef(angle2, 1.0, 0.0, 0.0); glRotatef(angle, 0.0, 1.0, 0.0); }