// // ZMLParticleSystem.h // Billiards // // Created by zhu on 2019/2/15. // #ifndef __RUZMLParticleSystem_h #define __RUZMLParticleSystem_h #include #include "cocos2d.h" #include "ParticleSystemModule.h" #include "RUDefine.h" #ifndef PARTICLE_EDITOR_MODE #define PARTICLE_EDITOR_MODE false #endif NS_RU_BEGIN enum ZMLShaderType { SHADER_COLOR = 0, //默认shader SHADER_ALPHA_BLEND, SHADER_DISTORT, SHADER_NORMAL }; typedef enum ZMLShaderType ZMLParticle_Shader_Type; class ClightSprite:public Sprite { public: ClightSprite(){ m_diffuse=Color4F(1, 1, 1, 1); m_ambient=Color4F(1, 1, 1, 1); m_z=0; } virtual~ClightSprite(){ } bool init(const string&texFileName){ Sprite::initWithFile(texFileName.c_str()); return true; } Color4F getDiffuse()const{return m_diffuse;} void setDiffuse(const Color4F& diffuse){ m_diffuse=diffuse; setColor(Color3B(m_diffuse.r*255,m_diffuse.g*255,m_diffuse.b*255)); } Color4F getAmbient()const{return m_ambient;} void setAmbient(const Color4F& ambient){m_ambient=ambient;} float getZ()const{return m_z;} void setZ(float z){m_z=z;} protected: Color4F m_diffuse; Color4F m_ambient; float m_z;//z value of the light }; class Cmaterial{ public: Color4F m_diffuse; Color4F m_ambient; Cmaterial(){ m_diffuse=Color4F(1, 1, 1, 1); m_ambient=Color4F(0.5, 0.5, 0.5, 1); } }; class ZMLParticleDataExpansion { public: float* startColorR; float* startColorG; float* startColorB; float* startColorA; float* deltaColorRAllLife; float* deltaColorGAllLife; float* deltaColorBAllLife; float* deltaColorAAllLife; float* sizeWidth; float* startSizeWidth; float* deltaSizeWidthAllLife; float* sizeHeight; float* startSizeHeighth; float* deltaSizeHeightAllLife; float* startRotation; float* deltaRotationAllLife; float* deltaLifePercentage; float* lifePercentage; int* textureIndex; int* startTextureIndex; float* posz; float* maxSpeendZOffset; float* life; unsigned int maxCount; ZMLParticleDataExpansion(); bool init(int count); void release(); unsigned int getMaxCount() { return maxCount; } void copyParticle(int p1, int p2) { startColorR[p1] = startColorR[p2]; startColorG[p1] = startColorG[p2]; startColorB[p1] = startColorB[p2]; startColorA[p1] = startColorA[p2]; deltaColorRAllLife[p1] = deltaColorRAllLife[p2]; deltaColorGAllLife[p1] = deltaColorGAllLife[p2]; deltaColorBAllLife[p1] = deltaColorBAllLife[p2]; deltaColorAAllLife[p1] = deltaColorAAllLife[p2]; sizeWidth[p1] = sizeWidth[p2]; startSizeHeighth[p1] = startSizeHeighth[p2]; deltaSizeWidthAllLife[p1] = deltaSizeWidthAllLife[p2]; sizeHeight[p1] = sizeHeight[p2]; startSizeHeighth[p1] = startSizeHeighth[p2]; deltaSizeHeightAllLife[p1] = deltaSizeHeightAllLife[p2]; startRotation[p1] = startRotation[p2]; deltaRotationAllLife[p1] = deltaRotationAllLife[p2]; deltaLifePercentage[p1] = deltaLifePercentage[p2]; lifePercentage[p1] = lifePercentage[p2]; textureIndex[p1] = textureIndex[p2]; startTextureIndex[p1] = startTextureIndex[p2]; posz[p1] = posz[p2]; maxSpeendZOffset[p1] = maxSpeendZOffset[p2]; life[p1] = life[p2]; } }; class ZMLParticleSystem : public ParticleSystem{ protected: enum { //纹理旋转结束和起始相同 START_ROTATION_EQUAL_TO_END_ROTATION = -1, //序列帧动画在生命周期内只播放一遍 FRAM_RATE_PLAY_ONCE_IN_ALL_LIFE = -1, //序列帧动画在生命周期内只播放一遍 FRAM_RATE_PLAY_CYCLE = -1, }; public: ZMLParticleSystem(); ~ZMLParticleSystem(); static ZMLParticleSystem *createWithJsonFile(string path); static ZMLParticleSystem *createWithJsonString(string jsonStr); bool initWithJsonFile(string path); bool initWithJsonString(string jsonStr); public: virtual void update(float dt) override; virtual void addParticles(int count); void SetColorPower(float colorPower); void addModule(ParticleSystemModule* module); ParticleSystemModule* getModule(ParticleSystemModuleFlag flag); protected: ZMLParticleDataExpansion _particleDataExpansion; //喷发控制 float _explosiveness_ratio; float* _sizeWidthChangeLaw; float* _sizeHeightChangeLaw; float* _spinChangeLaw; float* _colorAChangeLaw; float* _speedXOffset; float* _speedYOffset; float* _speedZOffset; float _angleEven; float _maxSpeendZOffset; float _posZVar; Vec2 _oldPos; float _launcherangle; float _launcherV; int _texNumber; float _frameRate; float _startSizeWidth; float _startSizeWidthVar; float _endSizeWidth; float _endSizeWidthVar; float _startSizeHeight; float _startSizeHeightVar; float _endSizeHeight; float _endSizeHeightVar; bool _lockAspectRatio; float _aspectRatio; // 风有关的力和变化曲线时间 float _maxWindX; float _maxWindY; float _windCycle; float* _windOffset; float _windTimelinePostion; float _winfTimelineDposPreS; Vec2 _lastAddParticleWordPostion; string _mainTexName; //默认的shader有一定的局限性,添加了一张可选的mask图 string _maskName; float _colorPower; int _shaderType; int moduleFlag; std::map modules; }; NS_RU_END #endif /* __RUZMLParticleSystem_h */