00001 #ifndef PERLIN_H_ 00002 00003 #define PERLIN_H_ 00004 00005 #include <stdlib.h> 00006 00007 00008 #define SAMPLE_SIZE 1024 00009 00010 class Perlin 00011 { 00012 public: 00013 00014 Perlin(int octaves,float freq,float amp,int seed); 00015 00016 00017 float Get(float x,float y) 00018 { 00019 float vec[2]; 00020 vec[0] = x; 00021 vec[1] = y; 00022 return perlin_noise_2D(vec); 00023 }; 00024 00025 private: 00026 void init_perlin(int n,float p); 00027 float perlin_noise_2D(float vec[2]); 00028 00029 float noise1(float arg); 00030 float noise2(float vec[2]); 00031 float noise3(float vec[3]); 00032 void normalize2(float v[2]); 00033 void normalize3(float v[3]); 00034 void init(void); 00035 00036 int mOctaves; 00037 float mFrequency; 00038 float mAmplitude; 00039 int mSeed; 00040 00041 int p[SAMPLE_SIZE + SAMPLE_SIZE + 2]; 00042 float g3[SAMPLE_SIZE + SAMPLE_SIZE + 2][3]; 00043 float g2[SAMPLE_SIZE + SAMPLE_SIZE + 2][2]; 00044 float g1[SAMPLE_SIZE + SAMPLE_SIZE + 2]; 00045 bool mStart; 00046 00047 }; 00048 00049 #endif 00050