| 1 | // Noise1234 |
| 2 | // Author: Stefan Gustavson (stegu@itn.liu.se) |
| 3 | // |
| 4 | // This library is public domain software, released by the author |
| 5 | // into the public domain in February 2011. You may do anything |
| 6 | // you like with it. You may even remove all attributions, |
| 7 | // but of course I'd appreciate it if you kept my name somewhere. |
| 8 | // |
| 9 | // This library is distributed in the hope that it will be useful, |
| 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12 | // General Public License for more details. |
| 13 | |
| 14 | /** \file |
| 15 | \brief Declares the Noise1234 class for producing Perlin noise. |
| 16 | \author Stefan Gustavson (stegu@itn.liu.se) |
| 17 | */ |
| 18 | |
| 19 | /* |
| 20 | * This is a clean, fast, modern and free Perlin noise class in C++. |
| 21 | * Being a stand-alone class with no external dependencies, it is |
| 22 | * highly reusable without source code modifications. |
| 23 | * |
| 24 | * Note: |
| 25 | * Replacing the "float" type with "double" can actually make this run faster |
| 26 | * on some platforms. A templatized version of Noise1234 could be useful. |
| 27 | */ |
| 28 | |
| 29 | class Noise1234 { |
| 30 | |
| 31 | public: |
| 32 | Noise1234() {} |
| 33 | ~Noise1234() {} |
| 34 | |
| 35 | /** 1D, 2D, 3D and 4D float Perlin noise, SL "noise()" |
| 36 | */ |
| 37 | static float noise( float x ); |
| 38 | static float noise( float x, float y ); |
| 39 | static float noise( float x, float y, float z ); |
| 40 | static float noise( float x, float y, float z, float w ); |
| 41 | |
| 42 | /** 1D, 2D, 3D and 4D float Perlin periodic noise, SL "pnoise()" |
| 43 | */ |
| 44 | static float pnoise( float x, int px ); |
| 45 | static float pnoise( float x, float y, int px, int py ); |
| 46 | static float pnoise( float x, float y, float z, int px, int py, int pz ); |
| 47 | static float pnoise( float x, float y, float z, float w, |
| 48 | int px, int py, int pz, int pw ); |
| 49 | |
| 50 | private: |
| 51 | static unsigned char perm[]; |
| 52 | static float grad( int hash, float x ); |
| 53 | static float grad( int hash, float x, float y ); |
| 54 | static float grad( int hash, float x, float y , float z ); |
| 55 | static float grad( int hash, float x, float y, float z, float t ); |
| 56 | |
| 57 | }; |
| 58 | |