00001 // $Id: perlinnoise.h,v 1.2 2006/05/24 16:52:41 sean Exp $ 00002 // $Copyright: (c)2001 National Biocomputation Center, Stanford University $ 00003 00004 #ifndef Perlin_Noise_Header 00005 #define Perlin_Noise_Header 00006 00007 // Perlin Noise function from Ken Perline 00008 // http://fundza.com/c4serious/noise/perlin/perlin.html 00009 // 00010 // This class uses the singleton pattern, to prevent from intantiating this 00011 // class more than once. Chris: There's no need to have more than one instance. 00012 // 00013 // Author: Original Java Code: Ken Perlin 00014 // Author: C code: Malcolm Kesson 00015 // Author: C++ code: Chris (caschwan@gmx.net) 00016 // 00017 class PerlinNoise { 00018 00019 public: 00020 00021 static int debug; 00022 static const char* rcsid; 00023 00024 // To get the one and only instance of perlin noise. 00025 static PerlinNoise* Instance(); 00026 00027 // the magic perlin noise function ... 00028 double pnoise(double x, double y, double z); 00029 00030 private: 00031 00032 // private constructors, to disable instantiation more than once (singleton pattern) 00033 PerlinNoise(); 00034 ~PerlinNoise(); 00035 00036 // helper functions 00037 double fade(double t); 00038 double lerp(double t, double a, double b); 00039 double grad(int hash, double x, double y, double z); 00040 00041 // perlin helper values 00042 int p[512]; 00043 00044 // the one and only instance of PerlinNoise 00045 static PerlinNoise* pinstance; 00046 }; 00047 00048 #endif // Perlin_Noise_Header
1.5.3