12345678910111213141516171819202122232425262728293031323334353637 |
- #include "RandNoise.h"
- #include <Random.h>
- #include <stdlib.h>
- #include "Constants.h"
- #include "FastNoiseLite.h"
- #include "FastNoiseWrapper.h"
- RandNoise::RandNoise(int seed)
- : Noise(),
- seed(seed)
- {
- srand(seed);
- table = new unsigned short[RandNoiseTableSize];
- for (int i = 0; i < RandNoiseTableSize; i++)
- table[i] = (unsigned short)(rand() % 0xFFFF);
- }
- RandNoise::~RandNoise()
- {
- delete[] table;
- }
- int RandNoise::getSeed() const
- {
- return seed;
- }
- double RandNoise::getNoise(double x, double y, double z)
- {
- int index = seed % RandNoiseTableSize;
- index = abs(table[index] + (int)x) % RandNoiseTableSize;
- index = abs(table[index] + (int)y) % RandNoiseTableSize;
- index = abs(table[index] + (int)z) % RandNoiseTableSize;
- return (double)table[index] / 0xFFFF;
- }
|