Exemplo n.º 1
0
void font_draw(meshset_t* fontmesh, uint32_t characterCount)
{
 	setRenderState(s_fontCtx.fontState);
 	setShaderParamBuffer(s_fontCtx.fontSettingsParam, s_fontCtx.fontSettingsBuffer);
	drawMeshSet(fontmesh, s_fontCtx.fontShader, characterCount*6);
}
Exemplo n.º 2
0
int main(int argc, char **argv) {
  carve::mesh::MeshSet<3> *a = makeTorus(30, 30, 2.0, 0.8, carve::math::Matrix::ROT(0.5, 1.0, 1.0, 1.0));
  

  carve::input::PolyhedronData data;

  for (int i = 0; i < DIM; i++) {
    double x = -3.0 + 6.0 * i / double(DIM - 1);
    for (int j = 0; j < DIM; j++) {
      double y = -3.0 + 6.0 * j / double(DIM - 1);
      double z = -1.0 + 2.0 * cos(sqrt(x * x + y * y) * 2.0) / sqrt(1.0 + x * x + y * y);
      size_t n = data.addVertex(carve::geom::VECTOR(x, y, z));
      if (i && j) {
        data.addFace(n - DIM - 1, n - 1, n - DIM);
        data.addFace(n - 1, n, n - DIM);
      }
    }
  }

  for (int i = 0; i < DIM; i++) {
    double x = -3.0 + 6.0 * i / double(DIM - 1);
    for (int j = 0; j < DIM; j++) {
      double y = -3.0 + 6.0 * j / double(DIM - 1);
      double z = 1.0 + 2.0 * cos(sqrt(x * x + y * y) * 2.0) / sqrt(1.0 + x * x + y * y);
      size_t n = data.addVertex(carve::geom::VECTOR(x, y, z));
      if (i && j) {
        data.addFace(n - DIM - 1, n - 1, n - DIM);
        data.addFace(n - 1, n, n - DIM);
      }
    }
  }

  carve::mesh::MeshSet<3> *b = data.createMesh(carve::input::opts());
  CARVE_ASSERT(b->meshes.size() == 2);

  Between between_collector(a, b);
  carve::mesh::MeshSet<3> *c = carve::csg::CSG().compute(a, b, between_collector, NULL, carve::csg::CSG::CLASSIFY_EDGE);

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

  glNewList(scene->draw_list_base + 0, GL_COMPILE);
  drawMeshSet(a, .4, .6, .8, 1.0);
  glEndList();

  glNewList(scene->draw_list_base + 1, GL_COMPILE);
  drawMeshSet(b, .8, .6, .4, 1.0);
  glEndList();

  glNewList(scene->draw_list_base + 2, GL_COMPILE);
  drawMeshSet(c, .2, .2, .8, 1.0);
  drawMeshSetWireframe(c, -1, false, false);
  glEndList();

  scene->run();

  delete scene;

  delete a;
  delete b;
  delete c;

  return 0;
}
Exemplo n.º 3
0
int main(int argc, char **argv) {
  carve::mesh::MeshSet<3> *a = makeCube(carve::math::Matrix::ROT(1.0, 1.0, 1.0, 1.0));
  
  std::vector<carve::mesh::MeshSet<3>::vertex_t> shape;

  for (int i = 0; i < POINTS; ++i) {
    double r = 2.0 + .4 * sin(i * 3 * M_TWOPI / POINTS) + .8 * sin(i * 5 * M_TWOPI / POINTS);
    shape.push_back(carve::mesh::MeshSet<3>::vertex_t(carve::geom::VECTOR(r * cos(i * M_TWOPI / POINTS), r * sin(i * M_TWOPI / POINTS), 0.0)));
  }
  std::vector<carve::mesh::MeshSet<3>::vertex_t *> face_verts;
  for (int i = 0; i < POINTS; ++i) {
    face_verts.push_back(&shape[i]);
  }
  std::vector<carve::mesh::MeshSet<3>::face_t *> faces;
  faces.push_back(new carve::mesh::MeshSet<3>::face_t(face_verts.begin(), face_verts.end()));

  carve::mesh::MeshSet<3> *b = new carve::mesh::MeshSet<3>(faces);

  std::list<std::pair<carve::csg::FaceClass, carve::mesh::MeshSet<3> *> > b_sliced;

  carve::csg::CSG csg;

  csg.hooks.registerHook(new carve::csg::CarveTriangulator, carve::csg::CSG::Hooks::PROCESS_OUTPUT_FACE_BIT);
  csg.sliceAndClassify(a, b, b_sliced);

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

  glNewList(scene->draw_list_base + 0, GL_COMPILE);

  drawMeshSet(a, .4, .6, .8, 1.0);
  glEndList();

  glNewList(scene->draw_list_base + 1, GL_COMPILE);
  drawMeshSet(b, .8, .6, .4, 1.0);
  glEndList();

  glNewList(scene->draw_list_base + 2, GL_COMPILE);
  {
    int n = 0;
    for (std::list<std::pair<carve::csg::FaceClass, carve::mesh::MeshSet<3> *> >::iterator i = b_sliced.begin(); i != b_sliced.end(); ++i) {
      float r, g, b;
      switch ((*i).first) {
      case carve::csg::FACE_IN:             r = 0.0; g = 0.0; b = 1.0; break;
      case carve::csg::FACE_OUT:            r = 1.0; g = 0.0; b = 0.0; break;
      case carve::csg::FACE_ON_ORIENT_OUT:  r = 1.0; g = 1.0; b = 0.0; break;
      case carve::csg::FACE_ON_ORIENT_IN:   r = 0.0; g = 1.0; b = 1.0; break;
      }
      drawMeshSet((*i).second, r, g, b, 1.0);
      ++n;
    }
  }
  glEndList();

  glNewList(scene->draw_list_base + 3, GL_COMPILE);
  {
    int n = 0;
    for (std::list<std::pair<carve::csg::FaceClass, carve::mesh::MeshSet<3> *> >::iterator i = b_sliced.begin(); i != b_sliced.end(); ++i) {
      float r, g, b;
      switch ((*i).first) {
      case carve::csg::FACE_IN:             r = 0.3; g = 0.3; b = 0.7; break;
      case carve::csg::FACE_OUT:            r = 0.7; g = 0.3; b = 0.3; break;
      case carve::csg::FACE_ON_ORIENT_OUT:  r = 0.7; g = 0.7; b = 0.3; break;
      case carve::csg::FACE_ON_ORIENT_IN:   r = 0.3; g = 0.7; b = 0.7; break;
      }
      drawMeshSetWireframe((*i).second, -1, false, false);
      ++n;
    }
  }
  glEndList();

  scene->run();

  delete scene;

  return 0;
}
Exemplo n.º 4
0
GLuint genSceneDisplayList(std::vector<carve::mesh::MeshSet<3> *> &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]->meshes.size() * N + 1;
  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]->getAABB();
  } 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]->getAABB());
  for (size_t p = 0; p < lines.size(); ++p) {
    std::cerr << lines[p]->aabb << std::endl;
    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::mesh::MeshSet<3> *poly = polys[p];
    glEnable(GL_CULL_FACE);
    for (unsigned i = 0; i < poly->meshes.size(); i++) {
      if (!poly->meshes[i]->isClosed()) {
        is_wireframe[list_num] = false;
        glNewList(dlist + list_num++, GL_COMPILE);
        glCullFace(GL_BACK);
        drawMeshSet(poly, 0.3f, 0.8f, 0.5f, 1.0f, i);
        glCullFace(GL_FRONT);
        drawMeshSet(poly, 0.0f, 0.0f, 1.0f, 1.0f, i);
        glCullFace(GL_BACK);
        glEndList();

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

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

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

    typedef carve::geom::RTreeNode<3, carve::mesh::Face<3> *> face_rtree_t;
    face_rtree_t *tree = face_rtree_t::construct_STR(poly->faceBegin(), poly->faceEnd(), 4, 4);
    // face_rtree_t *tree = face_rtree_t::construct_TGS(poly->faceBegin(), poly->faceEnd(), 50, 4);
    is_wireframe[list_num] = true;
    glNewList(dlist + list_num++, GL_COMPILE);
    // drawTree(tree);
    glEndList();
    delete tree;
  }

  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(4.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(4.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;
}
Exemplo n.º 5
0
int main(int argc, char **argv) {
  carve::mesh::MeshSet<3> *a = makeCube(carve::math::Matrix::ROT(1.0, 1.0, 1.0, 1.0));
  
  std::vector<carve::geom3d::Vector> shape;

  carve::input::PolyhedronData data;
  for (int i = 0; i < POINTS; ++i) {
    double r = 2.0 + .4 * sin(i * 3 * M_TWOPI / POINTS) + .8 * sin(i * 5 * M_TWOPI / POINTS);
    data.addVertex(carve::geom::VECTOR(r * cos(i * M_TWOPI / POINTS), r * sin(i * M_TWOPI / POINTS), 0.0));
  }
  std::vector<int> face_verts;
  for (int i = 0; i < POINTS; ++i) {
    face_verts.push_back(i);
  }
  data.addFace(face_verts.begin(), face_verts.end());

  carve::mesh::MeshSet<3> *b = new carve::mesh::MeshSet<3>(data.points, data.getFaceCount(), data.faceIndices);

  std::list<carve::mesh::MeshSet<3> *> a_sliced, b_sliced;

  carve::csg::CSG csg;

  csg.hooks.registerHook(new carve::csg::CarveTriangulator, carve::csg::CSG::Hooks::PROCESS_OUTPUT_FACE_BIT);
  csg.slice(a, b, a_sliced, b_sliced);

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

  glNewList(scene->draw_list_base + 0, GL_COMPILE);
  drawMeshSet(a, .4, .6, .8, 1.0);
  glEndList();

  glNewList(scene->draw_list_base + 1, GL_COMPILE);
  drawMeshSet(b, .8, .6, .4, 1.0);
  glEndList();

  glNewList(scene->draw_list_base + 2, GL_COMPILE);
  {
    int n = 0;
    for (std::list<carve::mesh::MeshSet<3> *>::iterator i = a_sliced.begin(); i != a_sliced.end(); ++i) {
      float r  = n & 1 ? .3 : .7;
      float g  = n & 2 ? .3 : .7;
      float b  = n & 4 ? .3 : .7;
      drawMeshSet(*i, r, g, b, 1.0);
      ++n;
    }
  }
  glEndList();

  glNewList(scene->draw_list_base + 3, GL_COMPILE);
  {
    int n = 0;
    for (std::list<carve::mesh::MeshSet<3> *>::iterator i = a_sliced.begin(); i != a_sliced.end(); ++i) {
      drawMeshSetWireframe(*i, -1, false, false);
      ++n;
    }
  }
  glEndList();

  glNewList(scene->draw_list_base + 4, GL_COMPILE);
  {
    int n = 0;
    for (std::list<carve::mesh::MeshSet<3> *>::iterator i = b_sliced.begin(); i != b_sliced.end(); ++i) {
      float r  = n & 1 ? .3 : .7;
      float g  = n & 2 ? .3 : .7;
      float b  = n & 4 ? .3 : .7;
      drawMeshSet(*i, r, g, b, 1.0);
      ++n;
    }
  }
  glEndList();

  glNewList(scene->draw_list_base + 5, GL_COMPILE);
  {
    int n = 0;
    for (std::list<carve::mesh::MeshSet<3> *>::iterator i = b_sliced.begin(); i != b_sliced.end(); ++i) {
      drawMeshSetWireframe(*i, -1, false, false);
      ++n;
    }
  }
  glEndList();

  scene->run();

  delete scene;

  return 0;
}