PerlinNoise.h

00001 #ifndef PERLIN_NOISE_
00002 #define PERLIN_NOISE_
00003 
00004 #include <math.h>
00005 #include <stdio.h>
00006 #include <windows.h>
00007 #include <GL/gl.h>
00008 #include <GL/glu.h>
00009 #include <GL/glut.h>
00010 
00011 #include "Geometry.h"
00012 
00013 #define LINEAR_INTERPOLATION            0
00014 #define COSINE_INTERPOLATION            1
00015 #define CUBIC_INTERPOLATION                     2
00016 
00017 
00046 class PerlinNoise
00047 {
00048 public:
00056         PerlinNoise (int size_x, int size_y);
00057 
00061         ~PerlinNoise ();
00062 
00072         void SetForegroundColor (float red, float green, float blue, float alpha);
00073 
00083         void SetBackgroundColor (float red, float green, float blue, float alpha);
00084 
00096         void SetParameters (float frequency, float persistence, int octaves, bool smooth);
00097 
00105         void SetInterpolationMode (int mode);
00106 
00116         void TransformXY (float (* processor)(float x, float y, float value));
00117 
00130         void TransformAB (float a, float b, float (* processor)(float a, float b, float value));
00131 
00137         void GenerateNoise ();
00138 
00148         void ExportRGB256 (GLubyte * data_pointer);
00149 
00158         void Export (float * data_pointer);
00159 
00168         void GetDimensions (int &dim_x, int &dim_y);
00169 
00173         void Push ();
00174 
00182         void FlushToColorBuffer ();
00183 
00193         void CombineColorBuffers (float (* combiner)(float val_1, float val_2));
00194 
00207         void CombineColorBuffersAB (float a, float b, float (* combiner)(float a, float b, float val_1, float val_2));
00208 
00215         void SmoothBorder (int border);
00216 
00217 
00218 private:
00222         PerlinNoise ();
00223 
00227         void Pop ();
00228 
00232         bool IsEmpty ();
00233 
00242         float GetSmoothedValue (float x, float y);
00243 
00250         float GetNoiseValue (float x, float y);
00251 
00258         float GetNoise2D (int x, int y);
00259 
00268         float Interpolate (float value_1, float value_2, float fraction);
00269 
00277         float LinearInterpolation (float value_1, float value_2, float fraction);
00278 
00287         float CosineInterpolation (float value_1, float value_2, float fraction);
00288 
00297         float CubicInterpolation (float value_1, float value_2, float fraction);
00298 
00300         int size_x;
00301 
00303         int size_y;
00304 
00306         typedef struct StackElem
00307         {
00308                 float background[4];                            
00309                 float foreground[4];                            
00310                 float frequency;                                        
00311                 float persistence;                                      
00312                 int octaves;                                            
00313                 bool smooth;                                            
00314                 int interpolation;                                      
00316                 float * perlin_buffer;                          
00317                 float * color_buffer;                           
00319                 StackElem * next;                                       
00320         }PerlinStack;
00321 
00322         PerlinStack * top;                                              
00325 //-------------------------------------------------------------------------------------------
00326 //                                                              PREDEFINED ROUTINES
00327 //-------------------------------------------------------------------------------------------
00328 public:
00329 
00340         static float RangeTransform (float a, float b, float perlin_xy);
00341 
00350         static float LinearTransform (float a, float b, float perlin_xy);
00351 
00360         static float MarblyTransform (float x, float y, float perlin_xy);
00361 
00370         static float GrainyTransform (float x, float y, float perlin_xy);
00371 
00380         static float SumCombiner (float val_1, float val_2);
00381 
00390         static float ProductCombiner (float val_1, float val_2);
00391 
00400         static float MaximumCombiner (float val_1, float val_2);
00401 
00412         static float WeightedSumCombiner (float weight_1, float weight_2, float val_1, float val_2);
00413 };
00414 
00415 
00416 #endif

Generated on Sun Jul 2 13:20:39 2006 for Demo by  doxygen 1.4.6-NO