RandNoise.cpp 816 B

12345678910111213141516171819202122232425262728293031323334353637
  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. srand(seed);
  12. table = new unsigned short[RandNoiseTableSize];
  13. for (int i = 0; i < RandNoiseTableSize; i++)
  14. table[i] = (unsigned short)(rand() % 0xFFFF);
  15. }
  16. RandNoise::~RandNoise()
  17. {
  18. delete[] table;
  19. }
  20. int RandNoise::getSeed() const
  21. {
  22. return seed;
  23. }
  24. double RandNoise::getNoise(double x, double y, double z)
  25. {
  26. int index = seed % RandNoiseTableSize;
  27. index = abs(table[index] + (int)x) % RandNoiseTableSize;
  28. index = abs(table[index] + (int)y) % RandNoiseTableSize;
  29. index = abs(table[index] + (int)z) % RandNoiseTableSize;
  30. return (double)table[index] / 0xFFFF;
  31. }