Ocular Engine
PerlinNoise.hpp
1 
17 #pragma once
18 #ifndef __H__OCULAR_MATH_PERLIN_NOISE__H__
19 #define __H__OCULAR_MATH_PERLIN_NOISE__H__
20 
21 #include "ANoise.hpp"
22 #include "Math/Random/ARandom.hpp"
23 
24 #include <memory>
25 #include <array>
26 
27 //------------------------------------------------------------------------------------------
28 
33 namespace Ocular
34 {
39  namespace Math
40  {
45  namespace Noise
46  {
57  class PerlinNoise : public ANoise
58  {
59  public:
60 
61  PerlinNoise();
62  ~PerlinNoise();
63 
73  virtual float getValue(float const x);
74 
86  virtual float getValue(float const x, float const y);
87 
100  virtual float getValue(float const x, float const y, float const z);
101 
111  void setOctaves(uint32_t const octaves);
112 
122  void setPersistence(float const persistence);
123 
135  void setScale(float const scale);
136 
141  void seed(int64_t seed);
142 
143  protected:
144 
145  float getInterpolatedNoise(float const x);
146  float getInterpolatedNoise(float const x, float const y);
147  float getInterpolatedNoise(float const x, float const y, float const z);
148 
149  float getSmoothNoise(float const x, float const y);
150 
151  float getRandom(float const x, float const y);
152 
153  private:
154 
155  uint32_t m_Octaves;
156  float m_Persistence;
157  float m_Scale;
158 
159  std::array<uint32_t, 514> m_Permutations;
160  std::array<float, 514> m_Gradient1;
161  std::array<std::array<float, 2>, 514> m_Gradient2;
162  std::array<std::array<float, 3>, 514> m_Gradient3[514][3];
163 
164  int64_t m_Seed;
165 
166  std::shared_ptr<Random::ARandom> m_PRNG;
167  };
168  }
172  }
176 }
181 //------------------------------------------------------------------------------------------
182 
183 #endif
void seed(int64_t seed)
Definition: PerlinNoise.cpp:112
void setPersistence(float const persistence)
Definition: PerlinNoise.cpp:98
Note: Once this library is made dynamic, this will no longer be needed.
Definition: Common.hpp:70
virtual float getValue(float const x)
Definition: PerlinNoise.cpp:60
Definition: PerlinNoise.hpp:57
void setScale(float const scale)
Definition: PerlinNoise.cpp:103
void setOctaves(uint32_t const octaves)
Definition: PerlinNoise.cpp:93
Definition: ANoise.hpp:48