noise.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /*
  2. Minetest-c55
  3. Copyright (C) 2010-2011 celeron55, Perttu Ahola <celeron55@gmail.com>
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License along
  13. with this program; if not, write to the Free Software Foundation, Inc.,
  14. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  15. */
  16. #ifndef NOISE_HEADER
  17. #define NOISE_HEADER
  18. double easeCurve(double t);
  19. // Return value: -1 ... 1
  20. double noise2d(int x, int y, int seed);
  21. double noise3d(int x, int y, int z, int seed);
  22. double noise2d_gradient(double x, double y, int seed);
  23. double noise3d_gradient(double x, double y, double z, int seed);
  24. double noise2d_perlin(double x, double y, int seed,
  25. int octaves, double persistence);
  26. double noise2d_perlin_abs(double x, double y, int seed,
  27. int octaves, double persistence);
  28. double noise3d_perlin(double x, double y, double z, int seed,
  29. int octaves, double persistence);
  30. double noise3d_perlin_abs(double x, double y, double z, int seed,
  31. int octaves, double persistence);
  32. enum NoiseType
  33. {
  34. NOISE_PERLIN,
  35. NOISE_PERLIN_ABS,
  36. NOISE_PERLIN_CONTOUR,
  37. NOISE_PERLIN_CONTOUR_FLIP_YZ
  38. };
  39. struct NoiseParams
  40. {
  41. NoiseType type;
  42. int seed;
  43. int octaves;
  44. double persistence;
  45. double pos_scale;
  46. double noise_scale; // Useful for contour noises
  47. NoiseParams(NoiseType type_=NOISE_PERLIN, int seed_=0,
  48. int octaves_=3, double persistence_=0.5,
  49. double pos_scale_=100.0, double noise_scale_=1.0):
  50. type(type_),
  51. seed(seed_),
  52. octaves(octaves_),
  53. persistence(persistence_),
  54. pos_scale(pos_scale_),
  55. noise_scale(noise_scale_)
  56. {
  57. }
  58. };
  59. double noise3d_param(const NoiseParams &param, double x, double y, double z);
  60. class NoiseBuffer
  61. {
  62. public:
  63. NoiseBuffer();
  64. ~NoiseBuffer();
  65. void clear();
  66. void create(const NoiseParams &param,
  67. double first_x, double first_y, double first_z,
  68. double last_x, double last_y, double last_z,
  69. double samplelength_x, double samplelength_y, double samplelength_z);
  70. void multiply(const NoiseParams &param);
  71. // Deprecated
  72. void create(int seed, int octaves, double persistence,
  73. bool abs,
  74. double first_x, double first_y, double first_z,
  75. double last_x, double last_y, double last_z,
  76. double samplelength_x, double samplelength_y, double samplelength_z);
  77. void intSet(int x, int y, int z, double d);
  78. void intMultiply(int x, int y, int z, double d);
  79. double intGet(int x, int y, int z);
  80. double get(double x, double y, double z);
  81. private:
  82. double *m_data;
  83. double m_start_x, m_start_y, m_start_z;
  84. double m_samplelength_x, m_samplelength_y, m_samplelength_z;
  85. int m_size_x, m_size_y, m_size_z;
  86. };
  87. #endif