2012-06-08 13:55:28 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2010-2012 cocos2d-x.org
|
|
|
|
* cocos2d for iPhone: http://www.cocos2d-iphone.org
|
|
|
|
*
|
|
|
|
* Copyright (c) 2008 Radu Gruian
|
|
|
|
*
|
|
|
|
* Copyright (c) 2011 Vit Valentin
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
|
|
|
*
|
|
|
|
*
|
2012-09-16 06:12:28 +08:00
|
|
|
* Original code by Radu Gruian: http://www.codeproject.com/Articles/30838/Overhauser-Catmull-Rom-Splines-for-Camera-Animatio.So
|
2012-06-08 13:55:28 +08:00
|
|
|
*
|
|
|
|
* Adapted to cocos2d-x by Vit Valentin
|
|
|
|
*
|
|
|
|
* Adapted from cocos2d-x to cocos2d-iphone by Ricardo Quesada
|
|
|
|
*/
|
|
|
|
#include "ccMacros.h"
|
|
|
|
#include "support/CCPointExtension.h"
|
|
|
|
#include "CCActionCatmullRom.h"
|
2012-06-19 16:20:46 +08:00
|
|
|
#include "cocoa/CCZone.h"
|
2012-06-08 13:55:28 +08:00
|
|
|
|
2012-06-11 18:25:57 +08:00
|
|
|
using namespace std;
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
NS_CC_BEGIN;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Implementation of CCPointArray
|
|
|
|
*/
|
2012-06-14 15:13:16 +08:00
|
|
|
|
|
|
|
CCPointArray* CCPointArray::create(unsigned int capacity)
|
2012-06-08 13:55:28 +08:00
|
|
|
{
|
|
|
|
CCPointArray* ret = new CCPointArray();
|
|
|
|
if (ret)
|
|
|
|
{
|
|
|
|
if (ret->initWithCapacity(capacity))
|
|
|
|
{
|
|
|
|
ret->autorelease();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
delete ret;
|
|
|
|
ret = NULL;
|
|
|
|
}
|
|
|
|
}
|
2012-06-14 15:13:16 +08:00
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-06-14 15:13:16 +08:00
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
bool CCPointArray::initWithCapacity(unsigned int capacity)
|
|
|
|
{
|
2013-01-14 14:45:16 +08:00
|
|
|
m_pControlPoints = new vector<CCPoint*>();
|
2012-06-08 13:55:28 +08:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
CCObject* CCPointArray::copyWithZone(cocos2d::CCZone *zone)
|
|
|
|
{
|
2013-01-14 14:45:16 +08:00
|
|
|
vector<CCPoint*> *newArray = new vector<CCPoint*>();
|
|
|
|
vector<CCPoint*>::iterator iter;
|
|
|
|
for (iter = m_pControlPoints->begin(); iter != m_pControlPoints->end(); ++iter)
|
|
|
|
{
|
|
|
|
newArray->push_back(new CCPoint((*iter)->x, (*iter)->y));
|
|
|
|
}
|
|
|
|
|
2013-01-23 14:38:46 +08:00
|
|
|
CCPointArray *points = new CCPointArray();
|
|
|
|
points->initWithCapacity(10);
|
2012-06-08 13:55:28 +08:00
|
|
|
points->setControlPoints(newArray);
|
|
|
|
|
|
|
|
return points;
|
|
|
|
}
|
|
|
|
|
|
|
|
CCPointArray::~CCPointArray()
|
|
|
|
{
|
2013-01-14 14:45:16 +08:00
|
|
|
vector<CCPoint*>::iterator iter;
|
|
|
|
for (iter = m_pControlPoints->begin(); iter != m_pControlPoints->end(); ++iter)
|
|
|
|
{
|
|
|
|
delete *iter;
|
|
|
|
}
|
|
|
|
delete m_pControlPoints;
|
2012-06-08 13:55:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
CCPointArray::CCPointArray() :m_pControlPoints(NULL){}
|
|
|
|
|
2013-01-14 14:45:16 +08:00
|
|
|
const std::vector<CCPoint*>* CCPointArray::getControlPoints()
|
2012-06-08 13:55:28 +08:00
|
|
|
{
|
2013-01-14 14:45:16 +08:00
|
|
|
return m_pControlPoints;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCPointArray::setControlPoints(vector<CCPoint*> *controlPoints)
|
|
|
|
{
|
2013-01-23 14:38:46 +08:00
|
|
|
CCAssert(controlPoints != NULL, "control points should not be NULL");
|
2013-01-14 14:45:16 +08:00
|
|
|
|
2013-01-23 14:38:46 +08:00
|
|
|
// delete old points
|
2013-01-14 14:45:16 +08:00
|
|
|
vector<CCPoint*>::iterator iter;
|
|
|
|
for (iter = m_pControlPoints->begin(); iter != m_pControlPoints->end(); ++iter)
|
|
|
|
{
|
|
|
|
delete *iter;
|
|
|
|
}
|
|
|
|
delete m_pControlPoints;
|
|
|
|
|
|
|
|
m_pControlPoints = controlPoints;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCPointArray::addControlPoint(CCPoint controlPoint)
|
|
|
|
{
|
|
|
|
m_pControlPoints->push_back(new CCPoint(controlPoint.x, controlPoint.y));
|
2012-06-08 13:55:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void CCPointArray::insertControlPoint(CCPoint &controlPoint, unsigned int index)
|
|
|
|
{
|
2012-06-11 18:25:57 +08:00
|
|
|
CCPoint *temp = new CCPoint(controlPoint.x, controlPoint.y);
|
2013-01-14 14:45:16 +08:00
|
|
|
m_pControlPoints->insert(m_pControlPoints->begin() + index, temp);
|
2012-06-08 13:55:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
CCPoint CCPointArray::getControlPointAtIndex(unsigned int index)
|
|
|
|
{
|
2013-01-14 14:45:16 +08:00
|
|
|
index = MIN(m_pControlPoints->size()-1, MAX(index, 0));
|
|
|
|
return *(m_pControlPoints->at(index));
|
2012-06-08 13:55:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void CCPointArray::replaceControlPoint(cocos2d::CCPoint &controlPoint, unsigned int index)
|
|
|
|
{
|
2013-01-14 14:45:16 +08:00
|
|
|
|
|
|
|
CCPoint *temp = m_pControlPoints->at(index);
|
|
|
|
temp->x = controlPoint.x;
|
|
|
|
temp->y = controlPoint.y;
|
2012-06-08 13:55:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void CCPointArray::removeControlPointAtIndex(unsigned int index)
|
|
|
|
{
|
2013-01-23 14:38:46 +08:00
|
|
|
vector<CCPoint*>::iterator iter = m_pControlPoints->begin() + index;
|
|
|
|
CCPoint* pRemovedPoint = *iter;
|
|
|
|
m_pControlPoints->erase(iter);
|
|
|
|
delete pRemovedPoint;
|
2012-06-08 13:55:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int CCPointArray::count()
|
|
|
|
{
|
2013-01-14 14:45:16 +08:00
|
|
|
return m_pControlPoints->size();
|
2012-06-08 13:55:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
CCPointArray* CCPointArray::reverse()
|
|
|
|
{
|
2013-01-14 14:45:16 +08:00
|
|
|
vector<CCPoint*> *newArray = new vector<CCPoint*>();
|
|
|
|
vector<CCPoint*>::reverse_iterator iter;
|
|
|
|
CCPoint *point = NULL;
|
|
|
|
for (iter = m_pControlPoints->rbegin(); iter != m_pControlPoints->rend(); ++iter)
|
2012-06-08 13:55:28 +08:00
|
|
|
{
|
2013-01-14 14:45:16 +08:00
|
|
|
point = *iter;
|
|
|
|
newArray->push_back(new CCPoint(point->x, point->y));
|
2012-06-08 13:55:28 +08:00
|
|
|
}
|
2012-06-14 15:13:16 +08:00
|
|
|
CCPointArray *config = CCPointArray::create(0);
|
2012-06-08 13:55:28 +08:00
|
|
|
config->setControlPoints(newArray);
|
|
|
|
|
|
|
|
return config;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCPointArray::reverseInline()
|
|
|
|
{
|
2013-01-14 14:45:16 +08:00
|
|
|
unsigned int l = m_pControlPoints->size();
|
|
|
|
CCPoint *p1 = NULL;
|
|
|
|
CCPoint *p2 = NULL;
|
|
|
|
int x, y;
|
2012-06-08 13:55:28 +08:00
|
|
|
for (unsigned int i = 0; i < l/2; ++i)
|
|
|
|
{
|
2013-01-14 14:45:16 +08:00
|
|
|
p1 = m_pControlPoints->at(i);
|
|
|
|
p2 = m_pControlPoints->at(l-i-1);
|
|
|
|
|
|
|
|
x = p1->x;
|
|
|
|
y = p1->y;
|
|
|
|
|
|
|
|
p1->x = p2->x;
|
|
|
|
p1->y = p2->y;
|
|
|
|
|
|
|
|
p2->x = x;
|
|
|
|
p2->y = y;
|
2012-06-08 13:55:28 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// CatmullRom Spline formula:
|
2012-06-11 10:41:52 +08:00
|
|
|
CCPoint ccCardinalSplineAt(CCPoint &p0, CCPoint &p1, CCPoint &p2, CCPoint &p3, float tension, float t)
|
2012-06-08 13:55:28 +08:00
|
|
|
{
|
|
|
|
float t2 = t * t;
|
|
|
|
float t3 = t2 * t;
|
|
|
|
|
|
|
|
/*
|
2012-06-20 11:48:31 +08:00
|
|
|
* Formula: s(-ttt + 2tt - t)P1 + s(-ttt + tt)P2 + (2ttt - 3tt + 1)P2 + s(ttt - 2tt + t)P3 + (-2ttt + 3tt)P3 + s(ttt - tt)P4
|
2012-06-08 13:55:28 +08:00
|
|
|
*/
|
|
|
|
float s = (1 - tension) / 2;
|
|
|
|
|
2012-06-20 11:48:31 +08:00
|
|
|
float b1 = s * ((-t3 + (2 * t2)) - t); // s(-t3 + 2 t2 - t)P1
|
|
|
|
float b2 = s * (-t3 + t2) + (2 * t3 - 3 * t2 + 1); // s(-t3 + t2)P2 + (2 t3 - 3 t2 + 1)P2
|
|
|
|
float b3 = s * (t3 - 2 * t2 + t) + (-2 * t3 + 3 * t2); // s(t3 - 2 t2 + t)P3 + (-2 t3 + 3 t2)P3
|
|
|
|
float b4 = s * (t3 - t2); // s(t3 - t2)P4
|
2012-06-08 13:55:28 +08:00
|
|
|
|
|
|
|
float x = (p0.x*b1 + p1.x*b2 + p2.x*b3 + p3.x*b4);
|
|
|
|
float y = (p0.y*b1 + p1.y*b2 + p2.y*b3 + p3.y*b4);
|
|
|
|
|
|
|
|
return ccp(x,y);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Implementation of CCCardinalSplineTo
|
|
|
|
*/
|
2012-06-14 15:13:16 +08:00
|
|
|
|
|
|
|
CCCardinalSplineTo* CCCardinalSplineTo::create(float duration, cocos2d::CCPointArray *points, float tension)
|
2012-06-08 13:55:28 +08:00
|
|
|
{
|
|
|
|
CCCardinalSplineTo *ret = new CCCardinalSplineTo();
|
|
|
|
if (ret)
|
|
|
|
{
|
|
|
|
if (ret->initWithDuration(duration, points, tension))
|
|
|
|
{
|
|
|
|
ret->autorelease();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CC_SAFE_RELEASE_NULL(ret);
|
|
|
|
}
|
|
|
|
}
|
2012-06-14 15:13:16 +08:00
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CCCardinalSplineTo::initWithDuration(float duration, cocos2d::CCPointArray *points, float tension)
|
|
|
|
{
|
|
|
|
CCAssert(points->count() > 0, "Invalid configuration. It must at least have one control point");
|
|
|
|
|
|
|
|
if (CCActionInterval::initWithDuration(duration))
|
|
|
|
{
|
|
|
|
this->setPoints(points);
|
|
|
|
this->m_fTension = tension;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
CCCardinalSplineTo::~CCCardinalSplineTo()
|
|
|
|
{
|
|
|
|
CC_SAFE_RELEASE_NULL(m_pPoints);
|
|
|
|
}
|
|
|
|
|
|
|
|
CCCardinalSplineTo::CCCardinalSplineTo()
|
|
|
|
: m_pPoints(NULL)
|
|
|
|
, m_fDeltaT(0.f)
|
2013-03-03 10:32:09 +08:00
|
|
|
, m_fTension(0.f)
|
2012-06-08 13:55:28 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCCardinalSplineTo::startWithTarget(cocos2d::CCNode *pTarget)
|
|
|
|
{
|
|
|
|
CCActionInterval::startWithTarget(pTarget);
|
|
|
|
|
2012-11-14 18:05:15 +08:00
|
|
|
// m_fDeltaT = (float) 1 / m_pPoints->count();
|
|
|
|
|
|
|
|
// Issue #1441
|
|
|
|
m_fDeltaT = (float) 1 / (m_pPoints->count() - 1);
|
2012-12-26 18:59:31 +08:00
|
|
|
|
2013-01-14 14:45:16 +08:00
|
|
|
m_previousPosition = pTarget->getPosition();
|
2012-12-26 18:59:31 +08:00
|
|
|
m_accumulatedDiff = CCPointZero;
|
2012-06-08 13:55:28 +08:00
|
|
|
}
|
|
|
|
|
2013-06-14 08:25:14 +08:00
|
|
|
CCCardinalSplineTo* CCCardinalSplineTo::clone() const
|
|
|
|
{
|
|
|
|
auto a = new CCCardinalSplineTo(*this);
|
|
|
|
a->initWithDuration(this->m_fDuration, this->m_pPoints, this->m_fTension);
|
|
|
|
a->autorelease();
|
|
|
|
return a;
|
|
|
|
}
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
CCCardinalSplineTo* CCCardinalSplineTo::copyWithZone(cocos2d::CCZone *pZone)
|
|
|
|
{
|
2012-06-14 15:13:16 +08:00
|
|
|
CCZone* pNewZone = NULL;
|
|
|
|
CCCardinalSplineTo* pRet = NULL;
|
|
|
|
if(pZone && pZone->m_pCopyObject) //in case of being called at sub class
|
|
|
|
{
|
|
|
|
pRet = (CCCardinalSplineTo*)(pZone->m_pCopyObject);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pRet = new CCCardinalSplineTo();
|
|
|
|
pZone = pNewZone = new CCZone(pRet);
|
|
|
|
}
|
|
|
|
|
|
|
|
CCActionInterval::copyWithZone(pZone);
|
|
|
|
|
|
|
|
pRet->initWithDuration(this->getDuration(), this->m_pPoints, this->m_fTension);
|
|
|
|
|
|
|
|
CC_SAFE_DELETE(pNewZone);
|
|
|
|
return pRet;
|
2012-06-08 13:55:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void CCCardinalSplineTo::update(float time)
|
|
|
|
{
|
|
|
|
unsigned int p;
|
|
|
|
float lt;
|
|
|
|
|
2012-11-14 18:05:15 +08:00
|
|
|
// eg.
|
|
|
|
// p..p..p..p..p..p..p
|
|
|
|
// 1..2..3..4..5..6..7
|
|
|
|
// want p to be 1, 2, 3, 4, 5, 6
|
2012-06-08 13:55:28 +08:00
|
|
|
if (time == 1)
|
|
|
|
{
|
|
|
|
p = m_pPoints->count() - 1;
|
|
|
|
lt = 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
p = time / m_fDeltaT;
|
|
|
|
lt = (time - m_fDeltaT * (float)p) / m_fDeltaT;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Interpolate
|
|
|
|
CCPoint pp0 = m_pPoints->getControlPointAtIndex(p-1);
|
|
|
|
CCPoint pp1 = m_pPoints->getControlPointAtIndex(p+0);
|
|
|
|
CCPoint pp2 = m_pPoints->getControlPointAtIndex(p+1);
|
|
|
|
CCPoint pp3 = m_pPoints->getControlPointAtIndex(p+2);
|
|
|
|
|
|
|
|
CCPoint newPos = ccCardinalSplineAt(pp0, pp1, pp2, pp3, m_fTension, lt);
|
|
|
|
|
2013-02-27 09:38:30 +08:00
|
|
|
#if CC_ENABLE_STACKABLE_ACTIONS
|
2013-01-14 14:45:16 +08:00
|
|
|
// Support for stacked actions
|
|
|
|
CCNode *node = m_pTarget;
|
|
|
|
CCPoint diff = ccpSub( node->getPosition(), m_previousPosition);
|
|
|
|
if( diff.x !=0 || diff.y != 0 ) {
|
|
|
|
m_accumulatedDiff = ccpAdd( m_accumulatedDiff, diff);
|
|
|
|
newPos = ccpAdd( newPos, m_accumulatedDiff);
|
2012-12-26 18:59:31 +08:00
|
|
|
}
|
2013-02-27 09:38:30 +08:00
|
|
|
#endif
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
this->updatePosition(newPos);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCCardinalSplineTo::updatePosition(cocos2d::CCPoint &newPos)
|
|
|
|
{
|
|
|
|
m_pTarget->setPosition(newPos);
|
2012-12-26 18:59:31 +08:00
|
|
|
m_previousPosition = newPos;
|
2012-06-08 13:55:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
CCActionInterval* CCCardinalSplineTo::reverse()
|
|
|
|
{
|
2012-06-14 15:13:16 +08:00
|
|
|
CCPointArray *pReverse = m_pPoints->reverse();
|
2012-06-08 13:55:28 +08:00
|
|
|
|
2012-06-14 15:13:16 +08:00
|
|
|
return CCCardinalSplineTo::create(m_fDuration, pReverse, m_fTension);
|
2012-06-08 13:55:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* CCCardinalSplineBy
|
|
|
|
*/
|
|
|
|
|
2012-06-14 15:13:16 +08:00
|
|
|
CCCardinalSplineBy* CCCardinalSplineBy::create(float duration, cocos2d::CCPointArray *points, float tension)
|
2012-06-08 13:55:28 +08:00
|
|
|
{
|
|
|
|
CCCardinalSplineBy *ret = new CCCardinalSplineBy();
|
|
|
|
if (ret)
|
|
|
|
{
|
|
|
|
if (ret->initWithDuration(duration, points, tension))
|
|
|
|
{
|
|
|
|
ret->autorelease();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CC_SAFE_RELEASE_NULL(ret);
|
|
|
|
}
|
|
|
|
}
|
2012-06-14 15:13:16 +08:00
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
CCCardinalSplineBy::CCCardinalSplineBy() : m_startPosition(0,0)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCCardinalSplineBy::updatePosition(cocos2d::CCPoint &newPos)
|
|
|
|
{
|
2012-12-26 18:59:31 +08:00
|
|
|
CCPoint p = ccpAdd(newPos, m_startPosition);
|
|
|
|
m_pTarget->setPosition(p);
|
|
|
|
m_previousPosition = p;
|
2012-06-08 13:55:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
CCActionInterval* CCCardinalSplineBy::reverse()
|
|
|
|
{
|
|
|
|
CCPointArray *copyConfig = (CCPointArray*)m_pPoints->copy();
|
|
|
|
|
|
|
|
//
|
|
|
|
// convert "absolutes" to "diffs"
|
|
|
|
//
|
|
|
|
CCPoint p = copyConfig->getControlPointAtIndex(0);
|
|
|
|
for (unsigned int i = 1; i < copyConfig->count(); ++i)
|
|
|
|
{
|
|
|
|
CCPoint current = copyConfig->getControlPointAtIndex(i);
|
|
|
|
CCPoint diff = ccpSub(current, p);
|
|
|
|
copyConfig->replaceControlPoint(diff, i);
|
|
|
|
|
|
|
|
p = current;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// convert to "diffs" to "reverse absolute"
|
|
|
|
|
2012-06-14 15:13:16 +08:00
|
|
|
CCPointArray *pReverse = copyConfig->reverse();
|
2012-06-08 13:55:28 +08:00
|
|
|
copyConfig->release();
|
|
|
|
|
|
|
|
// 1st element (which should be 0,0) should be here too
|
|
|
|
|
2012-06-14 15:13:16 +08:00
|
|
|
p = pReverse->getControlPointAtIndex(pReverse->count()-1);
|
|
|
|
pReverse->removeControlPointAtIndex(pReverse->count()-1);
|
2012-06-08 13:55:28 +08:00
|
|
|
|
|
|
|
p = ccpNeg(p);
|
2012-06-14 15:13:16 +08:00
|
|
|
pReverse->insertControlPoint(p, 0);
|
2012-06-08 13:55:28 +08:00
|
|
|
|
2012-06-14 15:13:16 +08:00
|
|
|
for (unsigned int i = 1; i < pReverse->count(); ++i)
|
2012-06-08 13:55:28 +08:00
|
|
|
{
|
2012-06-14 15:13:16 +08:00
|
|
|
CCPoint current = pReverse->getControlPointAtIndex(i);
|
2012-06-08 13:55:28 +08:00
|
|
|
current = ccpNeg(current);
|
|
|
|
CCPoint abs = ccpAdd(current, p);
|
2012-06-14 15:13:16 +08:00
|
|
|
pReverse->replaceControlPoint(abs, i);
|
2012-06-08 13:55:28 +08:00
|
|
|
|
|
|
|
p = abs;
|
|
|
|
}
|
|
|
|
|
2012-06-14 15:13:16 +08:00
|
|
|
return CCCardinalSplineBy::create(m_fDuration, pReverse, m_fTension);
|
2012-06-08 13:55:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void CCCardinalSplineBy::startWithTarget(cocos2d::CCNode *pTarget)
|
|
|
|
{
|
|
|
|
CCCardinalSplineTo::startWithTarget(pTarget);
|
|
|
|
m_startPosition = pTarget->getPosition();
|
|
|
|
}
|
|
|
|
|
2013-06-14 08:25:14 +08:00
|
|
|
CCCardinalSplineBy* CCCardinalSplineBy::clone() const
|
|
|
|
{
|
|
|
|
auto a = new CCCardinalSplineBy(*this);
|
|
|
|
a->initWithDuration(this->m_fDuration, (CCPointArray*)this->m_pPoints->copy()->autorelease(), this->m_fTension);
|
|
|
|
a->autorelease();
|
|
|
|
return a;
|
|
|
|
}
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
/* CCCatmullRomTo
|
|
|
|
*/
|
2012-06-14 15:13:16 +08:00
|
|
|
|
|
|
|
CCCatmullRomTo* CCCatmullRomTo::create(float dt, cocos2d::CCPointArray *points)
|
2012-06-08 13:55:28 +08:00
|
|
|
{
|
|
|
|
CCCatmullRomTo *ret = new CCCatmullRomTo();
|
|
|
|
if (ret)
|
|
|
|
{
|
|
|
|
if (ret->initWithDuration(dt, points))
|
|
|
|
{
|
|
|
|
ret->autorelease();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CC_SAFE_RELEASE_NULL(ret);
|
|
|
|
}
|
|
|
|
}
|
2012-06-14 15:13:16 +08:00
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CCCatmullRomTo::initWithDuration(float dt, cocos2d::CCPointArray *points)
|
|
|
|
{
|
|
|
|
if (CCCardinalSplineTo::initWithDuration(dt, points, 0.5f))
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-06-14 08:25:14 +08:00
|
|
|
CCCatmullRomTo* CCCatmullRomTo::clone() const
|
|
|
|
{
|
|
|
|
auto a = new CCCatmullRomTo(*this);
|
|
|
|
a->initWithDuration(this->m_fDuration, (CCPointArray*)this->m_pPoints->copy()->autorelease());
|
|
|
|
a->autorelease();
|
|
|
|
return a;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
/* CCCatmullRomBy
|
|
|
|
*/
|
2012-06-14 15:13:16 +08:00
|
|
|
|
|
|
|
CCCatmullRomBy* CCCatmullRomBy::create(float dt, cocos2d::CCPointArray *points)
|
2012-06-08 13:55:28 +08:00
|
|
|
{
|
|
|
|
CCCatmullRomBy *ret = new CCCatmullRomBy();
|
|
|
|
if (ret)
|
|
|
|
{
|
|
|
|
if (ret->initWithDuration(dt, points))
|
|
|
|
{
|
|
|
|
ret->autorelease();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CC_SAFE_RELEASE_NULL(ret);
|
|
|
|
}
|
|
|
|
}
|
2012-06-14 15:13:16 +08:00
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CCCatmullRomBy::initWithDuration(float dt, cocos2d::CCPointArray *points)
|
|
|
|
{
|
|
|
|
if (CCCardinalSplineTo::initWithDuration(dt, points, 0.5f))
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-06-14 08:25:14 +08:00
|
|
|
CCCatmullRomBy* CCCatmullRomBy::clone() const
|
|
|
|
{
|
|
|
|
auto a = new CCCatmullRomBy(*this);
|
|
|
|
a->initWithDuration(this->m_fDuration, (CCPointArray*)this->m_pPoints->copy()->autorelease());
|
|
|
|
a->autorelease();
|
|
|
|
return a;
|
|
|
|
}
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
NS_CC_END;
|
|
|
|
|