CCPULineEmitter.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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_LINE_EMITTER_H__
  23. #define __CC_PU_PARTICLE_3D_LINE_EMITTER_H__
  24. #include "extensions/Particle3D/PU/CCPUEmitter.h"
  25. NS_CC_BEGIN
  26. struct PUParticle3D;
  27. class CC_DLL PULineEmitter : public PUEmitter
  28. {
  29. public:
  30. // Constants
  31. static const Vec3 DEFAULT_END;
  32. static const float DEFAULT_MIN_INCREMENT;
  33. static const float DEFAULT_MAX_INCREMENT;
  34. static const float DEFAULT_MAX_DEVIATION;
  35. static PULineEmitter* create();
  36. /**
  37. */
  38. virtual void notifyStart (void) override;
  39. /** Override the default implementation, to allow that no particles are emitted if there
  40. is an incremental emission of particles (along a path), and the end of the line has
  41. been reached.
  42. */
  43. virtual unsigned short calculateRequestedParticles(float timeElapsed) override;
  44. /**
  45. */
  46. float getMaxDeviation(void) const;
  47. void setMaxDeviation(float maxDeviation);
  48. /**
  49. */
  50. float getMaxIncrement(void) const;
  51. void setMaxIncrement(float maxIncrement);
  52. /**
  53. */
  54. float getMinIncrement(void) const;
  55. void setMinIncrement(float minIncrement);
  56. /** Get the end vector. This is the vector that defines the end of the line (in local space).
  57. */
  58. const Vec3& getEnd(void) const;
  59. /** Set the end vector.
  60. */
  61. void setEnd(const Vec3& end);
  62. /**
  63. */
  64. virtual void notifyRescaled(const Vec3& scale) override;
  65. /**
  66. */
  67. virtual void initParticlePosition(PUParticle3D* particle) override;
  68. /**
  69. */
  70. virtual void initParticleDirection(PUParticle3D* particle) override;
  71. virtual PULineEmitter* clone() override;
  72. virtual void copyAttributesTo (PUEmitter* emitter) override;
  73. CC_CONSTRUCTOR_ACCESS:
  74. PULineEmitter(void);
  75. virtual ~PULineEmitter(void) {};
  76. protected:
  77. Vec3 _end; // End point of the line (startpoint is determined by means of position)
  78. Vec3 _perpendicular; // Generated unit vector perpendicular on the line
  79. float _maxDeviation; // Determines how far from the line a particle is emitted.
  80. // This attribute defines the maximum value.
  81. float _minIncrement; // Defines the minimum increment value.
  82. float _maxIncrement; // If > 0, it defines the maximum (random) increment value that is
  83. // taken on the line traject. If not set, there is no particular
  84. // order in particle generation.
  85. float _increment; // Defines the trajectory path along the line in terms of increments
  86. float _length; // The length of the line
  87. bool _incrementsLeft; // Indicates whether there are more increments on the path towards the end
  88. // of the line.
  89. bool _first; // True when the first particle is emitted (only for generating particles incremental)
  90. // Internal scaled values
  91. Vec3 _scaledEnd;
  92. float _scaledMaxDeviation;
  93. float _scaledMinIncrement;
  94. float _scaledMaxIncrement;
  95. float _scaledLength;
  96. };
  97. NS_CC_END
  98. #endif