CCPUForceFieldAffector.h 5.9 KB

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