CCPURibbonTrailRender.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. /****************************************************************************
  2. Copyright (C) 2013 Henry van Merode. All rights reserved.
  3. Copyright (c) 2015-2016 Chukong Technologies Inc.
  4. Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
  5. http://www.cocos2d-x.org
  6. Permission is hereby granted, free of charge, to any person obtaining a copy
  7. of this software and associated documentation files (the "Software"), to deal
  8. in the Software without restriction, including without limitation the rights
  9. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  10. copies of the Software, and to permit persons to whom the Software is
  11. furnished to do so, subject to the following conditions:
  12. The above copyright notice and this permission notice shall be included in
  13. all copies or substantial portions of the Software.
  14. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. THE SOFTWARE.
  21. ****************************************************************************/
  22. #ifndef __CC_PU_PARTICLE_3D_RIBBON_TRAIL_RENDER_H__
  23. #define __CC_PU_PARTICLE_3D_RIBBON_TRAIL_RENDER_H__
  24. #include "base/CCRef.h"
  25. #include "math/CCMath.h"
  26. #include "extensions/Particle3D/CCParticle3DRender.h"
  27. #include "extensions/Particle3D/PU/CCPUListener.h"
  28. #include "extensions/Particle3D/PU/CCPURender.h"
  29. #include "extensions/Particle3D/PU/CCPURibbonTrail.h"
  30. #include "extensions/Particle3D/PU/CCPUParticleSystem3D.h"
  31. #include <vector>
  32. NS_CC_BEGIN
  33. class PURibbonTrailVisualData : public Ref
  34. {
  35. public:
  36. //Constructor
  37. PURibbonTrailVisualData (Node* sceneNode, PURibbonTrail* ribbonTrail) :
  38. node(sceneNode),
  39. addedToTrail(false),
  40. trail(ribbonTrail),
  41. index(0){};
  42. Node* node;
  43. bool addedToTrail;
  44. PURibbonTrail* trail;
  45. size_t index;
  46. virtual void setVisible(bool visible)
  47. {
  48. if (visible)
  49. {
  50. if (!addedToTrail)
  51. {
  52. trail->addNode(node);
  53. addedToTrail = true;
  54. }
  55. }
  56. else
  57. {
  58. if (addedToTrail)
  59. {
  60. trail->removeNode(node);
  61. addedToTrail = false;
  62. }
  63. }
  64. }
  65. };
  66. // particle render for quad
  67. class CC_DLL PURibbonTrailRender : public PURender, public PUListener
  68. {
  69. public:
  70. // Constants
  71. static const bool DEFAULT_USE_VERTEX_COLOURS;
  72. static const size_t DEFAULT_MAX_ELEMENTS;
  73. static const float DEFAULT_LENGTH;
  74. static const float DEFAULT_WIDTH;
  75. static const bool DEFAULT_RANDOM_INITIAL_COLOUR;
  76. static const Vec4 DEFAULT_INITIAL_COLOUR;
  77. static const Vec4 DEFAULT_COLOUR_CHANGE;
  78. static PURibbonTrailRender* create(const std::string &texFile = "");
  79. virtual void notifyRescaled(const Vec3& scale) override;
  80. virtual void prepare() override;
  81. virtual void unPrepare() override;
  82. virtual void updateRender(PUParticle3D *particle, float deltaTime, bool firstParticle) override;
  83. virtual void render(Renderer* renderer, const Mat4 &transform, ParticleSystem3D* particleSystem) override;
  84. virtual void particleEmitted(PUParticleSystem3D* particleSystem, PUParticle3D* particle) override;
  85. virtual void particleExpired(PUParticleSystem3D* particleSystem, PUParticle3D* particle) override;
  86. /** Getters and Setters
  87. */
  88. bool isUseVertexColors(void) const;
  89. void setUseVertexColors(bool useVertexColours);
  90. size_t getMaxChainElements(void) const;
  91. void setMaxChainElements(size_t maxChainElements);
  92. float getTrailLength(void) const;
  93. void setTrailLength(float trailLength);
  94. float getTrailWidth(void) const;
  95. void setTrailWidth(float trailWidth);
  96. bool isRandomInitialColor(void) const;
  97. void setRandomInitialColor(bool randomInitialColour);
  98. const Vec4& getInitialColor(void) const;
  99. void setInitialColor(const Vec4& initialColour);
  100. const Vec4& getColorChange(void) const;
  101. void setColorChange(const Vec4& colourChange);
  102. /** Deletes all ChildSceneNodes en Entities.
  103. */
  104. void destroyAll(void);
  105. virtual PURibbonTrailRender* clone() override;
  106. void copyAttributesTo(PURibbonTrailRender *render);
  107. CC_CONSTRUCTOR_ACCESS:
  108. PURibbonTrailRender();
  109. virtual ~PURibbonTrailRender();
  110. void updateParticles(const ParticlePool &pool);
  111. protected:
  112. std::vector<PURibbonTrailVisualData*> _allVisualData;
  113. std::vector<PURibbonTrailVisualData*> _visualData;
  114. size_t _quota;
  115. PURibbonTrail* _trail;
  116. std::string _ribbonTrailName;
  117. bool _useVertexColours;
  118. size_t _maxChainElements;
  119. float _trailLength;
  120. float _trailWidth;
  121. bool _randomInitialColor;
  122. bool _setLength;
  123. bool _setWidth;
  124. Vec4 _initialColor;
  125. Vec4 _colorChange;
  126. Node* _childNode;
  127. std::string _texFile;
  128. };
  129. NS_CC_END
  130. #endif