| 469 | } |
| 470 | |
| 471 | void DrawNode::drawCardinalSpline(const PointArray* configIn, |
| 472 | float tension, |
| 473 | unsigned int segments, |
| 474 | const Color4F& color, |
| 475 | float thickness, |
| 476 | bool closed) |
| 477 | { |
| 478 | if (thickness <= 0.0f) |
| 479 | { |
| 480 | AXLOGW("{}: thickness <= 0", __FUNCTION__); |
| 481 | return; |
| 482 | } |
| 483 | |
| 484 | // Don't change the original PointArray |
| 485 | PointArray* config = configIn->clone(); |
| 486 | |
| 487 | if (closed && config->count() > 2) |
| 488 | { |
| 489 | config->addControlPoint(config->getControlPointAtIndex(0)); |
| 490 | config->addControlPoint(config->getControlPointAtIndex(1)); |
| 491 | config->insertControlPoint(config->getControlPointAtIndex(config->count() - 3), 0); |
| 492 | config->insertControlPoint(config->getControlPointAtIndex(config->count() - 4), 0); |
| 493 | } |
| 494 | |
| 495 | ssize_t p; |
| 496 | float lt; |
| 497 | float deltaT = 1.0f / config->count(); |
| 498 | |
| 499 | axstd::pod_vector<Vec2> _vertices{static_cast<size_t>(segments)}; |
| 500 | |
| 501 | for (unsigned int i = 0; i < segments; i++) |
| 502 | { |
| 503 | float dt = (float)i / segments; |
| 504 | p = static_cast<ssize_t>(dt / deltaT); |
| 505 | |
| 506 | // Check last control point reached |
| 507 | if (p >= (config->count() - 1)) |
| 508 | { |
| 509 | _vertices[i] = config->getControlPointAtIndex(config->count() - 1); |
| 510 | segments = i + 1; |
| 511 | _vertices.resize(segments); |
| 512 | break; |
| 513 | } |
| 514 | |
| 515 | // Interpolate |
| 516 | Vec2 pp0 = config->getControlPointAtIndex(p - 1); |
| 517 | Vec2 pp1 = config->getControlPointAtIndex(p + 0); |
| 518 | Vec2 pp2 = config->getControlPointAtIndex(p + 1); |
| 519 | Vec2 pp3 = config->getControlPointAtIndex(p + 2); |
| 520 | |
| 521 | lt = (dt - deltaT * (float)p) / deltaT; |
| 522 | _vertices[i] = cardinalSplineAt(pp0, pp1, pp2, pp3, tension, lt); |
| 523 | } |
| 524 | |
| 525 | // Dont draw the first and the last point |
| 526 | if (closed && config->count() > 2) |
| 527 | { |
| 528 | auto seg = static_cast<int>(segments / (config->count() - 2)); |