-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[TerrainGenerator] Working on new terrain generation. [SimplexNoise] …
…Added.
- Loading branch information
Showing
5 changed files
with
535 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/* | ||
* A speed-improved simplex noise algorithm for 2D, 3D and 4D in Java. | ||
* | ||
* Based on example code by Stefan Gustavson ([email protected]). | ||
* Optimisations by Peter Eastman ([email protected]). | ||
* Better rank ordering method for 4D by Stefan Gustavson in 2012. | ||
* | ||
* This could be speeded up even further, but it's useful as it is. | ||
* | ||
* Version 2012-03-09 | ||
* | ||
* This code was placed in the public domain by its original author, | ||
* Stefan Gustavson. You may use it as you see fit, but | ||
* attribution is appreciated. | ||
* | ||
* Original link: http://staffwww.itn.liu.se/~stegu/simplexnoise/SimplexNoise.java | ||
* Adapted to C++ by Unarelith | ||
* | ||
*/ | ||
#ifndef SIMPLEXNOISE_HPP_ | ||
#define SIMPLEXNOISE_HPP_ | ||
|
||
class SimplexNoise { | ||
public: | ||
// 2D simplex noise | ||
static double noise(double xin, double yin); | ||
|
||
// 3D simplex noise | ||
static double noise(double xin, double yin, double zin); | ||
|
||
// 4D simplex noise | ||
static double noise(double xin, double yin, double zin, double win); | ||
|
||
private: | ||
// Inner class to speed upp gradient computations | ||
// (In Java, array access is a lot slower than member access) | ||
// FIXME: Is C++ different on that topic? | ||
struct Grad { | ||
Grad(double _x, double _y, double _z) : x(_x), y(_y), z(_z) {} | ||
Grad(double _x, double _y, double _z, double _w) : x(_x), y(_y), z(_z), w(_w) {} | ||
|
||
double x = 0; | ||
double y = 0; | ||
double z = 0; | ||
double w = 0; | ||
}; | ||
|
||
// This method is a *lot* faster than using (int)Math.floor(x) | ||
static int fastfloor(double x) { | ||
int xi = (int)x; | ||
return x<xi ? xi-1 : xi; | ||
} | ||
|
||
static double dot(Grad g, double x, double y) { | ||
return g.x*x + g.y*y; | ||
} | ||
|
||
static double dot(Grad g, double x, double y, double z) { | ||
return g.x*x + g.y*y + g.z*z; | ||
} | ||
|
||
static double dot(Grad g, double x, double y, double z, double w) { | ||
return g.x*x + g.y*y + g.z*z + g.w*w; | ||
} | ||
|
||
// Initialization function | ||
static void init(); | ||
|
||
static Grad grad3[12]; | ||
static Grad grad4[32]; | ||
|
||
static unsigned short p[]; | ||
|
||
static short perm[512]; | ||
static short permMod12[512]; | ||
|
||
static double F2; | ||
static double G2; | ||
static double F3; | ||
static double G3; | ||
static double F4; | ||
static double G4; | ||
|
||
static bool isInitialized; | ||
}; | ||
|
||
#endif // SIMPLEXNOISE_HPP_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.