RandNoise.cpp 859 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. #include <Random.h>
  2. #include <stdlib.h>
  3. #include "RandNoise.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(x * 4 + y + z * 7, 7 * x + 4 * y + z, x + 7 * y + 4 * z);
  31. assert(n >= 0 && n <= 1);
  32. return n;
  33. }