123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223 |
- /****************************************************************************
- Copyright (c) 2008-2010 Ricardo Quesada
- Copyright (c) 2009 Leonardo Kasperavičius
- Copyright (c) 2010-2012 cocos2d-x.org
- Copyright (c) 2011 Zynga Inc.
- Copyright (c) 2013-2017 Chukong Technologies Inc.
-
- 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 __RUZMLPARTICLE_SYSTEM_QUAD_H__
- #define __RUZMLPARTICLE_SYSTEM_QUAD_H__
- #include "ZMLParticleSystem.h"
- #include "RUDefine.h"
- NS_RU_BEGIN
- struct PARTICLE_VERTEX_INFO{
- Vec4 TexturePercentage;
- Tex2F bl;
- Tex2F br;
- Tex2F tl;
- Tex2F tr;
- };
- class ZMLParticleSystemQuad : public ZMLParticleSystem
- {
- public:
- /** Creates a Particle Emitter.
- *
- * @return An autoreleased ZMLParticleSystemQuad object.
- */
- static ZMLParticleSystemQuad * create();
- /** Creates a Particle Emitter with a number of particles.
- *
- * @param numberOfParticles A given number of particles.
- * @return An autoreleased ZMLParticleSystemQuad object.
- */
- static ZMLParticleSystemQuad * createWithTotalParticles(int numberOfParticles);
- /** Creates an initializes a ZMLParticleSystemQuad from a plist file.
- This plist files can be created manually or with Particle Designer.
- *
- * @param filename Particle plist file name.
- * @return An autoreleased ZMLParticleSystemQuad object.
- */
- static ZMLParticleSystemQuad * create(const std::string& filename);
- /** Creates a Particle Emitter with a dictionary.
- *
- * @param dictionary Particle dictionary.
- * @return An autoreleased ZMLParticleSystemQuad object.
- */
- static ZMLParticleSystemQuad * create(ValueMap &dictionary);
-
- static ZMLParticleSystemQuad *createWithJsonFile(string path);
-
- static ZMLParticleSystemQuad *createWithJsonString(string jsonStr);
- /** Sets a new texture with a rect. The rect is in Points.
- @since v0.99.4
- * @js NA
- * @lua NA
- *
- * @param texture A given texture.
- 8 @param rect A given rect, in points.
- */
- void setTextureWithRect(Texture2D *texture, const Rect& rect, bool isrotaed, Vec2 offset, Vec2 originalSize);
- /** Listen the event that renderer was recreated on Android/WP8.
- * @js NA
- * @lua NA
- *
- * @param event the event that renderer was recreated on Android/WP8.
- */
- void listenRendererRecreated(EventCustom* event);
- /**
- * @js NA
- * @lua NA
- */
- virtual void setTexture(Texture2D* texture) override;
- /**
- * @js NA
- * @lua NA
- */
- virtual void updateParticleQuads() override;
- /**
- * @js NA
- * @lua NA
- */
- virtual void postStep() override;
- /**
- * @js NA
- * @lua NA
- */
- virtual void draw(Renderer *renderer, const Mat4 &transform, uint32_t flags) override;
- /**
- * @js NA
- * @lua NA
- */
- virtual void setBatchNode(ParticleBatchNode* batchNode) override;
- /**
- * @js NA
- * @lua NA
- */
- virtual void setTotalParticles(int tp) override;
- virtual std::string getDescription() const override;
- void SetAlphaTexture(Texture2D* tex);
- void UpdateGLProgramState();
- CC_CONSTRUCTOR_ACCESS:
- /**
- * @js ctor
- */
- ZMLParticleSystemQuad();
- /**
- * @js NA
- * @lua NA
- */
- virtual ~ZMLParticleSystemQuad();
-
- // Overrides
- /**
- * @js NA
- * @lua NA
- */
- virtual bool initWithTotalParticles(int numberOfParticles) override;
-
-
- void setCbOnExit(std::function<void(const std::string&, ZMLParticleSystem*)> cb);
-
- //normalMap
- void setLightSprite(ClightSprite*lightSprite){
- assert(lightSprite);
- if(m_lightSprite==NULL){
- m_lightSprite=lightSprite;
- m_lightSprite->retain();
- }else{
- m_lightSprite->release();
- m_lightSprite=lightSprite;
- m_lightSprite->retain();
- }
-
- }
- ClightSprite* getLightSprite(){return m_lightSprite;}
- void setKBump(float value){_colorPower = value;}
- float getKBump()const{return _colorPower;}
- protected:
- /** initializes the indices for the vertices*/
- void initIndices();
-
- /** initializes the texture with a rectangle measured Points */
- void initTexCoordsWithRect(const Rect& rect, bool isrotaed, Vec2 offset, Vec2 originalSize);
-
- /** Updates texture coords */
- void updateTexCoords();
- void setupVBOandVAO();
- void setupVBO();
- bool allocMemory();
-
- virtual void onExit() override;
-
- V3F_C4B_T2F_Quad *_quads; // quads to be rendered
- GLushort *_indices; // indices
- GLuint _VAOname;
- GLuint _buffersVBO[2]; //0: vertex 1: indices
- QuadCommand _quadCommand; // quad command
- ClightSprite*m_lightSprite;
- Cmaterial m_material;
-
- CustomCommand _passUnifoAndBindTexCommand;
- void onPassUnifoAndBindTex(const Mat4 &transform, uint32_t flags);
-
- protected:
- // float * _uvleft;
- // float * _uvbottom;
- // float * _uvright;
- // float * _uvtop;
-
- PARTICLE_VERTEX_INFO *_vertexInfo;
- public:
- void addSpriteFrame(SpriteFrame *spriteFrame);
- void addSpriteFrame(const std::string &spriteFrameName);
- void autoUpdateTexture();
- private:
- CC_DISALLOW_COPY_AND_ASSIGN(ZMLParticleSystemQuad);
-
- std::function<void(const std::string&, ZMLParticleSystem*)> _cbOnExit;
- std::string _plName;
- };
- // end of _2d group
- /// @}
- NS_RU_END
- #endif //__RUZMLPARTICLE_SYSTEM_QUAD_H__
|