Exemplo n.º 1
0
int main(int argc, char **argv) {
  carve::poly::Polyhedron *input = readPLY(argv[1]);
  double offset = strtod(argv[2], NULL);

  TestScene *scene = new TestScene(argc, argv, 3);

  glNewList(scene->draw_list_base, GL_COMPILE);
  doOffset(input, offset);
  glEndList();

  glNewList(scene->draw_list_base + 1, GL_COMPILE);
  drawPolyhedron(input, .6, .6, .6, 1.0, false);
  glEndList();

  glNewList(scene->draw_list_base + 2, GL_COMPILE);
  drawPolyhedronWireframe(input);
  glEndList();

  scene->draw_flags[0] = true;
  scene->draw_flags[1] = true;
  scene->draw_flags[2] = true;

  scene->run();

  delete scene;

  return 0;
}
Exemplo n.º 2
0
//Display Function
void drawScene()
{
	
	//setting
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	
	gluLookAt( rd * sin(theta) * cos(fi) , rd * cos(theta) , rd * sin(theta) * sin(fi)  ,
			0.0, 0.0, 0.0,
			-cos(theta) * cos(fi), sin(theta), -cos(theta) * sin(fi));
	
	
	//drawing
	glPolygonMode(GL_FRONT, GL_FILL);
	glPolygonMode(GL_BACK, GL_LINE);
	
	drawPolyhedron(p);
	
	//swap buffers
	glutSwapBuffers();	
	
}
Exemplo n.º 3
0
GLuint genSceneDisplayList(std::vector<carve::poly::Polyhedron *> &polys,
                           std::vector<carve::line::PolylineSet *> &lines,
                           std::vector<carve::point::PointSet *> &points,
                           size_t *listSize,
                           std::vector<bool> &is_wireframe) {

  int n = 0;
  int N = 1;

  is_wireframe.clear();

  if (options.wireframe) N = 2;

  for (size_t p = 0; p < polys.size(); ++p) n += polys[p]->manifold_is_closed.size() * N;
  for (size_t p = 0; p < lines.size(); ++p) n += lines[p]->lines.size() * 2;
  n += points.size();

  if (n == 0) return 0;

  carve::geom3d::AABB aabb;
  if (polys.size()) {
    aabb = polys[0]->aabb;
  } else if (lines.size()) {
    aabb = lines[0]->aabb;
  } else if (points.size()) {
    aabb = points[0]->aabb;
  }
  for (size_t p = 0; p < polys.size(); ++p) aabb.unionAABB(polys[p]->aabb);
  for (size_t p = 0; p < lines.size(); ++p) aabb.unionAABB(lines[p]->aabb);
  for (size_t p = 0; p < points.size(); ++p) aabb.unionAABB(points[p]->aabb);

  GLuint dlist = glGenLists((GLsizei)(*listSize = n));
  is_wireframe.resize(n, false);

  double scale_fac = 20.0 / aabb.extent[carve::geom::largestAxis(aabb.extent)];

  if (options.fit) {
    g_translation = -aabb.pos;
    g_scale = scale_fac;
  } else {
    g_translation = carve::geom::VECTOR(0.0,0.0,0.0);
    g_scale = 1.0;
  }

  unsigned list_num = 0;

  for (size_t p = 0; p < polys.size(); ++p) {
    carve::poly::Polyhedron *poly = polys[p];
    for (unsigned i = 0; i < poly->manifold_is_closed.size(); i++) {
      if (!poly->manifold_is_closed[i]) {
        is_wireframe[list_num] = false;
        glNewList(dlist + list_num++, GL_COMPILE);
        glCullFace(GL_BACK);
        drawPolyhedron(poly, 0.0f, 0.0f, 0.5f, 1.0f, false, i);
        glCullFace(GL_FRONT);
        drawPolyhedron(poly, 0.0f, 0.0f, 1.0f, 1.0f, false, i);
        glCullFace(GL_BACK);
        glEndList();

        if (options.wireframe) {
          is_wireframe[list_num] = true;
          glNewList(dlist + list_num++, GL_COMPILE);
          drawPolyhedronWireframe(poly, options.normal, i);
          glEndList();
        }
      }
    }

    for (unsigned i = 0; i < poly->manifold_is_closed.size(); i++) {
      if (poly->manifold_is_closed[i]) {
        is_wireframe[list_num] = false;
        glNewList(dlist + list_num++, GL_COMPILE);
        glCullFace(GL_BACK);
        drawPolyhedron(poly, 0.3f, 0.5f, 0.8f, 1.0f, false, i);
        glCullFace(GL_FRONT);
        drawPolyhedron(poly, 1.0f, 0.0f, 0.0f, 1.0f, false, i);
        glCullFace(GL_BACK);
        glEndList();

        if (options.wireframe) {
          is_wireframe[list_num] = true;
          glNewList(dlist + list_num++, GL_COMPILE);
          drawPolyhedronWireframe(poly, options.normal, i);
          glEndList();
        }
      }
    }
  }

  for (size_t l = 0; l < lines.size(); ++l) {
    carve::line::PolylineSet *line = lines[l];

    for (carve::line::PolylineSet::line_iter i = line->lines.begin(); i != line->lines.end(); ++i) {
      is_wireframe[list_num] = false;
      glNewList(dlist + list_num++, GL_COMPILE);
      glBegin((*i)->isClosed() ? GL_LINE_LOOP : GL_LINE_STRIP);
      glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
      for (carve::line::polyline_vertex_iter j = (*i)->vbegin(); j != (*i)->vend(); ++j) {
        carve::geom3d::Vector v = (*j)->v;
        glVertex3f(g_scale * (v.x + g_translation.x),
                   g_scale * (v.y + g_translation.y),
                   g_scale * (v.z + g_translation.z));
      }
      glEnd();
      glEndList();
      is_wireframe[list_num] = true;
      glNewList(dlist + list_num++, GL_COMPILE);
      glPointSize(2.0);
      glColor4f(1.0f, 1.0f, 0.0f, 1.0f);
      glBegin(GL_POINTS);
      for (carve::line::polyline_vertex_iter j = (*i)->vbegin(); j != (*i)->vend(); ++j) {
        carve::geom3d::Vector v = (*j)->v;
        glVertex3f(g_scale * (v.x + g_translation.x),
                   g_scale * (v.y + g_translation.y),
                   g_scale * (v.z + g_translation.z));
      }
      glEnd();
      glEndList();
    }
  }

  for (size_t l = 0; l < points.size(); ++l) {
    carve::point::PointSet *point = points[l];

    is_wireframe[list_num] = false;
    glNewList(dlist + list_num++, GL_COMPILE);
    glPointSize(2.0);
    glBegin(GL_POINTS);
    for (size_t i = 0; i < point->vertices.size(); ++i) {
      carve::geom3d::Vector v = point->vertices[i].v;
      glColor4f(0.0f, 1.0f, 1.0f, 1.0f);
      glVertex3f(g_scale * (v.x + g_translation.x),
                 g_scale * (v.y + g_translation.y),
                 g_scale * (v.z + g_translation.z));
    }
    glEnd();
    glEndList();
  }

  return dlist;
}