예제 #1
0
void keyPress(unsigned char key, int x, int y) {
    switch (key) {
        case 'f':
            baseTime = currentTime = glutGet(GLUT_ELAPSED_TIME);
            isPlaying = 1;
            playingForward = 1;
            playingBackward = 0;
            break;

        case 'b':
            baseTime = currentTime = glutGet(GLUT_ELAPSED_TIME);
            isPlaying = 1;
            playingForward = 0;
            playingBackward = 1;
            break;

        case 's':
            baseTime = currentTime = glutGet(GLUT_ELAPSED_TIME);
            isPlaying = 0;
            break;

        case 'd':
            aClip.deleteKeyframeAtCurrent();
            break;

        case 32: // Space stores current frame as keyframe
            Keyframe k_;
            k_.getKeyframeFromRobot(robot);
            aClip.addKeyframeAtCurrent(k_);
            break;
    }
    glutPostRedisplay();
}
예제 #2
0
/*
 * Written by Robert "Chip" Senkbeil
 * Uses -lglut, -lGLU, and -lGL to compile on Linux.
 */
int main(int argc, char** argv) {
  glutInit(&argc, argv);
  glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
  glutInitWindowPosition(0, 0);
  glutInitWindowSize(640, 640);
  glutCreateWindow(argv[0]);
  glEnable(GL_DEPTH_TEST);
  glEnable(GL_NORMALIZE);

  //glutReshapeFunc(/* ... */);
  glutSpecialFunc(arrowPress);
  glutKeyboardFunc(keyPress);
  glutMouseFunc(mouseEvent);
  glutMotionFunc(mouseMoveEvent);
  glutDisplayFunc(render);
  glutIdleFunc(idleEvent);

  // Build and attach the menu
  buildPopupMenu();
  glutAttachMenu(GLUT_RIGHT_BUTTON);

  // Allocate memory for a new robot
  printf("Allocating new robot...\n");
  robot = new Robot();

  // Add robot initial keyframe to animation clip
  {
    Keyframe k_;
    k_.getKeyframeFromRobot(robot);
    aClip.addKeyframeAtCurrent(k_);
  }

  printf("Setting up the camera...\n");
  camera.setCameraMaxDistance(4.0f);
  //camera.lock();

  // Set default fps
  framesPerSecond = DEFAULT_FRAMES_PER_SECOND;
  isPlaying = 0;
  playingForward = 1;
  playingBackward = 0;
  currentTime = 0;
  baseTime = 0;
  frames = 0;
  framesTotal = 0;

  // Set termination callback
  atexit(terminate_prog);

  // Enable lighting
  setupLight();

  // Setup a global material
  initMaterial();

  // Enable texture
  glEnable(GL_TEXTURE_2D);
  robot->loadTexture("texture/CorrugatedSharp.png");

  // Start the main loop
  glutMainLoop();

  // Exit program
  return 0;
}