1
0

CCPUNoise.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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_NOISE_H__
  22. #define __CC_PU_PARTICLE_3D_NOISE_H__
  23. #include "base/CCRef.h"
  24. #include "math/CCMath.h"
  25. NS_CC_BEGIN
  26. class PUNoise3D
  27. {
  28. public:
  29. /* Constructor / Destructor */
  30. PUNoise3D(void);
  31. virtual ~PUNoise3D(void);
  32. /* Inititialises the noise function */
  33. void initialise(unsigned short octaves, double frequency = 1.0, double amplitude = 1.0, double persistence = 1.0);
  34. /* Returns a noise value between [0, 1]
  35. @remarks
  36. The noise is calculated in realtime
  37. */
  38. double noise(double x, double y, double z);
  39. /* Returns a noise value between [0, 1]
  40. @remarks
  41. The noise is calculated in realtime
  42. */
  43. double noise(const Vec3& position);
  44. ///* Creates an image file to test the noise */
  45. //void noise2img(unsigned short dimension = 255);
  46. protected:
  47. /* Returns a noise value between [0, 1]
  48. @remarks
  49. The noise is calculated in realtime
  50. */
  51. double genNoise(double x, double y, double z);
  52. double fade(double t);
  53. double lerp(double t, double a, double b);
  54. double grad(int hash, double x, double y, double z);
  55. protected:
  56. int _p[512];
  57. unsigned short _octaves;
  58. double _frequency;
  59. double _amplitude;
  60. double _persistence;
  61. };
  62. NS_CC_END
  63. #endif