CCActionCatmullRom(样条曲线动作 通过点数组自定义动作曲线)
来源:互联网 发布:最好的防火墙软件 编辑:程序博客网 时间:2024/05/16 07:25
.h
#ifndef __CCACTION_CATMULLROM_H__
#define __CCACTION_CATMULLROM_H__
#include <vector>
#include "CCActionInterval.h"
#include "base_nodes/CCNode.h"
#include "cocoa/CCGeometry.h"
NS_CC_BEGIN;
/** An Array that contain control points.
Used by CCCardinalSplineTo and (By) and CCCatmullRomTo (and By) actions.
*/
class CC_DLL CCPointArray : public CCObject
{
public:
/** creates and initializes a Points array with capacity(能力;容量;资格,地位) */
static CCPointArray* create(unsigned int capacity);
virtual ~CCPointArray();
CCPointArray();
/** initializes a Catmull Rom(瑞丽模式,一种抗锯齿过滤器)config with a capacity(性能) hint(提示 暗示 ) */
bool initWithCapacity(unsigned int capacity);
/** appends(附加) a control point */
void addControlPoint(CCPoint controlPoint);
/** inserts a controlPoint at index */
void insertControlPoint(CCPoint &controlPoint, unsigned int index);
/** replaces an existing controlPoint at index */
void replaceControlPoint(CCPoint &controlPoint, unsigned int index);
/** get the value of a controlPoint at a given index */
CCPoint getControlPointAtIndex(unsigned int index);
/** deletes a control point at a given index */
void removeControlPointAtIndex(unsigned int index);
/** returns the number of objects of the control point array */
unsigned int count();//得到控制点数组大小
/** returns a new copy of the array reversed. User is responsible for releasing this copy */
CCPointArray* reverse();//返回一个相反的控制点数组 用户负责释放
/** reverse the current control point array inline, without generating(生成) a new one */
void reverseInline();//反转当前控制点数组
virtual CCObject* copyWithZone(CCZone *zone);
const std::vector<CCPoint*>* getControlPoints();//得到控制点数组指针
void setControlPoints(std::vector<CCPoint*> *controlPoints);//设置控制点数组 参数是控制点指针
private:
/** Array that contains the control points */
std::vector<CCPoint*> *m_pControlPoints; //制点数组指针
};
//参见下面的CCCardinalSplineBy(区别同 moveto 和moveby)
class CC_DLL CCCardinalSplineTo : public CCActionInterval
{
public:
/** creates an action with a Cardinal Spline array of points and tension */
static CCCardinalSplineTo* create(float duration, CCPointArray* points, float tension);
virtual ~CCCardinalSplineTo();
CCCardinalSplineTo();
/** initializes the action with a duration and an array of points */
bool initWithDuration(float duration, CCPointArray* points, float tension);
// super virtual functions
virtual CCCardinalSplineTo* copyWithZone(CCZone* pZone);
virtual void startWithTarget(CCNode *pTarget);
virtual void update(float time);
virtual CCActionInterval* reverse();
virtual void updatePosition(CCPoint &newPos);
inline CCPointArray* getPoints() { return m_pPoints; }
inline void setPoints(CCPointArray* points)
{
CC_SAFE_RETAIN(points);
CC_SAFE_RELEASE(m_pPoints);
m_pPoints = points;
}
protected:
/** Array of control points */
CCPointArray *m_pPoints;
float m_fDeltaT;
float m_fTension;
CCPointm_previousPosition;
CCPointm_accumulatedDiff;
};
/////////////////////////
CCCardinalSplineBy概念
这个类是样条曲线动作,其创建函数CCCardinalSplineBy::create(float duration, cocos2d::CCPointArray *points, float tension);
中duration是时间间隔,points是控制点列表,tension是松紧程度。tension==1时,样条线是分段直线。tension<1向外松弛弯
曲,tension>1向内缩紧弯曲。By动作是以当前坐标为新坐标原点。
CCCardinalSplineBy示例–为同一组控制点实现不同的移动路径
///////////////////
class CC_DLL CCCardinalSplineBy : public CCCardinalSplineTo
{
public:
/** creates an action with a Cardinal Spline array of points and tension */
//1、时间间隔 2、控制点列表 3、松紧程度。tension==1时,样条线是分段直线。tension<1向外松弛弯
//曲,tension>1向内缩紧弯曲。By动作是以当前坐标为新坐标原点。
static CCCardinalSplineBy* create(float duration, CCPointArray* points, float tension);
CCCardinalSplineBy();
virtual void startWithTarget(CCNode *pTarget);
virtual CCActionInterval* reverse();
virtual void updatePosition(CCPoint &newPos);
protected:
CCPoint m_startPosition;
};
/** An action that moves the target with a CatmullRom curve to a destination point.
A Catmull Rom is a Cardinal Spline with a tension of 0.5.
*/
class CC_DLL CCCatmullRomTo : public CCCardinalSplineTo//tension of 0.5.
{
public:
/** creates an action with a Cardinal Spline array of points and tension */
static CCCatmullRomTo* create(float dt, CCPointArray* points);
/** initializes the action with a duration and an array of points */
bool initWithDuration(float dt, CCPointArray* points);
};
/** An action that moves the target with a CatmullRom curve by a certain distance.
A Catmull Rom is a Cardinal Spline with a tension of 0.5.
http://en.wikipedia.org/wiki/Cubic_Hermite_spline#Catmull.E2.80.93Rom_spline
@ingroup Actions
*/
class CC_DLL CCCatmullRomBy : public CCCardinalSplineBy
{
public:
/** creates an action with a Cardinal Spline array of points and tension */
static CCCatmullRomBy* create(float dt, CCPointArray* points);
/** initializes the action with a duration and an array of points */
bool initWithDuration(float dt, CCPointArray* points);
};
/** Returns the Cardinal Spline position for a given set of control points, tension and time */
extern CC_DLL CCPoint ccCardinalSplineAt(CCPoint &p0, CCPoint &p1, CCPoint &p2, CCPoint &p3, float tension, float t);
// end of actions group
/// @}
NS_CC_END;
#endif // __CCACTION_CATMULLROM_H__
- CCActionCatmullRom(样条曲线动作 通过点数组自定义动作曲线)
- CCCardinalSplineBy 样条曲线动作
- B-样条曲线:移动控制点
- 样条曲线反求控制点
- 通过多个三维控制点 实现生成Bezier样条曲线 并通过输入值(按照百分比 输入0-100即可) 得到曲线上的三维坐标
- 三次样条曲线
- 样条曲线
- B样条曲线
- B样条曲线
- B样条曲线
- 样条曲线
- B样条曲线
- B样条曲线
- 样条曲线概述
- 三次样条曲线
- B样条曲线
- B样条曲线
- 三次样条曲线
- BZOJ [ZJOI2009]狼和羊的故事
- MQ简单实例
- 【C语言】16-预处理指令2-条件编译
- 尊重原创,请保证您的文章为原创作品尊重原创,请保证您的文章为原创作品
- DB2 未发出启动数据库管理器的命令
- CCActionCatmullRom(样条曲线动作 通过点数组自定义动作曲线)
- MYSQL中 ENUM 类型
- 【C语言】17-预处理指令3-文件包含
- hdu4118(树形DP)
- TelephonyManager类详解
- C++学习笔记-友元类声明
- 【C语言】18-变量类型
- CCActionEase(可以对动作进行包装 使动作的in和out速度发生改变 使动作更平滑)
- Spring Cache抽象详解