summaryrefslogtreecommitdiff
path: root/PerlinNoise.h
diff options
context:
space:
mode:
authormiguel <miguel@localhost>2017-09-23 23:13:25 +0200
committermiguel <miguel@localhost>2017-09-23 23:13:25 +0200
commit41c2d41746582db5439dc51a3c35b60384ea1e4a (patch)
treeb6662d7be627fe298c877b13f22c77b20e6ad71a /PerlinNoise.h
parentdc71cc317b960c5320cdd00171e4d1b37d4144bd (diff)
integrated perlin noise map into game as minimap
Diffstat (limited to 'PerlinNoise.h')
-rw-r--r--PerlinNoise.h28
1 files changed, 28 insertions, 0 deletions
diff --git a/PerlinNoise.h b/PerlinNoise.h
new file mode 100644
index 0000000..9ef109b
--- /dev/null
+++ b/PerlinNoise.h
@@ -0,0 +1,28 @@
+#include <vector>
+
+// THIS CLASS IS A TRANSLATION TO C++11 FROM THE REFERENCE
+// JAVA IMPLEMENTATION OF THE IMPROVED PERLIN FUNCTION (see http://mrl.nyu.edu/~perlin/noise/)
+// THE ORIGINAL JAVA IMPLEMENTATION IS COPYRIGHT 2002 KEN PERLIN
+
+// I ADDED AN EXTRA METHOD THAT GENERATES A NEW PERMUTATION VECTOR (THIS IS NOT PRESENT IN THE ORIGINAL IMPLEMENTATION)
+
+#ifndef PERLINNOISE_H
+#define PERLINNOISE_H
+
+class PerlinNoise {
+ // The permutation vector
+ std::vector<int> p;
+public:
+ // Initialize with the reference values for the permutation vector
+ PerlinNoise();
+ // Generate a new permutation vector based on the value of seed
+ PerlinNoise(unsigned int seed);
+ // Get a noise value, for 2D images z can have any value
+ double noise(double x, double y, double z);
+private:
+ double fade(double t);
+ double lerp(double t, double a, double b);
+ double grad(int hash, double x, double y, double z);
+};
+
+#endif