Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 9 additions & 17 deletions core/2d/DrawNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -489,17 +489,15 @@ void DrawNode::drawCardinalSpline(PointArray* config,
for (unsigned int i = 0; i < segments; i++)
{
float dt = (float)i / segments;
p = static_cast<ssize_t>(dt / deltaT);

// border
if (dt == 1)
// Check last control point reached
if (p >= (config->count() - 1))
{
p = config->count() - 1;
lt = 1;
}
else
{
p = static_cast<ssize_t>(dt / deltaT);
lt = (dt - deltaT * (float)p) / deltaT;
_vertices[i] = config->getControlPointAtIndex(config->count() - 1);
segments = i + 1;
_vertices.resize(segments);
break;
}

// Interpolate
Expand All @@ -508,14 +506,8 @@ void DrawNode::drawCardinalSpline(PointArray* config,
Vec2 pp2 = config->getControlPointAtIndex(p + 1);
Vec2 pp3 = config->getControlPointAtIndex(p + 2);

Vec2 newPos = ccCardinalSplineAt(pp0, pp1, pp2, pp3, tension, lt);
_vertices[i].x = newPos.x;
_vertices[i].y = newPos.y;
if (newPos == config->getControlPointAtIndex(config->count() - 1) && i > 0)
{
segments = i + 1;
break;
}
lt = (dt - deltaT * (float)p) / deltaT;
_vertices[i] = ccCardinalSplineAt(pp0, pp1, pp2, pp3, tension, lt);
}

_drawPoly(_vertices.data(), segments, false, color, thickness, true);
Expand Down
11 changes: 10 additions & 1 deletion tests/cpp-tests/Source/DrawNodeTest/DrawNodeTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3515,9 +3515,18 @@ void DrawNodeSpLinesTest::update(float dt)

drawNode->drawCardinalSpline(array, 0.2f, points.size() * 8, Color4F::GREEN, 20.0f);
drawNode->drawCardinalSpline(array, 0.2f, points.size() * 8, Color4F::BLUE);

drawNode->drawCardinalSpline(array, 0.2f, points.size() * 16, Color4F(1.0f, 1.0f, 0.5f, 1.0f), 10.0f);

// Issue #2302
auto array3 = PointArray::create(20);
for (int i = 0; i < 10; i++)
{
array3->addControlPoint(Vec2((i % 2) ? 20 : screen.width - 20, 50 + i * 20));
drawNode->drawPoint(array3->getControlPointAtIndex(i), 10, Color4F::BLUE);
}
drawNode->drawCardinalSpline(array3, 0.1, 20, Color4F::ORANGE);


// drawNode->drawCatmullRom(array, points.size() * 8, Color4F::YELLOW,5);
// if (points.size()>3)
//{
Expand Down
Loading