Example #1
0
int main(int argc, char* argv[]) {

	if (argc < 2) {
		cerr << "Usage: transforms scenefile [grader input (optional)]\n"; 
		exit(-1); 
	}

  	FreeImage_Initialise();
	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);
	glutCreateWindow("HW2: Scene Viewer");
	init();
        readfile(argv[1]) ; 
	glutDisplayFunc(display);
	glutSpecialFunc(specialKey);
	glutKeyboardFunc(keyboard);
	glutReshapeFunc(reshape);
	glutReshapeWindow(w, h);

	if (argc > 2) {
		allowGrader = true;
		stringstream tcid;
		tcid << argv[1] << "." << argv[2];
		grader.init(tcid.str());
		grader.loadCommands(argv[2]);
		grader.bindDisplayFunc(display);
		grader.bindSpecialFunc(specialKey);
		grader.bindKeyboardFunc(keyboard);
		grader.bindScreenshotFunc(saveScreenshot);
	}

	printHelp();
	glutMainLoop();
	FreeImage_DeInitialise();
	return 0;
}
Example #2
0
void keyboard(unsigned char key, int x, int y) {
	switch(key) {
        case 'w':
            stopObjTransform();
            break;
        case 'o':
            stopObjTransform();
            startObjTransform();
            break;
        case '+':
            amount++;
            std::cout << "amount set to " << amount << "\n" ;
            break;
        case '-':
            amount--;
            std::cout << "amount set to " << amount << "\n" ;
            break;
        case 'i':
            if(allowGrader) {
                std::cout << "Running tests...\n";
                grader.runTests();
                std::cout << "Done! [ESC to quit]\n";
            } else {
                std::cout << "Error: no input file specified for grader\n";
            }
            break;
        case 'g':
            useGlu = !useGlu;
            reshape(w,h) ;
            std::cout << "Using glm::LookAt and glm::Perspective set to: " << (useGlu ? " true " : " false ") << "\n" ;
            break;
        case 'h':
            printHelp();
            break;
        case 'x':
            std::cout << "printing image...\n";
            fileName << "extra_credit.obj.screenshot_" << screenshotCount << ".png";
            saveScreenshot(fileName.str());
            fileName.str("");
            screenshotCount++;
            break;
        case 27:  // Escape to quit
            exit(0) ;
            break ;
        case 'r': // reset eye and up vectors, scale and translate.
            for(int i = 0; i < 4*numLights; i++) lightposn[i] = lightposnReset[i];
            for(int k = 0; k < numobjects; k++){
                object * obj = &(objects[k]);
                obj -> transform = obj -> transformOriginal;
            }
            eye = eyeinit ;
            up = upinit ;
            sx = sy = 1.0 ;
            tx = ty = 0.0 ;
            break ;
        case 'v':
            transop = view ;
            std::cout << "Operation is set to View\n" ;
            break ;
        case 't':
            transop = translate ;
            std::cout << "Operation is set to Translate\n" ;
            break ;
        case 's':
            transop = scale ;
            std::cout << "Operation is set to Scale\n" ;
            break ;
        case '0':
            transop = lightop;
            activeLight = 0;
            std::cout << "Operation is set to light 0 movement\n";
            break;
        case '1':
            transop = lightop;
            activeLight = 1;
            std::cout << "Operation is set to light 1 movement\n";
            break;
        case '2':
            transop = lightop;
            activeLight = 2;
            std::cout << "Operation is set to light 2 movement\n";
            break;
        case '3':
            transop = lightop;
            activeLight = 3;
            std::cout << "Operation is set to light 3 movement\n";
            break;
        case '4':
            transop = lightop;
            activeLight = 4;
            std::cout << "Operation is set to light 4 movement\n";
            break;
        case '5':
            transop = lightop;
            activeLight = 5;
            std::cout << "Operation is set to light 5 movement\n";
            break;
        case '6':
            transop = lightop;
            activeLight = 6;
            std::cout << "Operation is set to light 6 movement\n";
            break;
        case '7':
            transop = lightop;
            activeLight = 7;
            std::cout << "Operation is set to light 7 movement\n";
            break;
        case '8':
            transop = lightop;
            activeLight = 8;
            std::cout << "Operation is set to light 8 movement\n";
            break;
        case '9':
            transop = lightop;
            activeLight = 9;
            std::cout << "Operation is set to light 9 movement\n";
            break;
    }
	glutPostRedisplay();
}