CCPUBeamRender.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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_BEAM_RENDER_H__
  23. #define __CC_PU_PARTICLE_3D_BEAM_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/CCPUBillboardChain.h"
  29. #include "extensions/Particle3D/PU/CCPURender.h"
  30. #include <vector>
  31. NS_CC_BEGIN
  32. class PUParticle3DBeamVisualData : public Ref
  33. {
  34. public:
  35. PUParticle3DBeamVisualData (size_t index, PUBillboardChain* bbChain) :
  36. chainIndex(index),
  37. timeSinceLastUpdate(0.0f),
  38. billboardChain(bbChain){};
  39. // Set the chain visible or invisible (PU 1.4)
  40. void setVisible(bool visible){/* No implementation */};
  41. /** The is no decent way to make the individual chains/elements invisible. The width of each element is set to 0 to make it invisible.
  42. PU 1.4
  43. */
  44. void setVisible(bool visible, float width)
  45. {
  46. if (!billboardChain)
  47. return;
  48. // Set width to 0 if not visible
  49. width = visible ? width : 0;
  50. size_t max = billboardChain->getMaxChainElements();
  51. PUBillboardChain::Element element;
  52. for (size_t j = 0; j < max; j++)
  53. {
  54. element = billboardChain->getChainElement(chainIndex, j);
  55. element.width = width;
  56. billboardChain->updateChainElement(chainIndex, j, element);
  57. }
  58. }
  59. // Index of the chain
  60. size_t chainIndex;
  61. Vec3 half[100];
  62. Vec3 destinationHalf[100];
  63. float timeSinceLastUpdate;
  64. PUBillboardChain* billboardChain;
  65. };
  66. // particle render for quad
  67. class CC_DLL PUBeamRender : 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_UPDATE_INTERVAL;
  74. static const float DEFAULT_DEVIATION;
  75. static const size_t DEFAULT_NUMBER_OF_SEGMENTS;
  76. static const PUBillboardChain::TexCoordDirection DEFAULT_TEXTURE_DIRECTION;
  77. static PUBeamRender* create(const std::string &texFile = "");
  78. virtual void prepare() override;
  79. virtual void unPrepare() override;
  80. virtual void updateRender(PUParticle3D *particle, float deltaTime, bool firstParticle) override;
  81. virtual void render(Renderer* renderer, const Mat4 &transform, ParticleSystem3D* particleSystem) override;
  82. virtual void particleEmitted(PUParticleSystem3D* particleSystem, PUParticle3D* particle) override;
  83. virtual void particleExpired(PUParticleSystem3D* particleSystem, PUParticle3D* particle) override;
  84. /** Getters and Setters
  85. */
  86. bool isUseVertexColours(void) const;
  87. void setUseVertexColours(bool useVertexColours);
  88. size_t getMaxChainElements(void) const;
  89. void setMaxChainElements(size_t maxChainElements);
  90. float getUpdateInterval(void) const;
  91. void setUpdateInterval(float updateInterval);
  92. float getDeviation(void) const;
  93. void setDeviation(float deviation);
  94. size_t getNumberOfSegments(void) const;
  95. void setNumberOfSegments(size_t numberOfSegments);
  96. bool isJump(void) const;
  97. void setJump(bool jump);
  98. PUBillboardChain::TexCoordDirection getTexCoordDirection(void) const;
  99. void setTexCoordDirection(PUBillboardChain::TexCoordDirection texCoordDirection);
  100. /** Destroys the BillboarChain
  101. */
  102. void destroyAll(void);
  103. virtual PUBeamRender* clone() override;
  104. void copyAttributesTo(PUBeamRender *render);
  105. CC_CONSTRUCTOR_ACCESS:
  106. PUBeamRender();
  107. virtual ~PUBeamRender();
  108. protected:
  109. std::string _texFile;
  110. std::string _billboardChainName;
  111. PUBillboardChain* _billboardChain;
  112. std::vector<PUParticle3DBeamVisualData*> _allVisualData;
  113. std::vector<PUParticle3DBeamVisualData*> _visualData;
  114. size_t _quota;
  115. bool _useVertexColours;
  116. size_t _maxChainElements;
  117. float _updateInterval;
  118. float _deviation;
  119. size_t _numberOfSegments;
  120. bool _jump;
  121. PUBillboardChain::TexCoordDirection _texCoordDirection;
  122. };
  123. NS_CC_END
  124. #endif