00001 #ifndef PERLINTEXTURE_H
00002 #define PERLINTEXTURE_H
00003
00004 #define PERLINTEXTURE_BASE_SIZE 32
00005 #define PERLINTEXTURE_BASE_SQUARE PERLINTEXTURE_BASE_SIZE * \
00006 PERLINTEXTURE_BASE_SIZE
00007
00008 #define INTERPOLATE(a,b,x) \
00009 (a * (1 - x) + b * x)
00010
00011 #define SCALE_INDEX(a) \
00012 (a % (scale * 32))
00013
00014 enum { NONE = 1, ONE = 2, TWO = 3, THREE = 4};
00015
00016 class PerlinTexture {
00017 public:
00018 PerlinTexture();
00019 inline unsigned char* get_scaled(unsigned char x, unsigned char y) {
00020
00021 unsigned char xx, yy;
00022 xx = SCALE_INDEX(x);
00023 yy = SCALE_INDEX(y);
00024 return data + yy * xx + xx;
00025 }
00026 void refresh();
00027 int get_scale() { return scale; }
00028 void set_scale(int s) { scale = s; }
00029 private:
00030 unsigned char _gen_noise(unsigned char x, unsigned char y);
00031 unsigned char _smooth(unsigned char x, unsigned char y);
00032 int scale;
00033 unsigned char* data;
00034 };
00035
00036 #endif