Пример #1
0
/*!********************************************************************************************
 @Function		TriangulatePolygon
 @Input			coordinates         Coordinate array for the polygon.
 @Input			polygons            The polygon definitions.
 @Output        triangle_coords     The resulting coordinates of the triangulation.
 @Output        triangle_indices    The resulting triangle indices of the polygon.
 @Return        True if the polygon could be triangulated, false otherwise.
 @Description	Triangulates the exterior polygon of a set of non-self-intersecting polygons.
                Note that this will not be able to deal with holes etc.
***********************************************************************************************/
bool TriangulatePolygon(const PVRTCoordinateVector &coordinates, const PVRTMultiPolygon &polygons, PVRTCoordinateVector &triangle_coords, PVRTTriangleVector &triangle_indices)
{
	// There must be at least one
	if (polygons.polygons.empty())
		return false;

	// Only triangulate the exterior polygon. 
	// For information on how to handle it properly, please have a look at the polygon triangulation section in the whitepaper.
	return TriangulatePolygon(coordinates, polygons.polygons.front(), triangle_coords, triangle_indices);
}
Пример #2
0
GLTriangleMesh SweepPolygon2DToGLMesh(const Polygon2D &polygon, GLfloat depth) {
  std::vector<GLTriangleMesh> gl_meshes;
  gl_meshes.emplace_back(SweeptPath2DToGLMesh(polygon.path, depth));
  for (const auto &hole : polygon.holes) {
    gl_meshes.emplace_back(SweeptPath2DToGLMesh(hole, depth, true, false));
  }
  auto diag_mesh = TriangulatePolygon(polygon);
  gl_meshes.emplace_back(
      ConvertDiagMesh2DToGLMesh(diag_mesh, -0.5 * depth, false));
  gl_meshes.emplace_back(
      ConvertDiagMesh2DToGLMesh(diag_mesh, depth * 0.5, true));
  return CombineGLMesh(gl_meshes);
}
Пример #3
0
GLTriangleMesh GLTriangulate2DShape2D(const CollisionShape2D *shape_ptr) {
  switch (shape_ptr->shape_type) {
    case Shape2DType::kDisk: {
      auto disk_ptr = dynamic_cast<const Disk2D *>(shape_ptr);
      const size_t num_vertices = 30;
      Polygon2D polygon(SketchDiskEdge(*disk_ptr, num_vertices));
      auto diag_mesh = TriangulatePolygon(polygon);
      return ConvertDiagMesh2DToGLMesh(diag_mesh, 0.0);
    } break;
    case Shape2DType::kPolygon: {
      auto poly_ptr = dynamic_cast<const Polygon2D *>(shape_ptr);
      auto diag_mesh = TriangulatePolygon(*poly_ptr);
      return ConvertDiagMesh2DToGLMesh(diag_mesh, 0.0);
    } break;
    case Shape2DType::kPolyLine: {
      auto line_ptr = dynamic_cast<const Line2D *>(shape_ptr);
      auto diag_mesh = TriangulatePolyline(line_ptr->path, 1.5);
      return ConvertDiagMesh2DToGLMesh(diag_mesh, 0.0);
    } break;
    default:
      break;
  }
  return GLTriangleMesh();
}