CCPUAffector.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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_AFFECTOR_H__
  23. #define __CC_PU_PARTICLE_3D_AFFECTOR_H__
  24. #include "base/CCRef.h"
  25. #include "math/CCMath.h"
  26. #include "extensions/Particle3D/CCParticle3DAffector.h"
  27. #include <vector>
  28. #include <string>
  29. NS_CC_BEGIN
  30. struct PUParticle3D;
  31. class PUParticleSystem3D;
  32. class CC_DLL PUAffector : public Particle3DAffector
  33. {
  34. friend class PUParticleSystem3D;
  35. public:
  36. /**
  37. The AffectSpecialisation enumeration is used to specialise the affector even more. This enumeration
  38. isn't used by all affectors; in some cases it isn't even applicable.
  39. */
  40. enum AffectSpecialisation
  41. {
  42. AFSP_DEFAULT,
  43. AFSP_TTL_INCREASE,
  44. AFSP_TTL_DECREASE
  45. };
  46. virtual void notifyStart();
  47. virtual void notifyStop();
  48. virtual void notifyPause();
  49. virtual void notifyResume();
  50. virtual void notifyRescaled(const Vec3& scale);
  51. virtual void prepare();
  52. virtual void unPrepare();
  53. virtual void preUpdateAffector(float deltaTime);
  54. virtual void updatePUAffector(PUParticle3D* particle, float delta);
  55. virtual void postUpdateAffector(float deltaTime);
  56. virtual void firstParticleUpdate(PUParticle3D *particle, float deltaTime);
  57. virtual void initParticleForEmission(PUParticle3D* particle);
  58. void process(PUParticle3D* particle, float delta, bool firstParticle);
  59. void setLocalPosition(const Vec3 &pos) { _position = pos; };
  60. const Vec3 getLocalPosition() const { return _position; };
  61. void setMass(float mass);
  62. float getMass() const;
  63. /** Calculate the derived position of the affector.
  64. @remarks
  65. Note, that in script, the position is set as localspace, while if the affector is
  66. emitted, its position is automatically transformed. This function always returns
  67. the derived position.
  68. */
  69. const Vec3& getDerivedPosition();
  70. /** Todo
  71. */
  72. const AffectSpecialisation& getAffectSpecialisation(void) const {return _affectSpecialisation;};
  73. void setAffectSpecialisation(const AffectSpecialisation& affectSpecialisation) {_affectSpecialisation = affectSpecialisation;};
  74. /** Todo
  75. */
  76. const std::string& getAffectorType(void) const {return _affectorType;};
  77. void setAffectorType(const std::string& affectorType) {_affectorType = affectorType;};
  78. /** Add a ParticleEmitter name that excludes Particles emitted by this ParticleEmitter from being
  79. affected.
  80. */
  81. void addEmitterToExclude(const std::string& emitterName);
  82. /** Remove a ParticleEmitter name that excludes Particles emitted by this ParticleEmitter.
  83. */
  84. void removeEmitterToExclude(const std::string& emitterName);
  85. /** Todo
  86. */
  87. const std::string& getName(void) const {return _name;};
  88. void setName(const std::string& name) {_name = name;};
  89. virtual void copyAttributesTo (PUAffector* affector);
  90. CC_CONSTRUCTOR_ACCESS:
  91. PUAffector();
  92. virtual ~PUAffector();
  93. protected:
  94. float calculateAffectSpecialisationFactor (const PUParticle3D* particle);
  95. protected:
  96. Vec3 _position;
  97. /** Although the scale is on a Particle System level, the affector can also be scaled.
  98. */
  99. Vec3 _affectorScale;
  100. /** Because the public attribute position is sometimes used for both localspace and worldspace
  101. position, the mDerivedPosition attribute is introduced.
  102. */
  103. Vec3 _derivedPosition;
  104. /** The mAffectSpecialisation is used to specialise the affector. This attribute is comparable with the
  105. mAutoDirection of the ParticleEmitter, it is an optional attribute and used in some of the Particle
  106. Affectors.
  107. */
  108. AffectSpecialisation _affectSpecialisation;
  109. // Type of the affector
  110. std::string _affectorType;
  111. std::vector<std::string> _excludedEmitters;
  112. // Name of the affector (optional)
  113. std::string _name;
  114. float _mass;
  115. };
  116. NS_CC_END
  117. #endif