CCPUForceFieldAffector.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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_FORCE_FIELD_AFFECTOR_H__
  23. #define __CC_PU_PARTICLE_3D_FORCE_FIELD_AFFECTOR_H__
  24. #include "extensions/Particle3D/PU/CCPUAffector.h"
  25. #include "extensions/Particle3D/PU/CCPUForceField.h"
  26. NS_CC_BEGIN
  27. class CC_DLL PUForceFieldAffector : public PUAffector
  28. {
  29. public:
  30. // Constants
  31. static const PUForceField::ForceFieldType DEFAULT_FORCEFIELD_TYPE;
  32. static const float DEFAULT_DELTA;
  33. static const float DEFAULT_FORCE;
  34. static const unsigned short DEFAULT_OCTAVES;
  35. static const double DEFAULT_FREQUENCY;
  36. static const double DEFAULT_AMPLITUDE;
  37. static const double DEFAULT_PERSISTENCE;
  38. static const unsigned int DEFAULT_FORCEFIELDSIZE;
  39. static const Vec3 DEFAULT_WORLDSIZE;
  40. static const Vec3 DEFAULT_MOVEMENT;
  41. static const float DEFAULT_MOVEMENT_FREQUENCY;
  42. static PUForceFieldAffector* create();
  43. virtual void notifyStart() override;
  44. virtual void preUpdateAffector(float deltaTime) override;
  45. virtual void updatePUAffector(PUParticle3D *particle, float deltaTime) override;
  46. virtual void prepare() override;
  47. /** Get/Set Forcefield type
  48. */
  49. PUForceField::ForceFieldType getForceFieldType() const;
  50. void setForceFieldType(const PUForceField::ForceFieldType forceFieldType);
  51. /** Get/Set Delta
  52. */
  53. float getDelta(void) const;
  54. void setDelta(float delta);
  55. /** Get/Set scale Force
  56. */
  57. float getScaleForce(void) const;
  58. void setScaleForce(float scaleForce);
  59. /** Get/Set scale Octaves
  60. */
  61. unsigned short getOctaves(void) const;
  62. void setOctaves(unsigned short octaves);
  63. /** Get/Set scale Frequency
  64. */
  65. double getFrequency(void) const;
  66. void setFrequency(double frequency);
  67. /** Get/Set scale Amplitude
  68. */
  69. double getAmplitude(void) const;
  70. void setAmplitude(double amplitude);
  71. /** Get/Set scale Persistence
  72. */
  73. double getPersistence(void) const;
  74. void setPersistence(double persistence);
  75. /** Get/Set scale ForceFieldSize
  76. */
  77. unsigned int getForceFieldSize(void) const;
  78. void setForceFieldSize(unsigned int forceFieldSize);
  79. /** Get/Set scale worldSize
  80. */
  81. Vec3 getWorldSize(void) const;
  82. void setWorldSize(const Vec3& worldSize);
  83. /** Get/Set scale flip attributes
  84. */
  85. bool getIgnoreNegativeX(void) const;
  86. void setIgnoreNegativeX(bool ignoreNegativeX);
  87. bool getIgnoreNegativeY(void) const;
  88. void setIgnoreNegativeY(bool ignoreNegativeY);
  89. bool getIgnoreNegativeZ(void) const;
  90. void setIgnoreNegativeZ(bool ignoreNegativeZ);
  91. /** Get/Set Movement
  92. @remarks
  93. The movement vector determines the position of the movement. This movement is a displacement of the particle position
  94. mapped to the forcefield.
  95. */
  96. const Vec3& getMovement(void) const;
  97. void setMovement(const Vec3& movement);
  98. /** Get/Set Movement frequency
  99. */
  100. float getMovementFrequency(void) const;
  101. void setMovementFrequency(float movementFrequency);
  102. /** Suppress (re)generation of the forcefield everytime an attribute is changed.
  103. */
  104. void suppressGeneration(bool suppress);
  105. virtual void copyAttributesTo (PUAffector* affector) override;
  106. CC_CONSTRUCTOR_ACCESS:
  107. PUForceFieldAffector();
  108. ~PUForceFieldAffector();
  109. protected:
  110. PUForceField _forceField; // Local force field
  111. PUForceField::ForceFieldType _forceFieldType; // Type of force field
  112. float _delta; // Radius of particle position
  113. Vec3 _force; // Force value that is used to calculate the force and reused for all particles
  114. float _scaleForce; // Scaling factor used in calculation of the direction vector of the particle
  115. unsigned short _octaves; // Used in noise generation
  116. double _frequency; // Used in noise generation
  117. double _amplitude; // Used in noise generation
  118. double _persistence; // Used in noise generation
  119. unsigned int _forceFieldSize; // The real size of the force field (is a unit cube in case of a 'realtime' force field type
  120. Vec3 _worldSize; // Size of the force field in world coordinates (can be non-cubic)
  121. bool _prepared; // Determines whether the force field is generated
  122. bool _ignoreNegativeX; // X-force is never negative
  123. bool _ignoreNegativeY; // Y-force is never negative
  124. bool _ignoreNegativeZ; // Z-force is never negative
  125. Vec3 _movement; // The direction to which the forcefield moves
  126. bool _movementSet; // Is true if the movement is set
  127. float _movementFrequency; // Speed of movement
  128. float _movementFrequencyCount;
  129. Vec3 _displacement;
  130. Vec3 _basePosition;
  131. bool _suppressGeneration; // Prevents re-generation of the complete forcefield after a change.
  132. };
  133. NS_CC_END
  134. #endif