RandNoise.cpp 915 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #include "RandNoise.h"
  2. #include <Random.h>
  3. #include <stdlib.h>
  4. #include "Constants.h"
  5. #include "FastNoiseLite.h"
  6. #include "FastNoiseWrapper.h"
  7. RandNoise::RandNoise(int seed)
  8. : Noise(),
  9. seed(seed)
  10. {
  11. FastNoiseLite* n = new FastNoiseLite(seed);
  12. n->SetNoiseType(FastNoiseLite::NoiseType::NoiseType_OpenSimplex2S);
  13. n->SetRotationType3D(FastNoiseLite::RotationType3D::RotationType3D_None);
  14. n->SetFrequency(0.333f);
  15. n->SetFractalOctaves(1);
  16. n->SetFractalType(FastNoiseLite::FractalType::FractalType_None);
  17. n->SetDomainWarpAmp(30.f);
  18. noise = new FastNoiseWrapper(n, seed);
  19. }
  20. RandNoise::~RandNoise()
  21. {
  22. delete noise;
  23. }
  24. int RandNoise::getSeed() const
  25. {
  26. return seed;
  27. }
  28. double RandNoise::getNoise(double x, double y, double z)
  29. {
  30. double n = noise->getNoise(
  31. x * 4 + y + z * 7, 7 * x + 4 * y + z, x + 7 * y + 4 * z);
  32. assert(n >= 0 && n <= 1);
  33. return n;
  34. }