Honeycomb  0.1
Component-Model Framework
Simplex.h
Go to the documentation of this file.
1 // Honeycomb, Copyright (C) 2015 NewGamePlus Inc. Distributed under the Boost Software License v1.0.
2 #pragma once
3 
4 #include "Honey/Math/Alge/Alge.h"
6 
7 namespace honey
8 {
9 
11 template<class Subclass, int Dim, class Real>
13 {
14 public:
15  typedef Vec<Dim,Real> Vec;
16 
18 
19 protected:
20  typedef Alge_<Real> Alge;
21 
22  int _size;
23  vector<int> _perm;
24 };
25 
27 
32 template<int Dim, class Real>
33 class SimplexNoise : SimplexNoiseCommon<SimplexNoise<Dim,Real>, Dim, Real>
34 {
36  using typename Super::Alge;
37 public:
38  using typename Super::Vec;
39 
45  SimplexNoise(RandomGen& gen, int size = 256);
46 
48 
52  Real noise(const Vec& x, optional<Vec&> dx = optnull);
53 };
54 
56 template<class Real>
57 class SimplexNoise<1, Real> : SimplexNoiseCommon<SimplexNoise<1,Real>, 1, Real>
58 {
60  using typename Super::Alge;
61 public:
62  using typename Super::Vec;
63 
64  SimplexNoise(RandomGen& gen, int size = 256) : Super(gen, size) {}
65  Real noise(const Vec& x, optional<Vec&> dx = optnull);
66 private:
67  void grad(int hash, Real& gx);
68 };
69 
70 template<class Real>
71 class SimplexNoise<2, Real> : SimplexNoiseCommon<SimplexNoise<2,Real>, 2, Real>
72 {
73  typedef SimplexNoiseCommon<SimplexNoise<2,Real>, 2, Real> Super;
74  using typename Super::Alge;
75 public:
76  using typename Super::Vec;
77 
78  SimplexNoise(RandomGen& gen, int size = 256) : Super(gen, size) {}
79  Real noise(const Vec& x, optional<Vec&> dx = optnull);
80 private:
81  void grad(int hash, Real& gx, Real& gy);
82 };
83 
84 template<class Real>
85 class SimplexNoise<3, Real> : SimplexNoiseCommon<SimplexNoise<3,Real>, 3, Real>
86 {
87  typedef SimplexNoiseCommon<SimplexNoise<3,Real>, 3, Real> Super;
88  using typename Super::Alge;
89 public:
90  using typename Super::Vec;
91 
92  SimplexNoise(RandomGen& gen, int size = 256) : Super(gen, size) {}
93  Real noise(const Vec& x, optional<Vec&> dx = optnull);
94 private:
95  void grad(int hash, Real& gx, Real& gy, Real& gz);
96 };
97 
98 template<class Real>
99 class SimplexNoise<4, Real> : SimplexNoiseCommon<SimplexNoise<4,Real>, 4, Real>
100 {
101  typedef SimplexNoiseCommon<SimplexNoise<4,Real>, 4, Real> Super;
102  using typename Super::Alge;
103 public:
104  using typename Super::Vec;
105 
106  SimplexNoise(RandomGen& gen, int size = 256) : Super(gen, size) {}
107  Real noise(const Vec& x, optional<Vec&> dx = optnull);
108 private:
109  void grad(int hash, Real& gx, Real& gy, Real& gz, Real& gw);
110 };
113 extern template class SimplexNoise<1, Float>;
114 extern template class SimplexNoise<2, Float>;
115 extern template class SimplexNoise<3, Float>;
116 extern template class SimplexNoise<4, Float>;
117 
118 extern template class SimplexNoise<1, Double>;
119 extern template class SimplexNoise<2, Double>;
120 extern template class SimplexNoise<3, Double>;
121 extern template class SimplexNoise<4, Double>;
122 
123 }
Algebra.
Definition: Alge.h:13
Random number generator interface.
Definition: Gen.h:11
static optnull_t optnull
Null optional, use to reset an optional to an uninitialized state or test for initialization.
Definition: Optional.h:12
SimplexNoiseCommon(RandomGen &gen, int size)
Definition: Simplex.cpp:12
int _size
Definition: Simplex.h:22
SimplexNoise(RandomGen &gen, int size=256)
Vec< Dim, Real > Vec
Definition: Simplex.h:15
vector< int > _perm
Definition: Simplex.h:23
float Real
Real number type. See Real_ for real number operations and constants.
Definition: Real.h:21
Enables any type to be optional so it can exist in an uninitialized null state.
Definition: Optional.h:52
int size(const StdContainer &cont)
Safely get the size of a std container as a signed integer.
Definition: StdUtil.h:19
Alge_< Real > Alge
Definition: Simplex.h:20
Real noise(const Vec &x, optional< Vec & > dx=optnull)
Get value at point in noise field. Returns noise in range [-1, 1].
Definition: Simplex.cpp:31
Generate smooth noise over space. Implementation of Perlin's "Simplex Noise" generator.
Definition: Simplex.h:33
Global Honeycomb namespace.
Methods common to all simplex noise dimensions.
Definition: Simplex.h:12