Пример #1
0
void
material_mouse(int button, int state, int x, int y)
{
    selection = 0;

    if (state == GLUT_DOWN) {
        lighting_mouse(x, y);
        /* mouse should only hit _one_ of the cells, so adding up all
        the hits just propagates a single hit. */
        selection += cell_hit(&material_Ka[0], x, y);
        selection += cell_hit(&material_Ka[1], x, y);
        selection += cell_hit(&material_Ka[2], x, y);
        selection += cell_hit(&material_Ka[3], x, y);
        selection += cell_hit(&material_Kd[0], x, y);
        selection += cell_hit(&material_Kd[1], x, y);
        selection += cell_hit(&material_Kd[2], x, y);
        selection += cell_hit(&material_Kd[3], x, y);
        selection += cell_hit(&material_Ks[0], x, y);
        selection += cell_hit(&material_Ks[1], x, y);
        selection += cell_hit(&material_Ks[2], x, y);
        selection += cell_hit(&material_Ks[3], x, y);
        selection += cell_hit(&material_Ke[0], x, y);
        selection += cell_hit(&material_Ke[1], x, y);
        selection += cell_hit(&material_Ke[2], x, y);
        selection += cell_hit(&material_Ke[3], x, y);
        selection += cell_hit(&material_Se, x, y);
    }

    old_y = y;

    redisplay_all();
}
Пример #2
0
void
main_keyboard(unsigned char key, int x, int y)
{
    switch (key) {
    case 'l':
        mode = GL_LINEAR;
        break;
    case 'e':
        mode = GL_EXP;
        break;
    case 'x':
        mode = GL_EXP2;
        break;
    case 'c':
        clear = !clear;
        break;
    case 'r':
        color[0].value = 0.7;
        color[1].value = 0.7;
        color[2].value = 0.7;
        color[3].value = 1.0;
        density.value = 1.0;
        fstart.value = 0.5;
        fend.value = 2.0;
        break;
    case 27:
        exit(0);
    }
    
    redisplay_all();
}
Пример #3
0
void
main_keyboard(unsigned char key, int x, int y)
{
    switch (key) {
    case 's':
        swapped = !swapped;
        break;
    case 'r':
        translation[0].value = 0.0;
        translation[1].value = 0.0;
        translation[2].value = 0.0;
        rotation[0].value = 0.0;
        rotation[1].value = 0.0;
        rotation[2].value = 1.0;
        rotation[3].value = 0.0;
        scale[0].value = 1.0;
        scale[1].value = 1.0;
        scale[2].value = 1.0;
        break;
    case 27:
        exit(0);
    }
    
    redisplay_all();
}
Пример #4
0
void
command_mouse(int button, int state, int x, int y)
{
    selection = 0;

    if (state == GLUT_DOWN) {
	/* mouse should only hit _one_ of the cells, so adding up all
           the hits just propagates a single hit. */
	selection += cell_hit(&light[0], x, y);
	selection += cell_hit(&light[1], x, y);
	selection += cell_hit(&light[2], x, y);
	selection += cell_hit(&light[3], x, y);
	selection += cell_hit(&lookat[0], x, y);
	selection += cell_hit(&lookat[1], x, y);
	selection += cell_hit(&lookat[2], x, y);
	selection += cell_hit(&lookat[3], x, y);
	selection += cell_hit(&lookat[4], x, y);
	selection += cell_hit(&lookat[5], x, y);
	selection += cell_hit(&lookat[6], x, y);
	selection += cell_hit(&lookat[7], x, y);
	selection += cell_hit(&lookat[8], x, y);
    }

    old_y = y;

    redisplay_all();
}
Пример #5
0
void
main_keyboard(char key, int x, int y)
{
    switch (key) {
    case 's':
        swapped = !swapped;
        break;
    case 'r':
        light[0].value = 1.5;
	light[1].value = 1.0;
	light[2].value = 1.0;
	light[3].value = 0.0;
	lookat[0].value = 0.0;
	lookat[1].value = 0.0;
	lookat[2].value = 2.0;
	lookat[3].value = 0.0;
	lookat[4].value = 0.0;
	lookat[5].value = 0.0;
	lookat[6].value = 0.0;
	lookat[7].value = 1.0;
	lookat[8].value = 0.0;
	break;
    case 27:
	exit(0);
    }

    redisplay_all();
}
Пример #6
0
Файл: texture.c Проект: jvanz/cg
void
matrix_mouse(int button, int state, int x, int y)
{
    selection = 0;
    
    if (state == GLUT_DOWN) {
        polygon_mouse(x, y);
        /* mouse should only hit _one_ of the cells, so adding up all
        the hits just propagates a single hit. */
        selection += cell_hit(&translation[0], x, y);
        selection += cell_hit(&translation[1], x, y);
        selection += cell_hit(&translation[2], x, y);
        selection += cell_hit(&rotation[0], x, y);
        selection += cell_hit(&rotation[1], x, y);
        selection += cell_hit(&rotation[2], x, y);
        selection += cell_hit(&rotation[3], x, y);
        selection += cell_hit(&scale[0], x, y);
        selection += cell_hit(&scale[1], x, y);
        selection += cell_hit(&scale[2], x, y);
    }
    
    old_y = y;
    
    redisplay_all();
}
Пример #7
0
void
command_motion(int x, int y)
{
    cell_update(&perspective[0], old_y-y);
    cell_update(&perspective[1], old_y-y);
    cell_update(&perspective[2], old_y-y);
    cell_update(&perspective[3], old_y-y);
    cell_update(&frustum[0], old_y-y);
    cell_update(&frustum[1], old_y-y);
    cell_update(&frustum[2], old_y-y);
    cell_update(&frustum[3], old_y-y);
    cell_update(&frustum[4], old_y-y);
    cell_update(&frustum[5], old_y-y);
    cell_update(&ortho[0], old_y-y);
    cell_update(&ortho[1], old_y-y);
    cell_update(&ortho[2], old_y-y);
    cell_update(&ortho[3], old_y-y);
    cell_update(&ortho[4], old_y-y);
    cell_update(&ortho[5], old_y-y);
    cell_update(&lookat[0], old_y-y);
    cell_update(&lookat[1], old_y-y);
    cell_update(&lookat[2], old_y-y);
    cell_update(&lookat[3], old_y-y);
    cell_update(&lookat[4], old_y-y);
    cell_update(&lookat[5], old_y-y);
    cell_update(&lookat[6], old_y-y);
    cell_update(&lookat[7], old_y-y);
    cell_update(&lookat[8], old_y-y);
    
    old_y = y;
    
    redisplay_all();
}
Пример #8
0
void
screen_mouse(int button, int state, int x, int y)
{
    old_x = x;
    old_y = y;

    redisplay_all();
}
Пример #9
0
void
screen_motion(int x, int y)
{
    spin_x = x - old_x;
    spin_y = y - old_y;

    redisplay_all();
}
Пример #10
0
void
main_keyboard(unsigned char key, int x, int y)
{
    switch (key) {
    case 'r':
        light_pos[0].value = -2.0;
        light_pos[1].value = 2.0;
        light_pos[2].value = 2.0;
        light_pos[3].value = 1.0;
        light_Ka[0].value = 0;
        light_Ka[1].value = 0;
        light_Ka[2].value = 0;
        light_Ka[3].value = 1;
        light_Kd[0].value = 1;
        light_Kd[1].value = 1;
        light_Kd[2].value = 1;
        light_Kd[3].value = 1;
        light_Ks[0].value = 1;
        light_Ks[1].value = 1;
        light_Ks[2].value = 1;
        light_Ks[3].value = 1;
        spot_direction[0].value = 1.0;
        spot_direction[1].value = -1.0;
        spot_direction[2].value = -1.0;
        spot_exponent.value = 30.0;
        spot_cutoff.value = 91.0;
        Kc.value = 1.0;
        Kl.value = 0.0;
        Kq.value = 0.0;
        new_material(Pewter);
        lmodel_Ka[0].value = 0.2;
        lmodel_Ka[1].value = 0.2;
        lmodel_Ka[2].value = 0.2;
        lmodel_Ka[3].value = 1.0;
        local_viewer.value = 0;
        two_side.value = 0;
        break;
    case 'm':
        glutSetWindow(command);
        glutMouseFunc(material_mouse);
        glutDisplayFunc(material_display);
        break;
    case 's':
        glutSetWindow(command);
        glutMouseFunc(spotlight_mouse);
        glutDisplayFunc(spotlight_display);
        break;
    case 'l':
        glutSetWindow(command);
        glutMouseFunc(lmodel_mouse);
        glutDisplayFunc(lmodel_display);
        break;
    case 27:
        exit(0);
    }

    redisplay_all();
}
Пример #11
0
int
main(int argc, char** argv)
{
    glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
    glutInitWindowSize(512+GAP*3, 512+GAP*3);
    glutInitWindowPosition(50, 50);
    glutInit(&argc, argv);
    
    window = glutCreateWindow("Transformation");
    glutReshapeFunc(main_reshape);
    glutDisplayFunc(main_display);
    glutKeyboardFunc(main_keyboard);
    
    world = glutCreateSubWindow(window, GAP, GAP, 256, 256);
    glutReshapeFunc(world_reshape);
    glutDisplayFunc(world_display);
    glutKeyboardFunc(main_keyboard);
    glutCreateMenu(world_menu);
    glutAddMenuEntry("Toggle model", 'm');
    glutAttachMenu(GLUT_RIGHT_BUTTON);
    
    screen = glutCreateSubWindow(window, GAP+256+GAP, GAP, 256, 256);
    glutReshapeFunc(screen_reshape);
    glutDisplayFunc(screen_display);
    glutKeyboardFunc(main_keyboard);
    glutCreateMenu(screen_menu);
    glutAddMenuEntry("Models", 0);
    glutAddMenuEntry("", 0);
    glutAddMenuEntry("Soccerball", 's');
    glutAddMenuEntry("Al Capone", 'a');
    glutAddMenuEntry("F-16 Jet", 'j');
    glutAddMenuEntry("Dolphins", 'd');
    glutAddMenuEntry("Flowers", 'f');
    glutAddMenuEntry("Porsche", 'p');
    glutAddMenuEntry("Rose", 'r');
    glutAttachMenu(GLUT_RIGHT_BUTTON);
    
    command = glutCreateSubWindow(window, GAP+256+GAP, GAP+256+GAP, 256, 256);
    glutReshapeFunc(command_reshape);
    glutDisplayFunc(command_display);
    glutMotionFunc(command_motion);
    glutMouseFunc(command_mouse);
    glutKeyboardFunc(main_keyboard);
    glutCreateMenu(command_menu);
    glutAddMenuEntry("Projection", 0);
    glutAddMenuEntry("", 0);
    glutAddMenuEntry("[s]  Swap translate/rotate", 's');
    glutAddMenuEntry("[r]  Reset parameters", 'r');
    glutAddMenuEntry("", 0);
    glutAddMenuEntry("Quit", 27);
    glutAttachMenu(GLUT_RIGHT_BUTTON);
    
    redisplay_all();
    
    glutMainLoop();
    
    return 0;
}
Пример #12
0
void
screen_menu(int value)
{
    char* name = 0;

    switch (value) {
    case 'a':
        name = (char*)"../data/al.obj";
        break;
    case 's':
        name = (char*)"../data/soccerball.obj";
        break;
    case 'd':
        name = (char*)"../data/dolphins.obj";
        break;
    case 'f':
        name = (char*)"../data/flowers.obj";
        break;
    case 'j':
        name = (char*)"../data/f-16.obj";
        break;
    case 'p':
        name = (char*)"../data/porsche.obj";
        break;
    case 'r':
        name = (char*)"../data/rose+vase.obj";
        break;
    case 'n':
        if (pmodel) glmDelete(pmodel);
        pmodel = NULL;
        redisplay_all();
        return;
    }

    if (name) {
        if (pmodel) glmDelete(pmodel);
        pmodel = glmReadOBJ(name);
        if (!pmodel) exit(0);
        glmUnitize(pmodel);
        glmFacetNormals(pmodel);
        glmVertexNormals(pmodel, 90.0);
    }

    redisplay_all();
}
Пример #13
0
void
world_menu(int value)
{
    switch (value) {
    case 'm':
        world_draw = !world_draw;
        break;
    }
    redisplay_all();
}
Пример #14
0
Файл: texture.c Проект: jvanz/cg
void
command_motion(int x, int y)
{
    cell_update(&translation[0], old_y-y);
    cell_update(&translation[1], old_y-y);
    cell_update(&translation[2], old_y-y);
    cell_update(&rotation[0], old_y-y);
    cell_update(&rotation[1], old_y-y);
    cell_update(&rotation[2], old_y-y);
    cell_update(&rotation[3], old_y-y);
    cell_update(&scale[0], old_y-y);
    cell_update(&scale[1], old_y-y);
    cell_update(&scale[2], old_y-y);
    cell_update(&texcoords[0], old_y-y);
    cell_update(&texcoords[1], old_y-y);
    cell_update(&texcoords[2], old_y-y);
    cell_update(&texcoords[3], old_y-y);
    cell_update(&texcoords[4], old_y-y);
    cell_update(&texcoords[5], old_y-y);
    cell_update(&texcoords[6], old_y-y);
    cell_update(&texcoords[7], old_y-y);
    cell_update(&vertices[0], old_y-y);
    cell_update(&vertices[1], old_y-y);
    cell_update(&vertices[2], old_y-y);
    cell_update(&vertices[3], old_y-y);
    cell_update(&vertices[4], old_y-y);
    cell_update(&vertices[5], old_y-y);
    cell_update(&vertices[6], old_y-y);
    cell_update(&vertices[7], old_y-y);
    cell_update(&vertices[8], old_y-y);
    cell_update(&vertices[9], old_y-y);
    cell_update(&vertices[10], old_y-y);
    cell_update(&vertices[11], old_y-y);
    cell_update(&pcolor[0], old_y-y);
    cell_update(&pcolor[1], old_y-y);
    cell_update(&pcolor[2], old_y-y);
    cell_update(&pcolor[3], old_y-y);
    cell_update(&bcolor[0], old_y-y);
    cell_update(&bcolor[1], old_y-y);
    cell_update(&bcolor[2], old_y-y);
    cell_update(&bcolor[3], old_y-y);
    cell_update(&ecolor[0], old_y-y);
    cell_update(&ecolor[1], old_y-y);
    cell_update(&ecolor[2], old_y-y);
    cell_update(&ecolor[3], old_y-y);
    
    glutSetWindow(screen);
    texenv();
    glutSetWindow(world);
    texenv();
    
    old_y = y;
    
    redisplay_all();
}
Пример #15
0
void
command_motion(int x, int y)
{
    cell_update(&light_pos[0], old_y-y);
    cell_update(&light_pos[1], old_y-y);
    cell_update(&light_pos[2], old_y-y);
    cell_update(&light_pos[3], old_y-y);
    cell_update(&light_Ka[0], old_y-y);
    cell_update(&light_Ka[1], old_y-y);
    cell_update(&light_Ka[2], old_y-y);
    cell_update(&light_Ka[3], old_y-y);
    cell_update(&light_Kd[0], old_y-y);
    cell_update(&light_Kd[1], old_y-y);
    cell_update(&light_Kd[2], old_y-y);
    cell_update(&light_Kd[3], old_y-y);
    cell_update(&light_Ks[0], old_y-y);
    cell_update(&light_Ks[1], old_y-y);
    cell_update(&light_Ks[2], old_y-y);
    cell_update(&light_Ks[3], old_y-y);
    cell_update(&spot_direction[0], old_y-y);
    cell_update(&spot_direction[1], old_y-y);
    cell_update(&spot_direction[2], old_y-y);
    cell_update(&spot_exponent, old_y-y);
    cell_update(&spot_cutoff, old_y-y);
    cell_update(&Kc, old_y-y);
    cell_update(&Kl, old_y-y);
    cell_update(&Kq, old_y-y);
    cell_update(&material_Ka[0], old_y-y);
    cell_update(&material_Ka[1], old_y-y);
    cell_update(&material_Ka[2], old_y-y);
    cell_update(&material_Ka[3], old_y-y);
    cell_update(&material_Kd[0], old_y-y);
    cell_update(&material_Kd[1], old_y-y);
    cell_update(&material_Kd[2], old_y-y);
    cell_update(&material_Kd[3], old_y-y);
    cell_update(&material_Ks[0], old_y-y);
    cell_update(&material_Ks[1], old_y-y);
    cell_update(&material_Ks[2], old_y-y);
    cell_update(&material_Ks[3], old_y-y);
    cell_update(&material_Ke[0], old_y-y);
    cell_update(&material_Ke[1], old_y-y);
    cell_update(&material_Ke[2], old_y-y);
    cell_update(&material_Ke[3], old_y-y);
    cell_update(&material_Se, old_y-y);
    cell_update(&lmodel_Ka[0], old_y-y);
    cell_update(&lmodel_Ka[1], old_y-y);
    cell_update(&lmodel_Ka[2], old_y-y);
    cell_update(&lmodel_Ka[3], old_y-y);
    cell_update(&local_viewer, old_y-y);
    cell_update(&two_side, old_y-y);

    old_y = y;

    redisplay_all();
}
Пример #16
0
void	cam_3d_viewer_init_display(int xPos, int yPos, int width, int height,
				   unsigned int displayMode, char *windowName,
				   void (*keyboardFuncCallback)(unsigned char, int, int),
				   void (*specialFuncCallback)(int, int, int),
				   void (*mouseFuncCallback)(int, int, int, int),
				   void (*mouseWheelCallback)(int, int, int , int),
 				   void	(*motionCallback)(int, int),
 				   void	(*passiveMotionCallback)(int, int),
				   void (*displayCallback)(void),
				   void (*idleCallback)(void),
				   void (*reshapeCallback)(int, int),
				   int infoWidth, int infoHeight,
				   void (*infoDisplayCallback)(void),
				   void (*infoReshapeCallback)(int, int))
{
  int	ac;

  ac = 0;
  glutInit(&ac, NULL);
  glutInitDisplayMode(displayMode);
  glutInitWindowPosition(xPos, yPos);
  glutInitWindowSize(width, height);
  mainWindow = glutCreateWindow(windowName);

  if (keyboardFuncCallback)
    glutKeyboardFunc(keyboardFuncCallback);
  if (specialFuncCallback)
    glutSpecialFunc(specialFuncCallback);
  glutDisplayFunc(displayCallback);
  if (idleCallback)
    glutIdleFunc(idleCallback);
  if (reshapeCallback)
    glutReshapeFunc(reshapeCallback);
  if (mouseFuncCallback)
    glutMouseFunc(mouseFuncCallback);
  if (mouseWheelCallback)
    glutMouseWheelFunc(mouseWheelCallback);
  if (motionCallback)
    glutMotionFunc(motionCallback);
  if (passiveMotionCallback)
    glutPassiveMotionFunc(passiveMotionCallback);

  info = glutCreateSubWindow(mainWindow, width - infoWidth, height - infoHeight, infoWidth, infoHeight);
  if (infoReshapeCallback)
    glutReshapeFunc(infoReshapeCallback);
  glutDisplayFunc(infoDisplayCallback);
  
  redisplay_all();
}
Пример #17
0
void
command_motion(int x, int y)
{
    cell_update(&color[0], old_y-y);
    cell_update(&color[1], old_y-y);
    cell_update(&color[2], old_y-y);
    cell_update(&color[3], old_y-y);
    cell_update(&fstart, old_y-y);
    cell_update(&fend, old_y-y);
    cell_update(&density, old_y-y);
    
    old_y = y;
    
    redisplay_all();
}
Пример #18
0
void
main_keyboard(unsigned char key, int x, int y)
{
    switch (key) {
    case 'p':
        mode = PERSPECTIVE;
        break;
    case 'o':
        mode = ORTHO;
        break;
    case 'f':
        mode = FRUSTUM;
        break;
    case 'r':
        perspective[0].value = 60.0;
        perspective[1].value = 1.0;
        perspective[2].value = 1.0;
        perspective[3].value = 10.0;
        ortho[0].value = -1.0;
        ortho[1].value = 1.0;
        ortho[2].value = -1.0;
        ortho[3].value = 1.0;
        ortho[4].value = 1.0;
        ortho[5].value = 3.5;
        frustum[0].value = -1.0;
        frustum[1].value = 1.0;
        frustum[2].value = -1.0;
        frustum[3].value = 1.0;
        frustum[4].value = 1.0;
        frustum[5].value = 3.5;
        lookat[0].value = 0.0;
        lookat[1].value = 0.0;
        lookat[2].value = 2.0;
        lookat[3].value = 0.0;
        lookat[4].value = 0.0;
        lookat[5].value = 0.0;
        lookat[6].value = 0.0;
        lookat[7].value = 1.0;
        lookat[8].value = 0.0;
        break;
    case 27:
        exit(0);
    }
    
    redisplay_all();
}
Пример #19
0
void
command_motion(int x, int y)
{
    cell_update(&translation[0], old_y-y);
    cell_update(&translation[1], old_y-y);
    cell_update(&translation[2], old_y-y);
    cell_update(&rotation[0], old_y-y);
    cell_update(&rotation[1], old_y-y);
    cell_update(&rotation[2], old_y-y);
    cell_update(&rotation[3], old_y-y);
    cell_update(&scale[0], old_y-y);
    cell_update(&scale[1], old_y-y);
    cell_update(&scale[2], old_y-y);
    
    old_y = y;
    
    redisplay_all();
}
Пример #20
0
void
command_mouse(int button, int state, int x, int y)
{
    selection = 0;
    
    if (state == GLUT_DOWN) {
        if (mode == PERSPECTIVE) {
        /* mouse should only hit _one_ of the cells, so adding up all
            the hits just propagates a single hit. */
            selection += cell_hit(&perspective[0], x, y);
            selection += cell_hit(&perspective[1], x, y);
            selection += cell_hit(&perspective[2], x, y);
            selection += cell_hit(&perspective[3], x, y);
        } else if (mode == FRUSTUM) {
            selection += cell_hit(&frustum[0], x, y);
            selection += cell_hit(&frustum[1], x, y);
            selection += cell_hit(&frustum[2], x, y);
            selection += cell_hit(&frustum[3], x, y);
            selection += cell_hit(&frustum[4], x, y);
            selection += cell_hit(&frustum[5], x, y);
        } else if (mode == ORTHO) {
            selection += cell_hit(&ortho[0], x, y);
            selection += cell_hit(&ortho[1], x, y);
            selection += cell_hit(&ortho[2], x, y);
            selection += cell_hit(&ortho[3], x, y);
            selection += cell_hit(&ortho[4], x, y);
            selection += cell_hit(&ortho[5], x, y);
        }
        selection += cell_hit(&lookat[0], x, y);
        selection += cell_hit(&lookat[1], x, y);
        selection += cell_hit(&lookat[2], x, y);
        selection += cell_hit(&lookat[3], x, y);
        selection += cell_hit(&lookat[4], x, y);
        selection += cell_hit(&lookat[5], x, y);
        selection += cell_hit(&lookat[6], x, y);
        selection += cell_hit(&lookat[7], x, y);
        selection += cell_hit(&lookat[8], x, y);
    }
    
    old_y = y;
    
    redisplay_all();
}
Пример #21
0
void
command_motion(int x, int y)
{
    cell_update(&light[0], old_y-y);
    cell_update(&light[1], old_y-y);
    cell_update(&light[2], old_y-y);
    cell_update(&light[3], old_y-y);
    cell_update(&lookat[0], old_y-y);
    cell_update(&lookat[1], old_y-y);
    cell_update(&lookat[2], old_y-y);
    cell_update(&lookat[3], old_y-y);
    cell_update(&lookat[4], old_y-y);
    cell_update(&lookat[5], old_y-y);
    cell_update(&lookat[6], old_y-y);
    cell_update(&lookat[7], old_y-y);
    cell_update(&lookat[8], old_y-y);
    
    old_y = y;
    
    redisplay_all();
}
Пример #22
0
void
lmodel_mouse(int button, int state, int x, int y)
{
    selection = 0;

    if (state == GLUT_DOWN) {
        lighting_mouse(x, y);
        /* mouse should only hit _one_ of the cells, so adding up all
        the hits just propagates a single hit. */
        selection += cell_hit(&lmodel_Ka[0], x, y);
        selection += cell_hit(&lmodel_Ka[1], x, y);
        selection += cell_hit(&lmodel_Ka[2], x, y);
        selection += cell_hit(&lmodel_Ka[3], x, y);
        selection += cell_hit(&local_viewer, x, y);
        selection += cell_hit(&two_side, x, y);
    }

    old_y = y;

    redisplay_all();
}
Пример #23
0
void
spotlight_mouse(int button, int state, int x, int y)
{
    selection = 0;

    if (state == GLUT_DOWN) {
        lighting_mouse(x, y);
        /* mouse should only hit _one_ of the cells, so adding up all
        the hits just propagates a single hit. */
        selection += cell_hit(&spot_direction[0], x, y);
        selection += cell_hit(&spot_direction[1], x, y);
        selection += cell_hit(&spot_direction[2], x, y);
        selection += cell_hit(&spot_exponent, x, y);
        selection += cell_hit(&spot_cutoff, x, y);
        selection += cell_hit(&Kc, x, y);
        selection += cell_hit(&Kl, x, y);
        selection += cell_hit(&Kq, x, y);
    }

    old_y = y;

    redisplay_all();
}
Пример #24
0
Файл: texture.c Проект: jvanz/cg
void
world_menu(int value)
{
    char* name = 0;
    
    switch (value) {
    case 'f':
        name = "data/fishermen.ppm";
        break;
    case 'o':
        name = "data/opengl.ppm";
        break;
    case 'c':
        name = "data/checker.ppm";
        break;
    case 'm':
        name = "data/marble.ppm";
        break;
    case 't':
        name = "data/train.ppm";
        break;
    }
    
    if (name) {
        free(image);
        image = glmReadPPM(name, &iwidth, &iheight);
        if (!image)
            image = glmReadPPM("data/fishermen.ppm", &iwidth, &iheight);
    }
    
    glutSetWindow(screen);
    texture();
    glutSetWindow(world);
    texture();
    
    redisplay_all();
}
Пример #25
0
void
command_mouse(int button, int state, int x, int y)
{
    selection = 0;
    
    if (state == GLUT_DOWN) {
    /* mouse should only hit _one_ of the cells, so adding up all
        the hits just propagates a single hit. */
        selection += cell_hit(&color[0], x, y);
        selection += cell_hit(&color[1], x, y);
        selection += cell_hit(&color[2], x, y);
        selection += cell_hit(&color[3], x, y);
        if (mode == GL_LINEAR) {
            selection += cell_hit(&fstart, x, y);
            selection += cell_hit(&fend, x, y);
        } else {
            selection += cell_hit(&density, x, y);
        }
    }
    
    old_y = y;
    
    redisplay_all();
}
Пример #26
0
void
world_menu(int value)
{
    switch (value) {
    case 1:
        new_material(Brass);
        break;
    case 2:
        new_material(Bronze);
        break;
    case 3:
        new_material(Polished_Bronze);
        break;
    case 4:
        new_material(Chrome);
        break;
    case 5:
        new_material(Copper);
        break;
    case 6:
        new_material(Polished_Copper);
        break;
    case 7:
        new_material(Gold);
        break;
    case 8:
        new_material(Polished_Gold);
        break;
    case 9:
        new_material(Pewter);
        break;
    case 10:
        new_material(Silver);
        break;
    case 11:
        new_material(Polished_Silver);
        break;
    case 12:
        new_material(Emerald);
        break;
    case 13:
        new_material(Jade);
        break;
    case 14:
        new_material(Obsidian);
        break;
    case 15:
        new_material(Pearl);
        break;
    case 16:
        new_material(Ruby);
        break;
    case 17:
        new_material(Turquoise);
        break;
    case 18:
        new_material(Black_Plastic);
        break;
    case 19:
        new_material(Black_Rubber);
        break;
    }

    redisplay_all();
}
Пример #27
0
int
main(int argc, char** argv)
{
    glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
    glutInitWindowSize((512+GAP*3)*3/2, 512+GAP*3);
    glutInitWindowPosition(50, 50);
    glutInit(&argc, argv);

    window = glutCreateWindow("Light & Material");
    glutReshapeFunc(main_reshape);
    glutDisplayFunc(main_display);
    glutKeyboardFunc(main_keyboard);

    world = glutCreateSubWindow(window, GAP, GAP, 256, 256);
    glutReshapeFunc(world_reshape);
    glutDisplayFunc(world_display);
    glutKeyboardFunc(main_keyboard);
    glutCreateMenu(world_menu);
    glutAddMenuEntry("Materials", 0);
    glutAddMenuEntry("", 0);
    glutAddMenuEntry("Brass", 1);
    glutAddMenuEntry("Bronze", 2);
    glutAddMenuEntry("Polished_Bronze", 3);
    glutAddMenuEntry("Chrome", 4);
    glutAddMenuEntry("Copper", 5);
    glutAddMenuEntry("Polished_Copper", 6);
    glutAddMenuEntry("Gold", 7);
    glutAddMenuEntry("Polished_Gold", 8);
    glutAddMenuEntry("Pewter", 9);
    glutAddMenuEntry("Silver", 10);
    glutAddMenuEntry("Polished_Silver", 11);
    glutAddMenuEntry("Emerald", 12);
    glutAddMenuEntry("Jade", 13);
    glutAddMenuEntry("Obsidian", 14);
    glutAddMenuEntry("Pearl", 15);
    glutAddMenuEntry("Ruby", 16);
    glutAddMenuEntry("Turquoise", 17);
    glutAddMenuEntry("Black_Plastic", 18);
    glutAddMenuEntry("Black_Rubber", 19);
    glutAttachMenu(GLUT_RIGHT_BUTTON);

    screen = glutCreateSubWindow(window, GAP+256+GAP, GAP, 256, 256);
    glutReshapeFunc(screen_reshape);
    glutDisplayFunc(screen_display);
    glutKeyboardFunc(main_keyboard);
    glutMotionFunc(screen_motion);
    glutMouseFunc(screen_mouse);
    glutCreateMenu(screen_menu);
    glutAddMenuEntry("Models", 0);
    glutAddMenuEntry("", 0);
    glutAddMenuEntry("Torus", 'n');
    glutAddMenuEntry("Flat plane", 'l');
    glutAddMenuEntry("Soccerball", 's');
    glutAddMenuEntry("Al Capone", 'a');
    glutAddMenuEntry("F-16 Jet", 'j');
    glutAddMenuEntry("Dolphins", 'd');
    glutAddMenuEntry("Flowers", 'f');
    glutAddMenuEntry("Porsche", 'p');
    glutAddMenuEntry("Rose", 'r');
    glutAttachMenu(GLUT_RIGHT_BUTTON);

    command = glutCreateSubWindow(window, GAP+256+GAP, GAP+256+GAP, 256, 256);
    glutReshapeFunc(command_reshape);
    glutDisplayFunc(material_display);
    glutMotionFunc(command_motion);
    glutMouseFunc(material_mouse);
    glutKeyboardFunc(main_keyboard);
    glutCreateMenu(command_menu);
    glutAddMenuEntry("Light & Material", 0);
    glutAddMenuEntry("", 0);
    glutAddMenuEntry("Material parameters", 'm');
    glutAddMenuEntry("Light model parameters", 'l');
    glutAddMenuEntry("Spotlight & attenuation", 's');
    glutAddMenuEntry("Reset parameters (r)", 'r');
    glutAddMenuEntry("", 0);
    glutAddMenuEntry("Quit", 27);
    glutAttachMenu(GLUT_RIGHT_BUTTON);

    new_material(Pewter);
    redisplay_all();

    glutMainLoop();
    return 0;
}
Пример #28
0
Файл: texture.c Проект: jvanz/cg
void
main_keyboard(unsigned char key, int x, int y)
{
    switch (key) {
    case 'm':
        glutSetWindow(command);
        glutMouseFunc(matrix_mouse);
        glutDisplayFunc(matrix_display);
        break;
    case 'p':
        glutSetWindow(command);
        glutMouseFunc(parameters_mouse);
        glutDisplayFunc(parameters_display);
        break;
    case 'r':
        translation[0].value = 0.0;
        translation[1].value = 0.0;
        translation[2].value = 0.0;
        rotation[0].value = 0.0;
        rotation[1].value = 0.0;
        rotation[2].value = 0.0;
        rotation[3].value = 1.0;
        scale[0].value = 1.0;
        scale[1].value = 1.0;
        scale[2].value = 1.0;
        texcoords[0].value = 0.0;
        texcoords[1].value = 0.0;
        texcoords[2].value = 1.0;
        texcoords[3].value = 0.0;
        texcoords[4].value = 1.0;
        texcoords[5].value = 1.0;
        texcoords[6].value = 0.0;
        texcoords[7].value = 1.0;
        vertices[0].value = -1.0;
        vertices[1].value = -1.0;
        vertices[2].value = 0.0;
        vertices[3].value = 1.0;
        vertices[4].value = -1.0;
        vertices[5].value = 0.0;
        vertices[6].value = 1.0;
        vertices[7].value = 1.0;
        vertices[8].value = 0.0;
        vertices[9].value = -1.0;
        vertices[10].value = 1.0;
        vertices[11].value = 0.0;
        pcolor[0].value = 0.6;
        pcolor[1].value = 0.6;
        pcolor[2].value = 0.6;
        pcolor[3].value = 0.6;
        bcolor[0].value = 1.0;
        bcolor[1].value = 0.0;
        bcolor[2].value = 0.0;
        bcolor[3].value = 1.0;
        ecolor[0].value = 0.0;
        ecolor[1].value = 1.0;
        ecolor[2].value = 0.0;
        ecolor[3].value = 1.0;
        minfilter = GL_NEAREST;
        magfilter = GL_NEAREST;
        env = GL_MODULATE;
        wraps = GL_REPEAT;
        wrapt = GL_REPEAT;
        break;
    case 27:
        exit(0);
    }
    
    glutSetWindow(screen);
    texenv();
    redisplay_all();
}
Пример #29
0
Файл: texture.c Проект: jvanz/cg
int
main(int argc, char** argv)
{
    image = glmReadPPM("data/terra.ppm", &iwidth, &iheight);
    if (!image)
        exit(0);
    
    glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
    glutInitWindowSize((512+GAP*3)*3/2, 512+GAP*3);
    glutInitWindowPosition(50, 50);
    glutInit(&argc, argv);
    
    window = glutCreateWindow("Texture");
    glutReshapeFunc(main_reshape);
    glutDisplayFunc(main_display);
    glutKeyboardFunc(main_keyboard);
    
    world = glutCreateSubWindow(window, GAP, GAP, 256, 256);
    glutReshapeFunc(world_reshape);
    glutDisplayFunc(world_display);
    glutKeyboardFunc(main_keyboard);
    glutCreateMenu(world_menu);
    glutAddMenuEntry("Textures", 0);
    glutAddMenuEntry("", 0);
    glutAddMenuEntry("Fishermen", 'f');
    glutAddMenuEntry("OpenGL Logo", 'o');
    glutAddMenuEntry("Checker", 'c');
    glutAddMenuEntry("Marble", 'm');
    glutAddMenuEntry("Train", 't');
    glutAttachMenu(GLUT_RIGHT_BUTTON);
    
    texture();
    
    screen = glutCreateSubWindow(window, GAP+256+GAP, GAP, 256, 256);
    glutReshapeFunc(screen_reshape);
    glutDisplayFunc(screen_display);
    glutKeyboardFunc(main_keyboard);
    glutMotionFunc(screen_motion);
    glutMouseFunc(screen_mouse);
    
    texture();
    
    command = glutCreateSubWindow(window, GAP+256+GAP, GAP+256+GAP, 256, 256);
    glutReshapeFunc(command_reshape);
    glutMotionFunc(command_motion);
    glutDisplayFunc(parameters_display);
    glutMouseFunc(parameters_mouse);
    glutKeyboardFunc(main_keyboard);
    glutCreateMenu(command_menu);
    glutAddMenuEntry("Texture", 0);
    glutAddMenuEntry("", 0);
    glutAddMenuEntry("Matrix", 'm');
    glutAddMenuEntry("Environment/Parameters", 'p');
    glutAddMenuEntry("Reset parameters (r)", 'r');
    glutAddMenuEntry("", 0);
    glutAddMenuEntry("Quit", 27);
    glutAttachMenu(GLUT_RIGHT_BUTTON);
    
    redisplay_all();
    
    glutTimerFunc(500, timer, 0);
    glutMainLoop();
    return 0;
}
Пример #30
0
Файл: texture.c Проект: jvanz/cg
void
parameters_mouse(int button, int state, int x, int y)
{
    selection = 0;
    
    if (state == GLUT_DOWN) {
        polygon_mouse(x, y);
        selection += cell_hit(&bcolor[0], x, y);
        selection += cell_hit(&bcolor[1], x, y);
        selection += cell_hit(&bcolor[2], x, y);
        selection += cell_hit(&bcolor[3], x, y);
        selection += cell_hit(&ecolor[0], x, y);
        selection += cell_hit(&ecolor[1], x, y);
        selection += cell_hit(&ecolor[2], x, y);
        selection += cell_hit(&ecolor[3], x, y);
        if (!selection) {
            if (y < 145 && y > 125) {
                if (minfilter == GL_NEAREST)
                    minfilter = GL_LINEAR;
                else if (minfilter == GL_LINEAR)
                    minfilter = GL_NEAREST_MIPMAP_NEAREST;
                else if (minfilter == GL_NEAREST_MIPMAP_NEAREST)
                    minfilter = GL_NEAREST_MIPMAP_LINEAR;
                else if (minfilter == GL_NEAREST_MIPMAP_LINEAR)
                    minfilter = GL_LINEAR_MIPMAP_NEAREST;
                else if (minfilter == GL_LINEAR_MIPMAP_NEAREST)
                    minfilter = GL_LINEAR_MIPMAP_LINEAR;
                else 
                    minfilter = GL_NEAREST;
            } else if (y < 165 && y > 145) {
                if (magfilter == GL_NEAREST)
                    magfilter = GL_LINEAR;
                else
                    magfilter = GL_NEAREST;
            } else if (y < 185 && y > 165) {
                if (wraps == GL_REPEAT)
                    wraps = GL_CLAMP;
                else
                    wraps = GL_REPEAT;
            } else if (y < 205 && y > 185) {
                if (wrapt == GL_REPEAT)
                    wrapt = GL_CLAMP;
                else
                    wrapt = GL_REPEAT;
            } else if (y < 225 && y > 205) {
                if (env == GL_REPLACE_EXT)
                    env = GL_DECAL;
                else if (env == GL_DECAL)
                    env = GL_BLEND;
                else if (env == GL_BLEND)
                    env = GL_MODULATE;
                else
                    env = GL_REPLACE_EXT;
            }
        }
    }
    
    glutSetWindow(screen);
    texenv();
    glutSetWindow(world);
    texenv();
    
    old_y = y;
    
    redisplay_all();
}