Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- USING_NS_CC;
- std::vector<p2t::Triangle*> TriangleHelper::getTriangles(Shape shape) {
- std::vector<p2t::Point*> polyline;
- for(int i = 0; i < shape.pointsCount; i++) {
- polyline.push_back(new p2t::Point(shape.coordinates[i][0], shape.coordinates[i][1]));
- }
- p2t::CDT cdt(polyline);
- cdt.Triangulate();
- return cdt.GetTriangles();
- }
- TriangulatedShape* TriangleHelper::getTriangulatedShapes(Shape* shapes, int count) {
- //TriangulatedShape * triangulatedShapes = (TriangulatedShape*) malloc(count * sizeof(TriangulatedShape));
- TriangulatedShape triangulatedShapes[count];
- for (int i = 0; i < count; i++) {
- Shape shape = shapes[i];
- std::vector<p2t::Triangle*> triangles = TriangleHelper::getTriangles(shape);
- int trianglesCounter = 0;
- for (p2t::Triangle *tri : triangles) {
- const p2t::Point &p1 = *tri->GetPoint(0);
- const p2t::Point &p2 = *tri->GetPoint(1);
- const p2t::Point &p3 = *tri->GetPoint(2);
- //triangulatedShapes[i].triangles[trianglesCounter][0] = Vec2(p1.x, p1.y);
- //triangulatedShapes[i].triangles[trianglesCounter][1] = Vec2(p2.x, p2.y);
- //triangulatedShapes[i].triangles[trianglesCounter][2] = Vec2(p3.x, p3.y);
- trianglesCounter++;
- }
- triangulatedShapes[i].color = shape.color;
- triangulatedShapes[i].type = shape.type;
- triangulatedShapes[i].trianglesCount = triangles.size();
- std::vector<p2t::Triangle*>().swap(triangles);
- }
- return triangulatedShapes;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement