コード例 #1
0
ファイル: RNTime.C プロジェクト: acplus/peptalk
RNTime 
RNCurrentTime(void)
{
    RNTime tm;
    tm.Read();
    return tm;
}
コード例 #2
0
ファイル: RNTime.C プロジェクト: acplus/peptalk
RNScalar RNTime::
Elapsed (void) const
{
    // Return number of seconds elapsed since time
    RNTime tm; tm.Read();
    return tm.Elapsed(*this);
}
コード例 #3
0
ファイル: photonmap.cpp プロジェクト: cricklet/Path-Tracer
void GLUTMouse(int button, int state, int x, int y)
{
  // Invert y coordinate
  y = GLUTwindow_height - y;

  // Mouse is going down
  if (state == GLUT_DOWN) {
    // Reset mouse drag
    GLUTmouse_drag = 0;
  }
  else {
    // Check for double click
    static RNBoolean double_click = FALSE;
    static RNTime last_mouse_up_time;
    double_click = (!double_click) && (last_mouse_up_time.Elapsed() < 0.4);
    last_mouse_up_time.Read();

    // Check for click (rather than drag)
    if (GLUTmouse_drag < 100) {
      // Check for double click
      if (double_click) {
        // Set viewing center point
        R3Ray ray = viewer->WorldRay(x, y);
        R3Point intersection_point;
        if (scene->Intersects(ray, NULL, NULL, NULL, &intersection_point)) {
          center = intersection_point;
        }
      }
    }
  }

  // Remember button state
  int b = (button == GLUT_LEFT_BUTTON) ? 0 : ((button == GLUT_MIDDLE_BUTTON) ? 1 : 2);
  GLUTbutton[b] = (state == GLUT_DOWN) ? 1 : 0;

  // Remember modifiers
  GLUTmodifiers = glutGetModifiers();

   // Remember mouse position
  GLUTmouse[0] = x;
  GLUTmouse[1] = y;

  // Redraw
  glutPostRedisplay();
}
コード例 #4
0
ファイル: kdtview.cpp プロジェクト: cricklet/Path-Tracer
void GLUTMouse(int button, int state, int x, int y)
{
  // Invert y coordinate
  y = GLUTwindow_height - y;
  
  // Process mouse button event
  if ((button == GLUT_LEFT_BUTTON) && (state == GLUT_DOWN)) {
    // Check for double click
    static RNTime click_time;
    const RNScalar max_double_click_elapsed = 0.5;
    RNBoolean double_click = (click_time.Elapsed() < max_double_click_elapsed);
    click_time.Read();

    // Select closest point to cursor
    if (double_click) {
      selected_point = NULL;
      RNLength closest_distance = 10;
      R2Point cursor_position(x, y);
      for (int i = 0; i < all_points.NEntries(); i++) {
        TestPoint *point = all_points[i];
        const R3Point& world_position = point->position;
        R2Point screen_position = viewer->ViewportPoint(world_position);
        RNLength distance = R2Distance(screen_position, cursor_position);
        if (distance < closest_distance) {
          selected_point = point;
          closest_distance = distance;
        }
      }

      // Find closest points
      closest_point = NULL;
      nearby_points.Empty();
      if (selected_point) {
        if (max_nearby_points > 0) {
          kdtree->FindClosest(selected_point, min_nearby_distance, max_nearby_distance, max_nearby_points, nearby_points);
          closest_point = (nearby_points.NEntries() > 0) ? nearby_points.Head() : NULL;
          if (print_debug) printf("Found %d points\n", nearby_points.NEntries());
        }
        else {
          kdtree->FindAll(selected_point, min_nearby_distance, max_nearby_distance, nearby_points);
          closest_point = kdtree->FindClosest(selected_point);
          if (print_debug) printf("Found %d points\n", nearby_points.NEntries());
        }
      }
    }
  }

  // Remember button state 
  int b = (button == GLUT_LEFT_BUTTON) ? 0 : ((button == GLUT_MIDDLE_BUTTON) ? 1 : 2);
  GLUTbutton[b] = (state == GLUT_DOWN) ? 1 : 0;

  // Remember modifiers 
  GLUTmodifiers = glutGetModifiers();

  // Remember mouse position 
  GLUTmouse[0] = x;
  GLUTmouse[1] = y;

  // Redraw
  glutPostRedisplay();
}
コード例 #5
0
ファイル: photonmap.cpp プロジェクト: cricklet/Path-Tracer
void GLUTRedraw(void)
{
  // Check scene
  if (!scene) return;

  // Set viewing transformation
  viewer->Camera().Load();

  // Clear window
  RNRgb background = scene->Background();
  glClearColor(background.R(), background.G(), background.B(), 1.0);
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

  // Load lights
  LoadLights(scene);

  // Draw camera
  if (show_camera) {
    glDisable(GL_LIGHTING);
    glColor3d(1.0, 1.0, 1.0);
    glLineWidth(5);
    DrawCamera(scene);
    glLineWidth(1);
  }

  // Draw lights
  if (show_lights) {
    glDisable(GL_LIGHTING);
    glColor3d(1.0, 1.0, 1.0);
    glLineWidth(5);
    DrawLights(scene);
    glLineWidth(1);
  }

  // Draw rays
  if (show_rays) {
    glDisable(GL_LIGHTING);
    glColor3d(0.0, 1.0, 0.0);
    glLineWidth(3);
    DrawRays(scene);
    glLineWidth(1);
  }

  // Draw rays
  if (show_photons) {
    glDisable(GL_LIGHTING);
    glColor3d(1.0, 1.0, 1.0);
    glLineWidth(1);
    DrawPhotonPaths(scene);
    glLineWidth(1);
  }

  // Draw rays
  if (show_global_samples) {
    glDisable(GL_LIGHTING);
    glColor3d(1.0, 1.0, 1.0);
    glLineWidth(1);
    DrawGlobalSamples(scene);
    glLineWidth(1);
  }

  // Draw rays
  if (show_caustic_samples) {
    glDisable(GL_LIGHTING);
    glColor3d(1.0, 1.0, 1.0);
    glLineWidth(1);
    DrawCausticSamples(scene);
    glLineWidth(1);
  }

  // Draw scene nodes
  if (show_shapes) {
    glEnable(GL_LIGHTING);
    R3null_material.Draw();
    DrawShapes(scene, scene->Root());
    R3null_material.Draw();
  }

  // Draw bboxes
  if (show_bboxes) {
    glDisable(GL_LIGHTING);
    glColor3d(1.0, 0.0, 0.0);
    DrawBBoxes(scene, scene->Root());
  }

  // Draw frame time
  if (show_frame_rate) {
    char buffer[128];
    static RNTime last_time;
    double frame_time = last_time.Elapsed();
    last_time.Read();
    if ((frame_time > 0) && (frame_time < 10)) {
      glDisable(GL_LIGHTING);
      glColor3d(1.0, 1.0, 1.0);
      sprintf(buffer, "%.1f fps", 1.0 / frame_time);
      DrawText(R2Point(100, 100), buffer);
    }
  }

  // Capture screenshot image
  if (screenshot_image_name) {
    if (print_verbose) printf("Creating image %s\n", screenshot_image_name);
    R2Image image(GLUTwindow_width, GLUTwindow_height, 3);
    image.Capture();
    image.Write(screenshot_image_name);
    screenshot_image_name = NULL;
  }

  // Swap buffers
  glutSwapBuffers();
}