vrecko
virtual reality framework
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PerlinNoiseAlgorithm.h
Go to the documentation of this file.
1 
9 #ifndef VRECKO_NATURE_TERRAIN_PERLINNOISE_H
10 #define VRECKO_NATURE_TERRAIN_PERLINNOISE_H
11 
12 #include "TerrainAlgorithm.h"
13 #include "../TerrainUtility.h"
14 #include <osg/Array>
15 
16 namespace APNature
17 {
19  {
20  private:
21 
22  int _permutationTable[514];
23  osg::ref_ptr<osg::Vec2Array> _gradientsTable;
24 
25  public:
26 
32  PerlinNoiseAlgorithm(int width, int height);
33 
44  float GetNoise(float x, float y);
45 
52  float* GenerateNoiseTexture(float frequencyX, float frequencyY);
53 
66  float* GenerateCloudsTexture(std::size_t octaveCount, float persistence);
67 
68  private:
69 
76  void InitTables();
77 
84  static inline float EaseCurve(float t) { return (t * t) * (3.0f - 2.0f * t); }
85 
98  inline osg::Vec2 GetGradient(int x, int y) {
99  return (*_gradientsTable)[ this->_permutationTable[ this->_permutationTable[ x ] + y ] ]; }
100 
112  static inline float InterpolationLinear(float from, float to, float x) { return from + x * (to - from); }
113 
125  static inline float InterpolationCosine(float from, float to, float x) { return from +
126  ((1.0f - cos(x * (float) osg::PI)) * 0.5f) * (to - from); }
127  };
128 
129 }
130 
131 #endif