CCPUDoPlacementParticleEventHandler.h 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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_DO_PLACEMENT_PARTICLE_EVENT_HANDLER_H__
  22. #define __CC_PU_PARTICLE_3D_DO_PLACEMENT_PARTICLE_EVENT_HANDLER_H__
  23. #include "base/CCRef.h"
  24. #include "math/CCMath.h"
  25. #include "extensions/Particle3D/PU/CCPUListener.h"
  26. #include "extensions/Particle3D/PU/CCPUEventHandler.h"
  27. #include <vector>
  28. #include <string>
  29. NS_CC_BEGIN
  30. struct PUParticle3D;
  31. class PUObserver;
  32. class PUEmitter;
  33. class PUParticleSystem3D;
  34. class CC_DLL PUDoPlacementParticleEventHandler : public PUEventHandler, public PUListener
  35. {
  36. public:
  37. // Constants
  38. static const unsigned int DEFAULT_NUMBER_OF_PARTICLES;
  39. static PUDoPlacementParticleEventHandler* create();
  40. /** Getters/Setters
  41. */
  42. bool isInheritPosition(void) const {return _inheritPosition;};
  43. bool isInheritDirection(void) const {return _inheritDirection;};
  44. bool isInheritOrientation(void) const {return _inheritOrientation;};
  45. bool isInheritTimeToLive(void) const {return _inheritTimeToLive;};
  46. bool isInheritMass(void) const {return _inheritMass;};
  47. bool isInheritTextureCoordinate(void) const {return _inheritTextureCoordinate;};
  48. bool isInheritColour(void) const {return _inheritColour;};
  49. bool isInheritParticleWidth(void) const {return _inheritParticleWidth;};
  50. bool isInheritParticleHeight(void) const {return _inheritParticleHeight;};
  51. bool isInheritParticleDepth(void) const {return _inheritParticleDepth;};
  52. void setInheritPosition(bool inheritPosition) {_inheritPosition = inheritPosition;};
  53. void setInheritDirection(bool inheritDirection) {_inheritDirection = inheritDirection;};
  54. void setInheritOrientation(bool inheritOrientation) {_inheritOrientation = inheritOrientation;};
  55. void setInheritTimeToLive(bool inheritTimeToLive) {_inheritTimeToLive = inheritTimeToLive;};
  56. void setInheritMass(bool inheritMass) {_inheritMass = inheritMass;};
  57. void setInheritTextureCoordinate(bool inheritTextureCoordinate) {_inheritTextureCoordinate = inheritTextureCoordinate;};
  58. void setInheritColour(bool inheritColour) {_inheritColour = inheritColour;};
  59. void setInheritParticleWidth(bool inheritParticleWidth) {_inheritParticleWidth = inheritParticleWidth;};
  60. void setInheritParticleHeight(bool inheritParticleHeight) {_inheritParticleHeight = inheritParticleHeight;};
  61. void setInheritParticleDepth(bool inheritParticleDepth) {_inheritParticleDepth = inheritParticleDepth;};
  62. /** Get the name of the emitter that is used to emit its particles.
  63. */
  64. const std::string& getForceEmitterName(void) const {return _forceEmitterName;};
  65. /** Set the name of the emitter that is used to emit its particles.
  66. */
  67. void setForceEmitterName(const std::string& forceEmitterName);
  68. /** Returns a pointer to the emitter that is used as a force emitter.
  69. */
  70. PUEmitter* getForceEmitter(void) const;
  71. /** Remove this as a listener from the technique.
  72. @remarks
  73. If a new force-emitter name has been set, the removeAsListener must be called, to remove the DoPlacementParticleEventHandler
  74. from the old technique (to which the force-emitter belongs. Only then the new force-emitter is used.
  75. The reason why it is not called automatically in the setForceEmitterName() function is to offer some flexibility on
  76. the moment the removeAsListener() is called.
  77. */
  78. void removeAsListener(void);
  79. /** Get the number of particles to emit.
  80. */
  81. unsigned int getNumberOfParticles(void) const {return _numberOfParticles;};
  82. /** Set the number of particles to emit.
  83. */
  84. void setNumberOfParticles(unsigned int numberOfParticles){_numberOfParticles = numberOfParticles;};
  85. /** Boolean that determines whether always the position of the particle that is handled must be used for emission of
  86. the new particle.
  87. */
  88. bool alwaysUsePosition(void) const {return _alwaysUsePosition;};
  89. /** Set the boolean to indicate whether the position of the particle that is handled must be used for emission of
  90. the new particle or whether the contact point of the physics actor must be used. This only applies if a physics engine
  91. is used, otherwise the default is used.
  92. */
  93. void setAlwaysUsePosition(bool alwaysUsePosition) {_alwaysUsePosition = alwaysUsePosition;};
  94. /** If the _handle() function of this class is invoked (by an Observer), it searches the
  95. ParticleEmitter defined by the mForceEmitterName. This ParticleEmitter is either part of
  96. the ParticleTechnique in which the DoPlacementParticleEventHandler is defined, and if the ParticleEmitter
  97. is not found, other ParticleTechniques are searched. The ParticleEmitter is 'forced' to emit the
  98. requested number of particles.
  99. */
  100. virtual void handle (PUParticleSystem3D* particleSystem, PUParticle3D* particle, float timeElapsed) override;
  101. /** Initialise the emitted particle. This means that its position is set.
  102. */
  103. virtual void particleEmitted(PUParticleSystem3D* particleSystem, PUParticle3D* particle) override;
  104. /** No implementation.
  105. */
  106. virtual void particleExpired(PUParticleSystem3D* particleSystem, PUParticle3D* particle) override;
  107. virtual void copyAttributesTo (PUEventHandler* eventHandler) override;
  108. CC_CONSTRUCTOR_ACCESS:
  109. PUDoPlacementParticleEventHandler(void);
  110. virtual ~PUDoPlacementParticleEventHandler(void);
  111. protected:
  112. // Identifies the name of emitter
  113. std::string _forceEmitterName;
  114. // The number of particles to emit
  115. unsigned int _numberOfParticles;
  116. /** Store the technique value to keep up to speed.
  117. @remarks
  118. If the ParticleTechnique has been destroyed, the DoPlacementParticleEventHandler isn't automatically
  119. notified. Using the pointer causes an exception.
  120. */
  121. PUParticleSystem3D* _system;
  122. /** Store the emitter value to keep up to speed.
  123. @remarks
  124. If the ParticleEmitter has been destroyed, the DoPlacementParticleEventHandler isn't automatically
  125. notified. Using the pointer causes an exception.
  126. */
  127. PUEmitter* _emitter;
  128. /** Used to determine whether the emitter used by the DoPlacementParticleEventHandler, is already found.
  129. */
  130. bool _found;
  131. /** By default the place where to put a new particle is on the position of the particle in the _handle function. If
  132. mAlwaysUsePosition is set to false, it tries the contact point of the physics actor that is associated with the
  133. particle.
  134. */
  135. bool _alwaysUsePosition;
  136. /** The base particle from which the attributes are inherited
  137. */
  138. PUParticle3D* _baseParticle;
  139. /** These flags are used to determine which attributes must be inherited from the base particle.
  140. */
  141. bool _inheritPosition;
  142. bool _inheritDirection;
  143. bool _inheritOrientation;
  144. bool _inheritTimeToLive;
  145. bool _inheritMass;
  146. bool _inheritTextureCoordinate;
  147. bool _inheritColour;
  148. bool _inheritParticleWidth;
  149. bool _inheritParticleHeight;
  150. bool _inheritParticleDepth;
  151. };
  152. NS_CC_END
  153. #endif