예제 #1
0
static void lvMotion(int x, int y) {
	// Here we handle translation
	float norm = 1.0f / lvZoom;
	if (lvPressed[GLUT_LEFT_BUTTON]) {
		lvTransX += float(lastx - x)*2.0f*norm; 
        lvTransY += float(lasty - y)*2.0f*norm;
	}
	if (lvPressed[GLUT_MIDDLE_BUTTON]) 
	{
		iPlaneY += float(lasty - y)*0.5f;
		// Use this to change camera focus
		if (lastx - x < 0)
		{
			zDist += lsystem.stopTrans * float(lastx - x)*pow(zDist, 1.15f)/(1000.0)*0.5f;
			lsystem.refocus(zDist, -1);
		}
		else
		{
			zDist += float(lastx - x)*pow(zDist, 1.15f)/(1000.0)*0.5f;
			lsystem.refocus(zDist, 1);
		}
		
	}
	// Here we handle zooming
	if (lvPressed[GLUT_RIGHT_BUTTON]) {
	    float zoom = 4.0f * float(x - lastx) / lvWidth;
	    if ((lvZoom + zoom) >= 1.0f)
			lvZoom += zoom;
	}

	lastx = x; lasty = y; 
	glutPostRedisplay();
}
예제 #2
0
int main(int argc, char** argv) {
	if (argc < 2) {
		//printf("Usage: lensview <lens file>\n");
		//exit (-1);
		//argv[1] = ".\\lenses\\dgauss.50mm.dat";
		argv[1] = ".\\lenses\\fisheye.10mm.dat";
		//argv[1] = ".\\lenses\\telephoto.250mm.dat";
		//argv[1] = ".\\lenses\\wide.22mm.dat";
	}


	if (!lsystem.Load(argv[1])) {
		printf("Cannot open the lens file: %s.\n", argv[1]);
		exit(-1);
	}

    printf("1\n");
	lvZoom = lvHeight / lsystem.maxAperture() / 3;
	lvZoom = maxv(1, lvZoom);
    printf("2\n");
	glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA);
    glutInitWindowSize(lvWidth, lvHeight);
    glutCreateWindow("lensview");
    glutDisplayFunc(lvDisplay);
    glutMotionFunc(lvMotion);
    glutMouseFunc(lvClick);
    glutKeyboardFunc(lvKey);
	glutReshapeFunc(lvResize);
    glutIdleFunc(NULL);

	glMatrixMode(GL_MODELVIEW);  glLoadIdentity();
    glMatrixMode(GL_PROJECTION); glLoadIdentity();	
	glClearColor(BGR, BGG, BGB, 1);

    printf("3\n");
	glLineWidth(1);
    printf("4\n");
	lsystem.findIntrinsics();
    printf("5\n");
    lsystem.refocus(zDist, -1);
    printf("6\n");
	glutMainLoop();
	return (0);
}