MCPcopy Create free account
hub / github.com/axmolengine/axmol / _drawPolygon

Method _drawPolygon

core/2d/DrawNode.cpp:838–1034  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

836}
837
838void DrawNode::_drawPolygon(const Vec2* verts,
839 unsigned int count,
840 const Color4F& fillColor,
841 const Color4F& borderColor,
842 bool closedPolygon,
843 float thickness,
844 bool isconvex)
845{
846 AXASSERT(count >= 0, "invalid count value");
847
848 bool outline = (thickness != 0.0f);
849
850 auto _vertices = _transform(verts, count, closedPolygon);
851
852 std::vector<V2F_C4B_T2F_Triangle> triangleList;
853
854 int vertex_count = 0;
855
856 // calculate the memory (important for correct drawing stuff)
857 if (closedPolygon && !isconvex && fillColor.a > 0.0f && !isConvex(_vertices.data(), count) && count >= 3)
858 {
859 std::vector<p2t::Point> p2pointsStorage;
860 p2pointsStorage.reserve(count);
861 std::vector<p2t::Point*> p2points;
862 p2points.reserve(count);
863
864 for (unsigned int i = 0; i < count - 1;
865 i++) // count-1 is needed because of: _vertices[0] = _vertices[i < count]
866 {
867 p2points.emplace_back(&p2pointsStorage.emplace_back((float)_vertices[i].x, (float)_vertices[i].y));
868 }
869 p2t::CDT cdt(p2points);
870 cdt.Triangulate();
871 std::vector<p2t::Triangle*> tris = cdt.GetTriangles();
872
873 vertex_count += tris.size();
874 for (auto&& t : tris) // use it later; only one calculate!!!
875 {
876 p2t::Point* vec1 = t->GetPoint(0);
877 p2t::Point* vec2 = t->GetPoint(1);
878 p2t::Point* vec3 = t->GetPoint(2);
879
880 V2F_C4B_T2F_Triangle triangle = {
881 {Vec2(vec1->x, vec1->y), fillColor, Vec2::ZERO},
882 {Vec2(vec2->x, vec2->y), fillColor, Vec2::ZERO},
883 {Vec2(vec3->x, vec3->y), fillColor, Vec2::ZERO},
884 };
885 triangleList.emplace_back(triangle); // use it for drawing later
886 }
887 }
888 else if (fillColor.a > 0.0f)
889 {
890 vertex_count += count - 2;
891 }
892
893 if (outline)
894 {
895 if (thickness != 1.0f || properties.drawOrder)

Callers

nothing calls this directly

Calls 12

GetTrianglesMethod · 0.80
isConvexFunction · 0.70
Vec2Class · 0.70
dotFunction · 0.50
dataMethod · 0.45
reserveMethod · 0.45
emplace_backMethod · 0.45
TriangulateMethod · 0.45
sizeMethod · 0.45
GetPointMethod · 0.45
getNormalizedMethod · 0.45

Tested by

no test coverage detected