Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

perlin.H

Go to the documentation of this file.
00001 /**********************************************************************
00002 * perlin.H:
00003 * perlin texture emulating the built in perlin noise
00004 * by Karol Szerszen
00005 **********************************************************************/
00006 #ifndef PERLIN_TEX_H_IS_INCLUDED
00007 #define PERLIN_TEX_H_IS_INCLUDED
00008 
00009 #include "geom/texturegl.H"
00010 #include "util.H"               // TexUnit
00011  
00012 //on the fly noise properties
00013 #define START_FREQ  4
00014 #define NUM_OCTAVES  4
00015 #define PRESISTANCE  2
00016 
00017 #define SEED_1 107
00018 #define SEED_2 1616
00019 #define SEED_3 4151984
00020 #define SEED_4 112000
00021 
00022 
00023 class Perlin {
00024 
00025 public:
00026 
00027    Perlin();
00028    virtual ~Perlin();
00029 
00030 
00031    //returns a pointer to textureGL with perlin noise 
00032    //these textures are created only once 
00033 
00034    TEXTUREglptr create_perlin_texture3(int tex_stage = TexUnit::PERLIN);
00035    TEXTUREglptr create_perlin_texture2(int tex_stage = TexUnit::PERLIN);
00036 
00037 
00038    //these functions can be used to access the noise value at a specific point
00039    //it will be computed on the fly, they all wrap around [0..1] in all dimensions
00040 
00041    Vec4 noise1(double x);
00042    Vec4 noise2(double x, double y);
00043    Vec4 noise3(double x, double y, double z);
00044    Vec4 noise4(double x, double y, double z, double t);
00045 
00046    //the seed value must be consistant between the calls
00047    //frequency is the number of random samples generated 
00048    inline double getval_1D(int freq, double x, unsigned int seed);
00049    inline double getval_2D(int freq, double x, double y, unsigned int seed);
00050    inline double getval_3D(int freq, double x, double y, double z, unsigned int seed);
00051    double getval_4D(int freq, double x, double y, double z, double t, unsigned int seed);
00052 
00053 
00054    static Perlin* get_instance() { return _instance; };
00055 
00056 protected:
00057 
00058    //the noise uses cubic interpolation between random values
00059    //for maximum user satisfaction :P
00060    inline double noise(unsigned int input);
00061    inline double cubic(double v0, double v1, double v2, double v3, double t);
00062    inline double frac(double);
00063  
00064    // variables
00065    TEXTUREglptr perlin2d_tex;  
00066    TEXTUREglptr perlin3d_tex; 
00067 
00068    static Perlin* _instance;
00069 
00070    //one of my paranoid safety measures
00071    //it remembers the previous instance
00072    Perlin* _previous_instance; 
00073 
00074 };
00075 
00076 #endif // PERLIN_TEX_H_IS_INCLUDED
00077 
00078 // perlin.H

Generated on Mon Sep 18 11:39:32 2006 for jot by  doxygen 1.4.4