Catmull-Rom / Cardinal Spline interpolation problem

At first please check the issue-1441 of cocos2d
[[http://code.google.com/p/cocos2d-iphone/issues/detail?id=1441]]
I think this problem exists in cocos2d-x too. If I am right, then I think we should solve it ASAP.

Agreed. Their fix works as well.

change:

void CCCardinalSplineTo::startWithTarget(cocos2d::CCNode *pTarget)
{
     CCActionInterval::startWithTarget(pTarget);
     m_fDeltaT = (float) 1 / m_pPoints->count();
}

to:

void CCCardinalSplineTo::startWithTarget(cocos2d::CCNode *pTarget)
{
     CCActionInterval::startWithTarget(pTarget);
     m_fDeltaT = (float) 1 / (m_pPoints->count() - 1);
}

I noticed that sprite sometimes disappear near the curve. Without this everything is working well.

I think this is probably still broken at DrawNode::drawCardinalSpline…
at least when I working on my own geometry above drawCardinalSpline code the curve ending is approximated wrong if we don’t apply fix recommended above:

so at the end of the curve we have many don’t needed points. after fix:

image

3 Likes