Skip to content

Commit

Permalink
Fix axmolengine#2140 DrawNode issue (axmolengine#2158)
Browse files Browse the repository at this point in the history
  • Loading branch information
aismann authored and xfbird committed Sep 18, 2024
1 parent 207a625 commit 050bd26
Showing 1 changed file with 28 additions and 12 deletions.
40 changes: 28 additions & 12 deletions core/2d/DrawNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,12 @@ void DrawNode::drawCircle(const Vec2& center,
AXLOGW("{}: thickness <= 0", __FUNCTION__);
return;
}
if (radius == 0.0f)
{
AXLOGW("{}: radius == 0", __FUNCTION__);
return;
}

_drawCircle(center, radius, angle, segments, drawLineToCenter, scaleX, scaleY, color, Color4B(), false, thickness);
}

Expand All @@ -368,6 +374,12 @@ void DrawNode::drawCircle(const Vec2& center,
AXLOGW("{}: thickness <= 0", __FUNCTION__);
return;
}
if (radius == 0.0f)
{
AXLOGW("{}: radius == 0", __FUNCTION__);
return;
}

_drawCircle(center, radius, angle, segments, drawLineToCenter, 1.0f, 1.0f, color, color, false, thickness);
}

Expand Down Expand Up @@ -982,7 +994,6 @@ void DrawNode::_drawPolygon(const Vec2* verts,

axstd::pod_vector<ExtrudeVerts> extrude{static_cast<size_t>(sizeof(struct ExtrudeVerts) * count)};

int closeCount = count - ((closedPolygon) ? 0 : 1);
for (unsigned int i = 0; i < count; i++)
{
Vec2 v0 = _vertices[(i - 1 + count) % count];
Expand All @@ -996,7 +1007,7 @@ void DrawNode::_drawPolygon(const Vec2* verts,
extrude[i] = {offset, n2};
}

for (unsigned int i = 0; i < closeCount; i++)
for (unsigned int i = 0; i < count; i++)
{
int j = (i + 1) % count;
Vec2 v0 = _vertices[i];
Expand Down Expand Up @@ -1244,28 +1255,33 @@ void DrawNode::_drawCircle(const Vec2& center,
{
const float coef = 2.0f * (float)M_PI / segments;

Vec2* _vertices = new Vec2[segments + 2];
int count = (drawLineToCenter) ? 3 : 2;
Vec2* _vertices = new Vec2[segments + count];

float rsX = radius * scaleX;
float rsY = radius * scaleY;
for (unsigned int i = 0; i < segments; i++)
{
float rads = i * coef;
float j = radius * cosf(rads + angle) * scaleX + center.x;
float k = radius * sinf(rads + angle) * scaleY + center.y;

_vertices[i].x = j;
_vertices[i].y = k;
float rads = i * coef + angle;
_vertices[i].x = rsX * cosf(rads) + center.x;
_vertices[i].y = rsY * sinf(rads) + center.y;
}
_vertices[segments] = _vertices[0];

if (drawLineToCenter)
_vertices[++segments] = center;


if (solid)
{
_drawPolygon(_vertices, segments, fillColor, borderColor, false, thickness, true);
_drawPolygon(_vertices, segments + 1, fillColor, borderColor, false, thickness, true);
}
else
{
if (drawLineToCenter)
_vertices[++segments] = center;
_drawPoly(_vertices, segments + 1, false, borderColor, thickness, true);
_drawPoly(_vertices, segments + 1, false, borderColor, thickness, true);
else
_drawPoly(_vertices, segments + 1, false, borderColor, thickness, true);
}
AX_SAFE_DELETE_ARRAY(_vertices);
}
Expand Down

0 comments on commit 050bd26

Please sign in to comment.