fractalNoise.h 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. Copyright (C) 2015 Marien Raat
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 3 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. */
  14. #pragma once
  15. #include <perlinNoise.h>
  16. // This class generates fractal noise. Fractal noise is a fractal like
  17. // form of noise generated by adding multiple perlin noise maps with
  18. // different feature sizes together. This class simplifies generating
  19. // fractal noise from perlin noise. It can generate standard fractal
  20. // noise and custom fractal noise from a list of values.
  21. class FractalNoiseGenerator {
  22. public:
  23. // The constructor of the class
  24. FractalNoiseGenerator(std::mt19937 *mt);
  25. ~FractalNoiseGenerator();
  26. // Generates a standard fractal noise map and saves it in
  27. // this->noiseMap. The strength of every feature size is
  28. // proportional to the root of the feature size. It will sum up
  29. // maps with a feature size down to 2 unless otherwise
  30. // specified. The largest feature size is always min(width,
  31. // height). No more maps will be added once a feature size that
  32. // isn't a divisor of one of the sides is encountered.
  33. void generateStandardFractalNoise(
  34. // The width and height of the fractal noise map
  35. unsigned width,
  36. unsigned height,
  37. // This describes to what power the feature size will be
  38. // raised before the map is multiplied with the result.
  39. // A high value will result in a smooth map and a
  40. // low value will result in a rough maps.
  41. double powerFeatureSizeMultiplier,
  42. // The smalles feature size summed up in the map
  43. unsigned smallestFeatureSize = 2,
  44. // Whether to overwrite the previous fractal noise map or
  45. // allocate new space.
  46. // If the fractal noise map size is different from the previous
  47. // size this decides whether the old map will be deleted,
  48. // since new space needs to be allocated regardless.
  49. bool overwriteOldMap = true);
  50. // Generates a fractal noise map based on the passed values
  51. // array. In this array every two values represent one perlin
  52. // noise map to be added to the fractal noise map. The first value
  53. // of these two represents the feature size of the perlin map and
  54. // the second value represents the weight of this map. The map
  55. // will be multiplied by this weight, before it is added.
  56. void generateFractalNoiseFromValues(
  57. // The values that represent the perlin noise maps to be added
  58. // together.
  59. double *values,
  60. // The length of the values array. So this is 2 times the
  61. // ammount of maps that will be added unto eachother.
  62. unsigned ammountOfValues,
  63. // The width and height of the fractal noise map
  64. unsigned width,
  65. unsigned height,
  66. // Whether to overwrite the previous fractal noise map or
  67. // allocate new space.
  68. // If the fractal noise map size is different from the previous
  69. // size this decides whether the old map will be deleted,
  70. // since new space needs to be allocated regardless.
  71. bool overwriteOldMap = true);
  72. // The noise map that wil be generated by calling either
  73. // generateStandardFractalNoise or generateFractalNoiseFromValues
  74. double *noiseMap;
  75. private:
  76. bool firstNoiseMap;
  77. unsigned previousWidth, previousHeight;
  78. PerlinNoiseGenerator *perlinNoiseGenerator;
  79. };