当前位置: 首页>>代码示例>>C++>>正文


C++ MeshBuilder::finalize方法代码示例

本文整理汇总了C++中MeshBuilder::finalize方法的典型用法代码示例。如果您正苦于以下问题:C++ MeshBuilder::finalize方法的具体用法?C++ MeshBuilder::finalize怎么用?C++ MeshBuilder::finalize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MeshBuilder的用法示例。


在下文中一共展示了MeshBuilder::finalize方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1:

MarkerMesh::MarkerMesh(float x, float y, float z, float size)
{
  float sqrt3 = 1.73205080757;
  float sqrt2 = 1.41421356237;
  float s2 = size / 2;
  float c2 = s2 / sqrt2;
  float c3 = s2 / sqrt3;

  MeshBuilder builder;
  builder.add_line(Math::Vector3<float> ({ x + s2, y, z }),
                   Math::Vector3<float> ({ x - s2, y, z }));
  builder.add_line(Math::Vector3<float> ({ x, y + s2, z }),
                   Math::Vector3<float> ({ x, y - s2, z }));
  builder.add_line(Math::Vector3<float> ({ x, y, z + s2 }),
                   Math::Vector3<float> ({ x, y, z - s2 }));
  builder.add_line(Math::Vector3<float> ({ x + c2, y + c2, z }),
                   Math::Vector3<float> ({ x - c2, y - c2, z }));
  builder.add_line(Math::Vector3<float> ({ x + c2, y - c2, z }),
                   Math::Vector3<float> ({ x - c2, y + c2, z }));
  builder.add_line(Math::Vector3<float> ({ x, y + c2, z + c2}),
                   Math::Vector3<float> ({ x, y - c2, z - c2}));
  builder.add_line(Math::Vector3<float> ({ x, y + c2, z - c2}),
                   Math::Vector3<float> ({ x, y - c2, z + c2}));
  builder.add_line(Math::Vector3<float> ({ x + c2, y, z + c2 }),
                   Math::Vector3<float> ({ x - c2, y, z - c2 }));
  builder.add_line(Math::Vector3<float> ({ x - c2, y, z + c2 }),
                   Math::Vector3<float> ({ x + c2, y, z - c2 }));

  _mesh = builder.finalize ();
}
开发者ID:soxslayer,项目名称:simple_csg,代码行数:30,代码来源:marker_mesh.cpp

示例2:

SurfaceMesh::SurfaceMesh (const CSG::Surface& surface)
  : _surface (surface)
{
  MeshBuilder b;

  int cnt = 0;
  surface.traverse([&] (const CSG::Pixel& pix, bool filled)
    {
      float s2 = pix.size / 2;

      Math::Vector2 pts[8];
      float densities[4];
      int tbl_index = 0;

      pts[0] = pix.center;
      pts[0].x += s2;
      pts[0].y += s2;
      if (_surface.test_point (pts[0]))
        tbl_index |= 1;
      densities[0] = _surface.density (pts[0]);

      pts[1] = pix.center;
      pts[1].x += s2;
      pts[1].y -= s2;
      if (_surface.test_point (pts[1]))
        tbl_index |= 2;
      densities[1] = _surface.density (pts[1]);

      pts[2] = pix.center;
      pts[2].x -= s2;
      pts[2].y -= s2;
      if (_surface.test_point (pts[2]))
        tbl_index |= 4;
      densities[2] = _surface.density (pts[2]);

      pts[3] = pix.center;
      pts[3].x -= s2;
      pts[3].y += s2;
      if (_surface.test_point (pts[3]))
        tbl_index |= 8;
      densities[3] = _surface.density (pts[3]);

      if (MSEdgeTable[tbl_index] & 1) {
        pts[4] = Math::Vector2 (
          Math::f_interpolate (0, densities[0], pts[0].x,
                               densities[1], pts[1].x),
          Math::f_interpolate (0, densities[0], pts[0].y,
                               densities[1], pts[1].y));
      }
      if (MSEdgeTable[tbl_index] & 2) {
        pts[5] = Math::Vector2 (
          Math::f_interpolate (0, densities[1], pts[1].x,
                               densities[2], pts[2].x),
         Math::f_interpolate (0, densities[1], pts[1].y,
                               densities[2], pts[2].y));
      }
      if (MSEdgeTable[tbl_index] & 4) {
        pts[6] = Math::Vector2 (
          Math::f_interpolate (0, densities[2], pts[2].x,
                               densities[3], pts[3].x),
          Math::f_interpolate (0, densities[2], pts[2].y,
                               densities[3], pts[3].y));
      }
      if (MSEdgeTable[tbl_index] & 8) {
        pts[7] = Math::Vector2 (
          Math::f_interpolate (0, densities[3], pts[3].x,
                               densities[0], pts[0].x),
          Math::f_interpolate (0, densities[3], pts[3].y,
                               densities[0], pts[0].y));
      }

      for (int i = 0; MSTriangleTable[tbl_index][i] != -1; i += 3) {
        b.add_triangle (Math::Vector3 (
                          pts[MSTriangleTable[tbl_index][i]].x,
                          pts[MSTriangleTable[tbl_index][i]].y,
                          0),
                        Math::Vector3 (
                          pts[MSTriangleTable[tbl_index][i + 1]].x,
                          pts[MSTriangleTable[tbl_index][i + 1]].y,
                          0),
                        Math::Vector3 (
                          pts[MSTriangleTable[tbl_index][i + 2]].x,
                          pts[MSTriangleTable[tbl_index][i + 2]].y,
                          0));
        }

      return true;
    }, .1);

  MeshBuilder::Buffs buffs = b.finalize ();
  _v.alloc (std::get<0> (buffs).first, std::get<0> (buffs).second);
  _w.alloc (std::get<1> (buffs).first, std::get<1> (buffs).second);
  _f.alloc (std::get<2> (buffs).first, std::get<2> (buffs).second);

  const CSG::BRect& br = _surface.bounds ();
  MeshBuilder bb;

  bb.add_line (Math::Vector3 (br.lb.x, br.lb.y, 0),
               Math::Vector3 (br.lb.x, br.ub.y, 0));
  bb.add_line (Math::Vector3 (br.lb.x, br.ub.y, 0),
//.........这里部分代码省略.........
开发者ID:soxslayer,项目名称:simple_csg,代码行数:101,代码来源:surface_mesh.cpp


注:本文中的MeshBuilder::finalize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。