1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- #include "RandNoise.h"
- #include <Random.h>
- #include <stdlib.h>
- #include "Constants.h"
- #include "FastNoiseLite.h"
- #include "FastNoiseWrapper.h"
- #ifndef RAND_MAX
- # define RAND_MAX 0x7FFF
- #endif
- RandNoise::RandNoise(int seed)
- : Noise(),
- seed(seed)
- {
- srand(seed);
- table = new unsigned short[RandNoiseTableSize];
- for (int i = 0; i < RandNoiseTableSize; i++)
- {
- int r = rand();
- table[i] = (unsigned short)(r % RAND_MAX);
- }
- }
- 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] / RAND_MAX;
- }
|