cocos2d-x实例学习(11)之CCCatmullRomTo&CCCatmullRomBy

CCCatmullRomTo&CCCatmullRomBy概念

CCCatmullRomTo:把某一对象以Catmull-Rom curve曲线移动到某一点。它的类继承图为:

CCCatmullRomBy:把某一对象以Catmull-Rom curve曲线移动一段距离。它的类继承图为:

CCCatmullRomTo&CCCatmullRomBy使用方式


    CCSize s = CCDirector::sharedDirector()->getWinSize();

    //使用CCCatmullRomTo
    m_tamara->setPosition(ccp(50, 50));

    CCPointArray *array = CCPointArray::create(20);

    array->addControlPoint(ccp(0, 0));
    array->addControlPoint(ccp(80, 80));
    array->addControlPoint(ccp(s.width - 80, 80));
    array->addControlPoint(ccp(s.width - 80, s.height - 80));
    array->addControlPoint(ccp(80, s.height - 80));
    array->addControlPoint(ccp(80, 80));
    array->addControlPoint(ccp(s.width / 2, s.height / 2));

    CCCatmullRomBy *action = CCCatmullRomBy::create(3, array);
    CCFiniteTimeAction *reverse = action->reverse();

    CCFiniteTimeAction *seq = CCSequence::create(action, reverse, NULL);

    m_tamara->runAction(seq);

    //使用CCCatmullRomBy

    CCPointArray *array2 = CCPointArray::create(20);

    array2->addControlPoint(ccp(s.width / 2, 30));
    array2->addControlPoint(ccp(s.width  -80, 30));
    array2->addControlPoint(ccp(s.width - 80, s.height - 80));
    array2->addControlPoint(ccp(s.width / 2, s.height - 80));
    array2->addControlPoint(ccp(s.width / 2, 30));
    CCCatmullRomTo *action2 = CCCatmullRomTo::create(3, array2);
    CCFiniteTimeAction *reverse2 = action2->reverse();
    CCFiniteTimeAction *seq2 = CCSequence::create(action2, reverse2, NULL);
    m_kathia->runAction(seq2);
    m_pArray1 = array;
    m_pArray1->retain();
    m_pArray2 = array2;
    m_pArray2->retain();

效果图如下:

注:

云形线(Catmull-Rom curve曲线)

云线(Spline或B-spline)在数学上有很多种类,常用的三阶云线有Hermite, Bezier, Uniform B-spline, Nonuniform B-spline, Catmull-Rom及Kochanek-Bartels等。NURBS curve则是NonUniform Rational B-Spline curve(非一致(的)有理(的)基底样条曲线)的缩写。

早期的Spline curve翻译成样条曲线,是因为它是从造船时,为了弯曲木板,所发展出来的数学。对木板在固定的位置施以压力,造成弯曲,固定成型。后来发展成B-spline curve时也有翻译成拟合曲线,这是因为一条复杂的曲线是分段控制的,就好象由数条简单的曲线拟合成一条曲线。B-spline的B是Basis,是数学基底,不同基底所拟合的曲线会有些许差异。

然后比较知名的曲线如Hermite curve, Catmull-Rom curve, Bezier curve及NURBS curve陆续发展出来。最后NURBS curve成为CAD的最爱,因为NURBS的拟真性最佳,尤其是二阶的圆锥曲线(Conic)。NURBS可以用最少的控制点做出误差最小的圆。

现在这些曲线统称为云形线,简称为云线

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值