Ejemplo n.º 1
0
const R3Sphere R3Triangle::
BSphere(void) const
{
    // Return bounding sphere (is this right???)
    R3Point centroid = Centroid();
    RNLength radius = R3Distance(centroid, v[0]->Position());
    return R3Sphere(centroid, radius);
}
Ejemplo n.º 2
0
void DrawLights(R3Scene *scene)
{
  // Check if should draw lights
  if (!show_lights) return;

  // Setup
  GLboolean lighting = glIsEnabled(GL_LIGHTING);
  glDisable(GL_LIGHTING);

  // Draw all lights
  double radius = scene->bbox.DiagonalRadius();
  for (int i = 0; i < scene->NLights(); i++) {
    R3Light *light = scene->Light(i);
    glColor3d(light->color[0], light->color[1], light->color[2]);
    if (light->type == R3_DIRECTIONAL_LIGHT) {
      // Draw direction vector
      glLineWidth(5);
      glBegin(GL_LINES);
      R3Point centroid = scene->bbox.Centroid();
      R3Vector vector = radius * light->direction;
      glVertex3d(centroid[0] - vector[0], centroid[1] - vector[1], centroid[2] - vector[2]);
      glVertex3d(centroid[0] - 1.25*vector[0], centroid[1] - 1.25*vector[1], centroid[2] - 1.25*vector[2]);
      glEnd();
      glLineWidth(1);
    }
    else if (light->type == R3_POINT_LIGHT) {
      // Draw sphere at point light position
      R3Sphere(light->position, 0.1 * radius).Draw();
    }
    else if (light->type == R3_SPOT_LIGHT) {
      // Draw sphere at point light position and line indicating direction
      R3Sphere(light->position, 0.1 * radius).Draw();
  
      // Draw direction vector
      glLineWidth(5);
      glBegin(GL_LINES);
      R3Vector vector = radius * light->direction;
      glVertex3d(light->position[0], light->position[1], light->position[2]);
      glVertex3d(light->position[0] + 0.25*vector[0], light->position[1] + 0.25*vector[1], light->position[2] + 0.25*vector[2]);
      glEnd();
      glLineWidth(1);
    }
    else if (light->type == R3_AREA_LIGHT) {
      // Draw circular area
      R3Vector v1, v2;
      double r = light->radius;
      R3Point p = light->position;
      int dim = light->direction.MinDimension();
      if (dim == 0) { v1 = light->direction % R3posx_vector; v1.Normalize(); v2 = light->direction % v1; }
      else if (dim == 1) { v1 = light->direction % R3posy_vector; v1.Normalize(); v2 = light->direction % v1; }
      else { v1 = light->direction % R3posz_vector; v1.Normalize(); v2 = light->direction % v1; }
      glBegin(GL_POLYGON);
      glVertex3d(p[0] +  1.00*r*v1[0] +  0.00*r*v2[0], p[1] +  1.00*r*v1[1] +  0.00*r*v2[1], p[2] +  1.00*r*v1[2] +  0.00*r*v2[2]);
      glVertex3d(p[0] +  0.71*r*v1[0] +  0.71*r*v2[0], p[1] +  0.71*r*v1[1] +  0.71*r*v2[1], p[2] +  0.71*r*v1[2] +  0.71*r*v2[2]);
      glVertex3d(p[0] +  0.00*r*v1[0] +  1.00*r*v2[0], p[1] +  0.00*r*v1[1] +  1.00*r*v2[1], p[2] +  0.00*r*v1[2] +  1.00*r*v2[2]);
      glVertex3d(p[0] + -0.71*r*v1[0] +  0.71*r*v2[0], p[1] + -0.71*r*v1[1] +  0.71*r*v2[1], p[2] + -0.71*r*v1[2] +  0.71*r*v2[2]);
      glVertex3d(p[0] + -1.00*r*v1[0] +  0.00*r*v2[0], p[1] + -1.00*r*v1[1] +  0.00*r*v2[1], p[2] + -1.00*r*v1[2] +  0.00*r*v2[2]);
      glVertex3d(p[0] + -0.71*r*v1[0] + -0.71*r*v2[0], p[1] + -0.71*r*v1[1] + -0.71*r*v2[1], p[2] + -0.71*r*v1[2] + -0.71*r*v2[2]);
      glVertex3d(p[0] +  0.00*r*v1[0] + -1.00*r*v2[0], p[1] +  0.00*r*v1[1] + -1.00*r*v2[1], p[2] +  0.00*r*v1[2] + -1.00*r*v2[2]);
      glVertex3d(p[0] +  0.71*r*v1[0] + -0.71*r*v2[0], p[1] +  0.71*r*v1[1] + -0.71*r*v2[1], p[2] +  0.71*r*v1[2] + -0.71*r*v2[2]);
      glEnd();
    }
    else {
      fprintf(stderr, "Unrecognized light type: %d\n", light->type);
      return;
    }
  }

  // Clean up
  if (lighting) glEnable(GL_LIGHTING);
}
Ejemplo n.º 3
0
void GLUTRedraw(void)
{
  // Set viewing transformation
  viewer->Camera().Load();

  // Clear window 
  glClearColor(200.0/255.0, 200.0/255.0, 200.0/255.0, 1.0);
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

  // Set lights
  static GLfloat light0_position[] = { 3.0, 4.0, 5.0, 0.0 };
  glLightfv(GL_LIGHT0, GL_POSITION, light0_position);
  static GLfloat light1_position[] = { -3.0, -2.0, -3.0, 0.0 };
  glLightfv(GL_LIGHT1, GL_POSITION, light1_position);

  // Show all points
  if (show_points) {
    glEnable(GL_LIGHTING);
    static GLfloat material[4] = { 0, 0, 1, 1 };
    glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, material); 
    for (int i = 0; i < all_points.NEntries(); i++) {
      TestPoint *point = all_points[i];
      R3Sphere(point->position, 0.01).Draw();
    }
  }
    
  // Show nearby points
  if (selected_point && !nearby_points.IsEmpty()) {
    glEnable(GL_LIGHTING);
    static GLfloat material[4] = { 1, 0, 0, 1 };
    glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, material); 
    for (int i = 0; i < nearby_points.NEntries(); i++) {
      TestPoint *point = nearby_points.Kth(i);
      R3Sphere(point->position, 0.02).Draw();
    }
  }

  // Show closest point
  if (selected_point && closest_point) {
    glEnable(GL_LIGHTING);
    static GLfloat material[4] = { 0, 1, 0, 1 };
    glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, material); 
    R3Sphere(closest_point->position, 0.03).Draw();
  }
    
  // Show selected point
  if (selected_point) {
    glEnable(GL_LIGHTING);
    static GLfloat material[4] = { 1, 1, 1, 1 };
    glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, material); 
    R3Sphere(selected_point->position, 0.05).Draw();
  }
    
  // Show constraints
  if (0 && show_constraints) {
    glDisable(GL_LIGHTING);
    glColor3f(0.5, 0, 0);
    R3Sphere(selected_point->position, min_nearby_distance).Outline();
    R3Sphere(selected_point->position, max_nearby_distance).Outline();
  }
    
  // Show KD tree
  if (show_kdtree) {
    glDisable(GL_LIGHTING);
    glColor3f(0, 0, 0);
    kdtree->Outline();
  }
    
  // Swap buffers 
  glutSwapBuffers();
}    
Ejemplo n.º 4
0
const R3Sphere R3Box::
BSphere (void) const
{
    // Return bounding sphere 
    return R3Sphere(Centroid(), DiagonalRadius());
}
Ejemplo n.º 5
0
R3Sphere R3PointLight::
SphereOfInfluence(RNScalar intensity_threshold) const
{
    // Return sphere within which light intensity is below threshhold
    return R3Sphere(Position(), RadiusOfInfluence(intensity_threshold));
}
Ejemplo n.º 6
0
const R3Sphere R3Span::
BSphere(void) const
{
    // Return bounding sphere 
    return R3Sphere(Midpoint(), 0.5 * Length());
}
Ejemplo n.º 7
0
const R3Sphere R3Point::
BSphere (void) const
{
    // Return bounding sphere
    return R3Sphere(*this, 0.0);
}
Ejemplo n.º 8
0
const R3Sphere R3Circle::
BSphere(void) const
{
    // Return bounding sphere of circle
    return R3Sphere(center, radius);
}