arbeit
Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | Compound Members | File Members

PNoise.h

Go to the documentation of this file.
00001 //-------------------------------------------------------------------------
00002 //
00003 //   Joe Kniss
00004 //    Perlin Noise Generator
00005 //  PNoise.h Handles basic perlin noise generation, taken from Ken's 
00006 //    original implementaion, adapted for C++
00007 //     12-9-01
00008 //                   ________    ____   ___ 
00009 //                  |        \  /    | /  /
00010 //                  +---+     \/     |/  /
00011 //                  +--+|  |\    /|     < 
00012 //                  |  ||  | \  / |  |\  \ 
00013 //                  |      |  \/  |  | \  \ 
00014 //                   \_____|      |__|  \__\
00015 //                       Copyright  2001 
00016 //                      Joe Michael Kniss
00017 //               "All Your Base are Belong to Us"
00018 //-------------------------------------------------------------------------
00019 // PNoise.h: interface for the PNoise class.
00020 //
00021 //////////////////////////////////////////////////////////////////////
00022 
00023 #if !defined(AFX_PNOISE_H__C1CDB3F2_6FDA_49C8_BF27_1DEDA73F3EE5__INCLUDED_)
00024 #define AFX_PNOISE_H__C1CDB3F2_6FDA_49C8_BF27_1DEDA73F3EE5__INCLUDED_
00025 
00026 #if _MSC_VER > 1000
00027 #pragma once
00028 #endif // _MSC_VER > 1000
00029 
00030 class PNoise  
00031 {
00032 public:
00033    PNoise();           ///<seeds itself with the time
00034    PNoise(int seed);   ///<you choose the seed
00035    virtual ~PNoise();
00036 
00037    void seed();      ///<seed rand with the time
00038    void seed(int s); ///<specify seed
00039 
00040    /**
00041    In what follows "alpha" is the weight when the sum is formed.
00042    Typically it is 2, As this approaches 1 the function is noisier.
00043    "beta" is the harmonic scaling/spacing, typically 2. "n" is the
00044    number of harmonics to sum.  
00045 
00046    Notice: n, alpha, and beta have default values set.
00047    These match Ken's original calls
00048    */
00049    /// range is -1 -> 1
00050    double PerlinNoise1D(double x,int n =1, double alpha =2,double beta =2);
00051    double PerlinNoise2D(double x,double y,int n =1,double alpha =2,double beta =2);
00052    double PerlinNoise3D(double x,double y,double z,int n =1,double alpha =2,double beta =2);
00053 
00054    /// range is 0 -> 1
00055    double PerlinNoise3DABS(double x,double y,double z,int n =1, double alpha =2,double beta =2);
00056 
00057    // This next set is to simplify calls with aliases
00058    void   setParams(int n, double alpha =2, double beta =2);
00059    double PN1D(double x);
00060    double PN2D(double x, double y);
00061    double PN3D(double x, double y, double z);
00062    double PN3DA(double x, double y, double z);
00063 
00064    // TO DO: fast 2D & 3D field generation, Vector noise
00065 
00066 private:
00067    void init(void);
00068    double noise1(double);
00069    double noise2(double *);
00070    double noise3(double *);
00071    void normalize3(double *);
00072    void normalize2(double *);
00073 
00074    int    *p;
00075    double **g3;
00076    double **g2;
00077    double *g1;
00078    int    start;
00079 
00080    inline int random();
00081 
00082    double _alpha;
00083    double _beta;
00084    int    _n;
00085 
00086 };
00087 
00088 
00089 ///////////////////////////////////////////////////////////////////////
00090 /// generate a texture with perlin noise
00091 ///   allocates space for you, new  
00092 ///    range is always [0-1]
00093 void gen2DPerlinTexture(float *&data, unsigned int sx, unsigned int sy,
00094                         unsigned int   components,      /// greyscale, RGBA, how many??
00095                         int   octaves = 4, 
00096                         float frequencyScale = 2,
00097                         float amplitudeScale = 2,
00098                         bool  absNoise = false);        /// absolute value noise
00099 
00100 void gen3DPerlinTexture(float *&data, unsigned int sx, unsigned int sy, unsigned int sz,
00101                         unsigned int   components,      /// greyscale, RGBA, how many??
00102                         int   octaves = 4, 
00103                         float frequencyScale = 2,
00104                         float amplitudeScale = 2,
00105                         bool  absNoise = false);        /// absolute value noise
00106 
00107 
00108 
00109 
00110 #endif // !defined(AFX_PNOISE_H__C1CDB3F2_6FDA_49C8_BF27_1DEDA73F3EE5__INCLUDED_)

Send questions, comments, and bug reports to:
jmk