CCPUBeamRender.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /****************************************************************************
  2. Copyright (C) 2013 Henry van Merode. All rights reserved.
  3. Copyright (c) 2015-2017 Chukong Technologies Inc.
  4. http://www.cocos2d-x.org
  5. Permission is hereby granted, free of charge, to any person obtaining a copy
  6. of this software and associated documentation files (the "Software"), to deal
  7. in the Software without restriction, including without limitation the rights
  8. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. copies of the Software, and to permit persons to whom the Software is
  10. furnished to do so, subject to the following conditions:
  11. The above copyright notice and this permission notice shall be included in
  12. all copies or substantial portions of the Software.
  13. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  14. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  15. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  16. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  17. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  18. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  19. THE SOFTWARE.
  20. ****************************************************************************/
  21. #ifndef __CC_PU_PARTICLE_3D_BEAM_RENDER_H__
  22. #define __CC_PU_PARTICLE_3D_BEAM_RENDER_H__
  23. #include "base/CCRef.h"
  24. #include "math/CCMath.h"
  25. #include "extensions/Particle3D/CCParticle3DRender.h"
  26. #include "extensions/Particle3D/PU/CCPUListener.h"
  27. #include "extensions/Particle3D/PU/CCPUBillboardChain.h"
  28. #include "extensions/Particle3D/PU/CCPURender.h"
  29. #include <vector>
  30. NS_CC_BEGIN
  31. class PUParticle3DBeamVisualData : public Ref
  32. {
  33. public:
  34. PUParticle3DBeamVisualData (size_t index, PUBillboardChain* bbChain) :
  35. chainIndex(index),
  36. timeSinceLastUpdate(0.0f),
  37. billboardChain(bbChain){};
  38. // Set the chain visible or invisible (PU 1.4)
  39. void setVisible(bool visible){/* No implementation */};
  40. /** 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.
  41. PU 1.4
  42. */
  43. void setVisible(bool visible, float width)
  44. {
  45. if (!billboardChain)
  46. return;
  47. // Set width to 0 if not visible
  48. width = visible ? width : 0;
  49. size_t max = billboardChain->getMaxChainElements();
  50. PUBillboardChain::Element element;
  51. for (size_t j = 0; j < max; j++)
  52. {
  53. element = billboardChain->getChainElement(chainIndex, j);
  54. element.width = width;
  55. billboardChain->updateChainElement(chainIndex, j, element);
  56. }
  57. }
  58. // Index of the chain
  59. size_t chainIndex;
  60. Vec3 half[100];
  61. Vec3 destinationHalf[100];
  62. float timeSinceLastUpdate;
  63. PUBillboardChain* billboardChain;
  64. };
  65. // particle render for quad
  66. class CC_DLL PUBeamRender : public PURender, public PUListener
  67. {
  68. public:
  69. // Constants
  70. static const bool DEFAULT_USE_VERTEX_COLOURS;
  71. static const size_t DEFAULT_MAX_ELEMENTS;
  72. static const float DEFAULT_UPDATE_INTERVAL;
  73. static const float DEFAULT_DEVIATION;
  74. static const size_t DEFAULT_NUMBER_OF_SEGMENTS;
  75. static const PUBillboardChain::TexCoordDirection DEFAULT_TEXTURE_DIRECTION;
  76. static PUBeamRender* create(const std::string &texFile = "");
  77. virtual void prepare() override;
  78. virtual void unPrepare() override;
  79. virtual void updateRender(PUParticle3D *particle, float deltaTime, bool firstParticle) override;
  80. virtual void render(Renderer* renderer, const Mat4 &transform, ParticleSystem3D* particleSystem) override;
  81. virtual void particleEmitted(PUParticleSystem3D* particleSystem, PUParticle3D* particle) override;
  82. virtual void particleExpired(PUParticleSystem3D* particleSystem, PUParticle3D* particle) override;
  83. /** Getters and Setters
  84. */
  85. bool isUseVertexColours(void) const;
  86. void setUseVertexColours(bool useVertexColours);
  87. size_t getMaxChainElements(void) const;
  88. void setMaxChainElements(size_t maxChainElements);
  89. float getUpdateInterval(void) const;
  90. void setUpdateInterval(float updateInterval);
  91. float getDeviation(void) const;
  92. void setDeviation(float deviation);
  93. size_t getNumberOfSegments(void) const;
  94. void setNumberOfSegments(size_t numberOfSegments);
  95. bool isJump(void) const;
  96. void setJump(bool jump);
  97. PUBillboardChain::TexCoordDirection getTexCoordDirection(void) const;
  98. void setTexCoordDirection(PUBillboardChain::TexCoordDirection texCoordDirection);
  99. /** Destroys the BillboarChain
  100. */
  101. void destroyAll(void);
  102. virtual PUBeamRender* clone() override;
  103. void copyAttributesTo(PUBeamRender *render);
  104. CC_CONSTRUCTOR_ACCESS:
  105. PUBeamRender();
  106. virtual ~PUBeamRender();
  107. protected:
  108. std::string _texFile;
  109. std::string _billboardChainName;
  110. PUBillboardChain* _billboardChain;
  111. std::vector<PUParticle3DBeamVisualData*> _allVisualData;
  112. std::vector<PUParticle3DBeamVisualData*> _visualData;
  113. size_t _quota;
  114. bool _useVertexColours;
  115. size_t _maxChainElements;
  116. float _updateInterval;
  117. float _deviation;
  118. size_t _numberOfSegments;
  119. bool _jump;
  120. PUBillboardChain::TexCoordDirection _texCoordDirection;
  121. };
  122. NS_CC_END
  123. #endif