2011-03-19 10:59:01 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2010-2011 cocos2d-x.org
|
|
|
|
Copyright (c) 2008, 2009 Jason Booth
|
|
|
|
|
|
|
|
http://www.cocos2d-x.org
|
|
|
|
|
|
|
|
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.
|
|
|
|
****************************************************************************/
|
|
|
|
#ifndef __CCRIBBON_H__
|
|
|
|
#define __CCRIBBON_H__
|
|
|
|
|
|
|
|
/*#include <GLES/egl.h>*/
|
|
|
|
#include "CCNode.h"
|
|
|
|
#include "CCProtocols.h"
|
|
|
|
|
|
|
|
namespace cocos2d {
|
|
|
|
|
2010-12-25 15:09:42 +08:00
|
|
|
class CCRibbonSegment;
|
|
|
|
/**
|
|
|
|
* @brief A CCRibbon is a dynamically generated list of polygons drawn as a single or series
|
|
|
|
* of triangle strips. The primary use of CCRibbon is as the drawing class of Motion Streak,
|
|
|
|
* but it is quite useful on it's own. When manually drawing a ribbon, you can call addPointAt
|
|
|
|
* and pass in the parameters for the next location in the ribbon. The system will automatically
|
|
|
|
* generate new polygons, texture them accourding to your texture width, etc, etc.
|
|
|
|
*
|
|
|
|
* CCRibbon data is stored in a CCRibbonSegment class. This class statically allocates enough verticies and
|
|
|
|
* texture coordinates for 50 locations (100 verts or 48 triangles). The ribbon class will allocate
|
|
|
|
* new segments when they are needed, and reuse old ones if available. The idea is to avoid constantly
|
|
|
|
* allocating new memory and prefer a more static method. However, since there is no way to determine
|
|
|
|
* the maximum size of some ribbons (motion streaks), a truely static allocation is not possible.
|
|
|
|
*
|
|
|
|
* @since v0.8.1
|
|
|
|
*/
|
2011-03-07 17:11:57 +08:00
|
|
|
class CC_DLL CCRibbon : public CCNode, public CCTextureProtocol
|
2010-12-25 15:09:42 +08:00
|
|
|
{
|
|
|
|
/** Texture used by the ribbon. Conforms to CCTextureProtocol protocol */
|
2011-03-07 17:11:57 +08:00
|
|
|
CC_PROPERTY(CCTexture2D*, m_pTexture, Texture)
|
2010-12-25 15:09:42 +08:00
|
|
|
/** Texture lengths in pixels */
|
2011-03-07 17:11:57 +08:00
|
|
|
CC_PROPERTY(float, m_fTextureLength, TextureLength)
|
2010-12-25 15:09:42 +08:00
|
|
|
/** GL blendind function */
|
2011-03-07 17:11:57 +08:00
|
|
|
CC_PROPERTY(ccBlendFunc, m_tBlendFunc, BlendFunc)
|
2010-12-25 15:09:42 +08:00
|
|
|
/** color used by the Ribbon (RGBA) */
|
2011-03-07 17:11:57 +08:00
|
|
|
CC_PROPERTY(ccColor4B, m_tColor, Color)
|
2011-03-19 10:59:01 +08:00
|
|
|
|
2010-12-25 15:09:42 +08:00
|
|
|
public:
|
|
|
|
CCRibbon() : m_pTexture(0), m_pSegments(0), m_pDeletedSegments(0){}
|
|
|
|
virtual ~CCRibbon();
|
2011-03-19 10:59:01 +08:00
|
|
|
|
2010-12-25 15:09:42 +08:00
|
|
|
/** creates the ribbon */
|
|
|
|
static CCRibbon * ribbonWithWidth(float w, const char *path, float length, ccColor4B color, float fade);
|
|
|
|
/** init the ribbon */
|
|
|
|
bool initWithWidth(float w, const char *path, float length, ccColor4B color, float fade);
|
|
|
|
/** add a point to the ribbon */
|
2011-03-07 17:11:57 +08:00
|
|
|
void addPointAt(CCPoint location, float width);
|
2010-12-25 15:09:42 +08:00
|
|
|
/** polling function */
|
|
|
|
void update(ccTime delta);
|
|
|
|
/** determine side of line */
|
2011-03-07 17:11:57 +08:00
|
|
|
float sideOfLine(CCPoint p, CCPoint l1, CCPoint l2);
|
2010-12-25 15:09:42 +08:00
|
|
|
// super method
|
|
|
|
virtual void draw();
|
|
|
|
private:
|
|
|
|
/** rotates a point around 0, 0 */
|
2011-03-07 17:11:57 +08:00
|
|
|
CCPoint rotatePoint(CCPoint vec, float rotation);
|
2010-12-25 15:09:42 +08:00
|
|
|
protected:
|
2011-03-07 17:11:57 +08:00
|
|
|
CCMutableArray<CCRibbonSegment*> *m_pSegments;
|
|
|
|
CCMutableArray<CCRibbonSegment*> *m_pDeletedSegments;
|
2010-08-18 17:56:59 +08:00
|
|
|
|
2011-03-07 17:11:57 +08:00
|
|
|
CCPoint m_tLastPoint1;
|
|
|
|
CCPoint m_tLastPoint2;
|
|
|
|
CCPoint m_tLastLocation;
|
2010-12-25 15:09:42 +08:00
|
|
|
// int m_nVertCount_;
|
|
|
|
float m_fTexVPos;
|
|
|
|
float m_fCurTime;
|
|
|
|
float m_fFadeTime;
|
|
|
|
float m_fDelta;
|
|
|
|
float m_fLastWidth;
|
|
|
|
float m_fLastSign;
|
|
|
|
bool m_bPastFirstPoint;
|
|
|
|
};
|
2010-08-18 17:56:59 +08:00
|
|
|
|
2010-12-25 15:09:42 +08:00
|
|
|
/** @brief object to hold ribbon segment data */
|
2011-03-07 17:11:57 +08:00
|
|
|
class CC_DLL CCRibbonSegment : public CCObject
|
2010-12-25 15:09:42 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
GLfloat m_pVerts[50*6];
|
|
|
|
GLfloat m_pCoords[50*4];
|
|
|
|
GLubyte m_pColors[50*8];
|
|
|
|
float m_pCreationTime[50];
|
|
|
|
bool m_bFinished;
|
|
|
|
unsigned int m_uEnd;
|
|
|
|
unsigned int m_uBegin;
|
|
|
|
public:
|
2011-04-01 16:06:53 +08:00
|
|
|
CCRibbonSegment()
|
|
|
|
: m_bFinished(false)
|
|
|
|
, m_uBegin(0)
|
|
|
|
, m_uEnd(0)
|
|
|
|
{}
|
2010-12-25 15:09:42 +08:00
|
|
|
virtual ~CCRibbonSegment();
|
|
|
|
char * description();
|
|
|
|
bool init();
|
|
|
|
void reset();
|
|
|
|
void draw(float curTime, float fadeTime, ccColor4B color);
|
2011-03-19 10:59:01 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace cocos2d
|
|
|
|
|
2010-08-18 17:56:59 +08:00
|
|
|
#endif //__CCRIBBON_H__
|