CCPUAffector.h 5.1 KB

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