//////////////////////////////////////////////////////////////////////////////////
// Load up a new motion captured frame
//////////////////////////////////////////////////////////////////////////////////
void SetSkeletonsToSpecifiedFrame(int frameIndex)
{
  if (frameIndex < 0)
  {
    printf("Error in SetSkeletonsToSpecifiedFrame: frameIndex %d is illegal.\n", frameIndex);
    exit(0);
  }
  if (displayer.GetSkeletonMotion(0) != NULL)
  {
    int postureID;
    if (frameIndex >= displayer.GetSkeletonMotion(0)->GetNumFrames())
      postureID = displayer.GetSkeletonMotion(0)->GetNumFrames() - 1;
    else 
      postureID = frameIndex;
    displayer.GetSkeleton(0)->setPosture(* (displayer.GetSkeletonMotion(0)->GetPosture(postureID)));
  }
}
예제 #2
0
void resetPostureAccordingFrameSlider(void)
{
  currentFrameIndex = (int)frame_slider->value() - 1;
  currentFrameIndexDoublePrecision = currentFrameIndex;

  // display
  for (int skeletonIndex = 0; skeletonIndex < displayer.GetNumSkeletons(); skeletonIndex++)
  {
    int postureID;
    if (currentFrameIndex >= displayer.GetSkeletonMotion(skeletonIndex)->GetNumFrames())
      postureID = displayer.GetSkeletonMotion(skeletonIndex)->GetNumFrames() - 1;
    else
      postureID = currentFrameIndex;
    // Set skeleton to the first posture
    Posture * currentPosture = displayer.GetSkeletonMotion(skeletonIndex)->GetPosture(postureID);
    displayer.GetSkeleton(skeletonIndex)->setPosture(*currentPosture);
  }
}
예제 #3
0
void UpdateMaxFrameNumber(void)
{
  maxFrames = 0;
  for(int skeletonIndex = 0; skeletonIndex < displayer.GetNumSkeletons(); skeletonIndex++)
  {
    int currentFrames = displayer.GetSkeletonMotion(skeletonIndex)->GetNumFrames();
    if (currentFrames > maxFrames)
      maxFrames = currentFrames;
  }
}
//////////////////////////////////////////////////////////////////////////////////
// Called occasionally to see if anything's happening
//////////////////////////////////////////////////////////////////////////////////
void idle()
{
  // load up the next motion capture frame
  SetSkeletonsToSpecifiedFrame(currentFrameIndex);

  if (animate)
    currentFrameIndex+=2;

  // if we've reached the end of the motion capture sequence,
  // start over from frome 0
  int totalFrames = displayer.GetSkeletonMotion(0)->GetNumFrames();
  if (currentFrameIndex >= maxFrameIndex)
  {
    currentFrameIndex = 0;
    cout << " Hit end frame, exiting" << endl;
    exit(0);
  }

  glutPostRedisplay();
}
예제 #5
0
int main(int argc, char **argv) 
{
  // Initialize form, sliders and buttons
  form = make_window();

  performanceCounter.StartCounter();  // init
  saveFileTimeCounter.StartCounter(); // init

  groundPlane_button->value(groundPlane);
  fog_button->value(useFog);
  worldAxes_button->value(renderWorldAxes);
  frame_slider->value(1);
  if (saveScreenToFile == SAVE_CONTINUOUS)
    record_button->value(1);  // ON
  else
    record_button->value(0);  // OFF

  // just do some timing, no special purpose
  // because the first data is always not trustable according to experience
  performanceCounter.StopCounter(); 
  performanceCounter.GetElapsedTime();
  saveFileTimeCounter.StopCounter();
  saveFileTimeCounter.GetElapsedTime();
  performanceCounter.StartCounter();
  // show form, and do initial draw of model
  form->show();
  glwindow->show(); // glwindow is initialized when the form is built
  performanceCounter.StopCounter();

  if (argc > 2)
  {
    char *filename;

    filename = argv[1];
    if(filename != NULL)
    {
      //Read skeleton from asf file
      pSkeleton = new Skeleton(filename, MOCAP_SCALE);

      //Set the rotations for all bones in their local coordinate system to 0
      //Set root position to (0, 0, 0)
      pSkeleton->setBasePosture();
      displayer.LoadSkeleton(pSkeleton);
      lastSkeleton++;
    }

    if (displayer.GetNumSkeletons())
    {
      filename = argv[2];
      if(filename != NULL)
      {
        //Read motion (.amc) file and create a motion
        pMotion = new Motion(filename, MOCAP_SCALE,pSkeleton);

        //set sampled motion for display
        displayer.LoadMotion(pMotion);               
        
        lastMotion++;

        //Tell skeleton to perform the first pose ( first posture )
        pSkeleton->setPosture(*(displayer.GetSkeletonMotion(0)->GetPosture(0)));          

        // Set skeleton to perform the first pose ( first posture )         
        int currentFrames = displayer.GetSkeletonMotion(0)->GetNumFrames();
        if (currentFrames > maxFrames)
        {
          maxFrames = currentFrames;
          frame_slider->maximum((double)maxFrames);

        }
        frame_slider->maximum((double)maxFrames);

        currentFrameIndex=0;
      } // if(filename != NULL)
    }
    else
      printf("Load a skeleton first.\n");
    framesIncrementDoublePrecision = 1.0;            // Current frame and frame increment
    playButton = ON;
    repeatButton = OFF;
    groundPlane = ON; 
    glwindow->redraw();
  }  // if (argc > 2)
  Fl::add_idle(idle);
  return Fl::run();
}
예제 #6
0
void idle(void*)
{
  if (previousPlayButtonStatus == ON)  
  {
    // it means we should measure the interval between two frames
    // if it is too tiny, we should slow down the motion
    performanceCounter.StopCounter();
    double actualTimeCostOneFrame = performanceCounter.GetElapsedTime(); // in seconds

    // time spent on saving the screen in previous time-step should be excluded
    if (saveFileTimeCost > 0.0)   
      actualTimeCostOneFrame -= saveFileTimeCost;

    framesIncrementDoublePrecision = actualTimeCostOneFrame * expectedFPS;
  }
  // start counter at the beginning of the new round
  if (playButton == ON)
    performanceCounter.StartCounter();

  if(rewindButton == ON)
  {
    currentFrameIndex = 0;
    currentFrameIndexDoublePrecision = 0.0;
    for (int i = 0; i < displayer.GetNumSkeletons(); i++)
    {
      if (displayer.GetSkeletonMotion(i) != NULL)
      {
        Posture * initSkeleton = displayer.GetSkeletonMotion(i)->GetPosture(0);
        displayer.GetSkeleton(i)->setPosture(*initSkeleton);
      }
    }
    rewindButton = OFF;
  }

  // Initialization
  saveFileTimeCost = -1.0;

  if(playButton == ON) 
  {
    if (saveScreenToFile == SAVE_CONTINUOUS)
    {
      saveFileTimeCounter.StartCounter();
      CreateScreenFilename(SAVE_CONTINUOUS, saveScreenToFileContinuousCount, saveScreenToFileContinuousFilename);
      saveScreenshot(640, 480, saveScreenToFileContinuousFilename);
      printf("%s is saved to disk.\n", saveScreenToFileContinuousFilename);
      saveScreenToFileContinuousCount++;
      saveFileTimeCounter.StopCounter();
      saveFileTimeCost = saveFileTimeCounter.GetElapsedTime();
    }

    if (saveScreenToFile == SAVE_CONTINUOUS)
    {
      currentFrameIndexDoublePrecision += 1.0;
    }
    else
    {
      currentFrameIndexDoublePrecision += framesIncrementDoublePrecision;
    }

    currentFrameIndex = (int)currentFrameIndexDoublePrecision;

    if(currentFrameIndex >= maxFrames)
    {
      if (repeatButton == ON)
      {
        currentFrameIndex = 0;
        currentFrameIndexDoublePrecision = 0.0;
      }
      else  // repeat button is OFF
      {
        currentFrameIndex = maxFrames - 1;
        currentFrameIndexDoublePrecision = currentFrameIndex;
        playButton = OFF;  // important, especially in "recording" mode
      }
    }

    if (currentFrameIndex < 0)
    {
      currentFrameIndex = 0;
      currentFrameIndexDoublePrecision = 0.0;
    }

    SetSkeletonsToSpecifiedFrame(currentFrameIndex);

    frame_slider->value((double) currentFrameIndex + 1);
  }  // if(playButton == ON)

  if (minusOneButton == ON)
    if (displayer.GetNumSkeletons() != 0)
    {
      currentFrameIndex--;
      if (currentFrameIndex < 0)
        currentFrameIndex = 0;
      frame_slider->value((double) currentFrameIndex + 1);

      SetSkeletonsToSpecifiedFrame(currentFrameIndex);    
      if (saveScreenToFile == SAVE_CONTINUOUS)
      {
        CreateScreenFilename(SAVE_CONTINUOUS, saveScreenToFileContinuousCount, saveScreenToFileContinuousFilename);
        saveScreenshot(640, 480, saveScreenToFileContinuousFilename);
        printf("%s is saved to disk.\n", saveScreenToFileContinuousFilename);
        saveScreenToFileContinuousCount++;
      }
      minusOneButton = OFF;
    }

  if (plusOneButton == ON)
  {
    if (displayer.GetNumSkeletons() != 0)
    {
      currentFrameIndex++;
      if (currentFrameIndex >= maxFrames)
        currentFrameIndex = maxFrames - 1;
      frame_slider->value((double) currentFrameIndex + 1);

      SetSkeletonsToSpecifiedFrame(currentFrameIndex);
      if (saveScreenToFile == SAVE_CONTINUOUS)
      {
        CreateScreenFilename(SAVE_CONTINUOUS, saveScreenToFileContinuousCount, saveScreenToFileContinuousFilename);
        saveScreenshot(640, 480, saveScreenToFileContinuousFilename);
        printf("%s is saved to disk.\n", saveScreenToFileContinuousFilename);
        saveScreenToFileContinuousCount++;
      }
      plusOneButton = OFF;
    }
  }

  frame_slider->value((double)(currentFrameIndex + 1));

  previousPlayButtonStatus = playButton; // Super important updating

  glwindow->redraw();
}
int main(int argc, char** argv)
{
    // init frame dimensions and buffer
    width = windowWidth;//800;
    height = windowHeight;//600;
    pixels = new unsigned char[3*width*height];

    if(argc==3)
    {
        currentFrameIndex = atoi(argv[1]);
        maxFrameIndex = atoi(argv[2]);
    }


    // init camera
    fovy = 65;
    nearz = 1;
    neary = nearz * tan(fovy/2 * (PI/180));
    nearx = neary * ((float)width/(float)height);
    eye = Vector3(-5, 1, -5);
    focus= Vector3(0, 1, 0);
    up = Vector3(0, 1, 0);

    // init scene objects
    numObjects = 0;
    boneIndex=-1;
    objsPerBone=0;
    // spheres
    numSpheres=0;
    spheres[numSpheres] = new Sphere(Vector3(0, -1000, 0), 1000, Vector3(0.5, 0.5, 0.5), MAT_DIFFUSE);
    objects[numObjects++] = spheres[numSpheres++];
    spheres[numSpheres] = new Sphere(Vector3(-1.5, 2, 3), 0.2, Vector3(0, 0, 1), MAT_DIFFUSE);
    objects[numObjects++] = spheres[numSpheres++];
    //cylinders
    numCylinders=0;
    Matrix3 rot = getRotationMatrix(90, 1, 0, 0);
    cylinders[numCylinders]= new Cylinder(Vector3(-1.5, 0.5, 3), 0.2, 1.5, rot, Vector3(0, 0, 1), MAT_DIFFUSE);
    objects[numObjects++] = cylinders[numCylinders++];
    cylinders[numCylinders]= new Cylinder(Vector3(-1.5, 2, 3), 0.005, 2, rot, Vector3(0.8, 0.8, 0.8), MAT_DIFFUSE);
    objects[numObjects++] = cylinders[numCylinders++];
    // dumbells
    float l = 0.35;
    Vector3 pos = Vector3(-3, 0.07, 3);
    rot = getRotationMatrix(120, 0, 1, 0);
    spheres[numSpheres] = new Sphere(pos, 0.07, Vector3(0.2, 0.2, 0.2), MAT_DIFFUSE);
    objects[numObjects++] = spheres[numSpheres++];
    spheres[numSpheres] = new Sphere(pos+(rot*Vector3(0, 0, l)), 0.07, Vector3(0.2, 0.2, 0.2), MAT_DIFFUSE);
    objects[numObjects++] = spheres[numSpheres++];
    cylinders[numCylinders]= new Cylinder(pos, 0.02, l, rot, Vector3(0.2, 0.2, 0.2), MAT_DIFFUSE);
    objects[numObjects++] = cylinders[numCylinders++];
    
    pos = Vector3(-3.5, 0.07, 3.4);
    rot = getRotationMatrix(170, 0, 1, 0);
    spheres[numSpheres] = new Sphere(pos, 0.07, Vector3(0.2, 0.2, 0.2), MAT_DIFFUSE);
    objects[numObjects++] = spheres[numSpheres++];
    spheres[numSpheres] = new Sphere(pos+(rot*Vector3(0, 0, l)), 0.07, Vector3(0.2, 0.2, 0.2), MAT_DIFFUSE);
    objects[numObjects++] = spheres[numSpheres++];
    cylinders[numCylinders]= new Cylinder(pos, 0.02, l, rot, Vector3(0.2, 0.2, 0.2), MAT_DIFFUSE);
    objects[numObjects++] = cylinders[numCylinders++];

    //triangles
    numTriangles=0;
    Vector3 ah = Vector3( 2, 3,  5); Vector3 al = Vector3( 2, 0,  5);
    Vector3 bh = Vector3(-5, 3,  5); Vector3 bl = Vector3(-5, 0,  5);
    Vector3 ch = Vector3( 2, 3, -2); Vector3 cl = Vector3( 2, 0, -2);
    Vector3 dh = Vector3(-5, 3, -2); Vector3 dl = Vector3(-5, 0, -2);
    triangles[numTriangles] = new Triangle(ah, bh, al, Vector3(0, 0, 1), 0, 0, 1, 0, 0, 1);
    objects[numObjects++] = triangles[numTriangles++];
    triangles[numTriangles] = new Triangle(bh, al, bl, Vector3(0, 0, 1), 1, 0, 0, 1, 1, 1);
    objects[numObjects++] = triangles[numTriangles++];
    triangles[numTriangles] = new Triangle(bh, dh, bl, Vector3(0.5, 0.5, 0.5),MAT_REFLECT);
    objects[numObjects++] = triangles[numTriangles++];
    triangles[numTriangles] = new Triangle(dh, bl, dl, Vector3(0.5, 0.5, 0.5),MAT_REFLECT);
    objects[numObjects++] = triangles[numTriangles++];
    triangles[numTriangles] = new Triangle(ch, ah, cl, Vector3(1, 0, 1), 0, 0, 1, 0, 0, 1);
    objects[numObjects++] = triangles[numTriangles++];
    triangles[numTriangles] = new Triangle(ah, cl, al, Vector3(1, 0, 1), 1, 0, 0, 1, 1, 1);
    objects[numObjects++] = triangles[numTriangles++];
    triangles[numTriangles] = new Triangle(dh, ch, dl, Vector3(1, 1, 0), 0, 0, 1, 0, 0, 1);
    objects[numObjects++] = triangles[numTriangles++];
    triangles[numTriangles] = new Triangle(ch, dl, cl, Vector3(1, 1, 0), 1, 0, 0, 1, 1, 1);
    objects[numObjects++] = triangles[numTriangles++];
    triangles[numTriangles] = new Triangle(ah, bh, ch, Vector3(0.75, 0.75, 0.75),MAT_DIFFUSE);
    objects[numObjects++] = triangles[numTriangles++];
    triangles[numTriangles] = new Triangle(bh, ch, dh, Vector3(0.75, 0.75, 0.75),MAT_DIFFUSE);
    objects[numObjects++] = triangles[numTriangles++];
    // lights
    numLights=0;
    lights[numLights++] = new Light(Vector3(1, 2, -1), Vector3(0.5, 0.5, 0.5), 
				    Vector3(1.0f, 0.0f, 0.0f), Vector3(0.0f, 0.0f, 1.0f), 1, 1, 0.05f);
    lights[numLights++] = new Light(Vector3(-1, 2.9, -1), Vector3(0.5, 0.5, 0.5), 
				    Vector3(1.0f, 0.0f, 0.0f), Vector3(0.0f, 0.0f, 1.0f), 1, 1, 0.05f);
    
    // GLUT functions
  glutInit(&argc, argv);
  glutInitWindowSize(windowWidth,windowHeight);
  glutInitWindowPosition(100, 100);
  glutCreateWindow("CS 180, Final Project");
  glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
  glutDisplayFunc(display);
  glutKeyboardFunc(keyboard);
  glutIdleFunc(idle);
  
  // load up Kim's skeleton stuff
  string skeletonFilename("01.asf");
  string motionFilename("01_02.amc");
  skeleton = new Skeleton(skeletonFilename.c_str(), MOCAP_SCALE);
  skeleton->setBasePosture();
  displayer.LoadSkeleton(skeleton);
  motion = new Motion(motionFilename.c_str(), MOCAP_SCALE, skeleton);
  displayer.LoadMotion(motion);
  skeleton->setPosture(*(displayer.GetSkeletonMotion(0)->GetPosture(0)));
  // load up the next motion capture frame
  SetSkeletonsToSpecifiedFrame(currentFrameIndex);

  glutMainLoop();

  return 0;
}