NGL  6.5
The NCCA Graphics Library
Random.h
Go to the documentation of this file.
1 
17 #ifndef RANDOM_H_
18 #define RANDOM_H_
19 //----------------------------------------------------------------------------------------------------------------------
22 //----------------------------------------------------------------------------------------------------------------------
23 // must include types.h first for Real and GLEW if required
24 #include "Colour.h"
25 #include "Singleton.h"
26 #include "Vec4.h"
27 
28 #include <unordered_map>
29 #include <random>
30 namespace ngl
31 {
32 
33  //----------------------------------------------------------------------------------------------------------------------
36  //----------------------------------------------------------------------------------------------------------------------
42 
43 
44 //----------------------------------------------------------------------------------------------------------------------
55 
58 
62 //----------------------------------------------------------------------------------------------------------------------
63 
64 
65 
66 class NGL_DLLEXPORT Random : public Singleton<Random>
67 {
68 //----------------------------------------------------------------------------------------------------------------------
70 //----------------------------------------------------------------------------------------------------------------------
71 friend class Singleton<Random>;
72 friend class Colour;
73 friend class Vec4;
74 
75 public :
76 
77  //----------------------------------------------------------------------------------------------------------------------
79  //----------------------------------------------------------------------------------------------------------------------
80  void setSeed();
81  //----------------------------------------------------------------------------------------------------------------------
84  //----------------------------------------------------------------------------------------------------------------------
85  void setSeed( unsigned int _value );
86  //----------------------------------------------------------------------------------------------------------------------
91  //----------------------------------------------------------------------------------------------------------------------
92  Real getFloatFromGeneratorName( const std::string &_name);
93  //----------------------------------------------------------------------------------------------------------------------
95  //----------------------------------------------------------------------------------------------------------------------
96  Colour getRandomColour();
97  //----------------------------------------------------------------------------------------------------------------------
99  //----------------------------------------------------------------------------------------------------------------------
100  Colour getRandomColourAndAlpha();
101  //----------------------------------------------------------------------------------------------------------------------
103  //----------------------------------------------------------------------------------------------------------------------
104  Vec4 getRandomVec4();
105  //----------------------------------------------------------------------------------------------------------------------
107  //----------------------------------------------------------------------------------------------------------------------
108  Vec4 getRandomNormalizedVec4();
109  //----------------------------------------------------------------------------------------------------------------------
111  //----------------------------------------------------------------------------------------------------------------------
112  Vec3 getRandomVec3();
113  //----------------------------------------------------------------------------------------------------------------------
115  //----------------------------------------------------------------------------------------------------------------------
116  Vec3 getRandomNormalizedVec3();
117  //----------------------------------------------------------------------------------------------------------------------
119  //----------------------------------------------------------------------------------------------------------------------
120  Vec2 getRandomVec2();
121  //----------------------------------------------------------------------------------------------------------------------
123  //----------------------------------------------------------------------------------------------------------------------
124  Vec2 getRandomNormalizedVec2();
125 
126  //----------------------------------------------------------------------------------------------------------------------
132  //----------------------------------------------------------------------------------------------------------------------
133  Vec3 getRandomPoint( Real _xRange=1.0, Real _yRange=1.0, Real _zRange=1.0 );
134  //----------------------------------------------------------------------------------------------------------------------
139  //----------------------------------------------------------------------------------------------------------------------
140  Real randomNumber(Real _mult=1);
141  //----------------------------------------------------------------------------------------------------------------------
146  //----------------------------------------------------------------------------------------------------------------------
147  Real randomPositiveNumber( Real _mult=1 );
148  /*
149  //----------------------------------------------------------------------------------------------------------------------
156  //----------------------------------------------------------------------------------------------------------------------
157  void addGenerator( const std::string &_name, RANDDIST _distribution, Real _min=0.0, Real _max=1.0,Real _prob=0.5);
158  */
159 protected :
160 
161  //----------------------------------------------------------------------------------------------------------------------
165 
166  std::mt19937 m_generator;
167  //----------------------------------------------------------------------------------------------------------------------
168 
169  //----------------------------------------------------------------------------------------------------------------------
171  //----------------------------------------------------------------------------------------------------------------------
172  Random();
173  //----------------------------------------------------------------------------------------------------------------------
177  //----------------------------------------------------------------------------------------------------------------------
178  std::unordered_map<std::string, std::uniform_real_distribution<Real> > m_floatGenerators;
179 
180 };
181 
182 }// end namespace
183 
184 #endif
185 //----------------------------------------------------------------------------------------------------------------------
186 
187 
simple Vec2 encapsulates a 3 float object like glsl Vec2 but not maths use the Vec2 class for maths a...
Definition: Vec2.h:49
simple class to hold colour information and set the basic opengl colour state. also has overloaded me...
Definition: Colour.h:40
simple Vector class for OpenGL graphics, contains overloaded operators for most math functions...
Definition: Vec4.h:57
a simple colour class for RGBA colour
#define NGL_DLLEXPORT
Definition: Types.h:65
wrapper for std random and distribution functions, it will generate two basic random functions for Ra...
Definition: Random.h:66
simple Vec3 encapsulates a 3 float object like glsl vec3 but not maths use the Vec3 class for maths a...
Definition: Vec3.h:51
implementation files for RibExport class
Definition: AABB.cpp:22
PRECISION Real
create a variable called Real which is the main data type we use (GLfloat for most cases) ...
Definition: Types.h:127
encapsulates a 4d Homogenous Point / Vector object
std::unordered_map< std::string, std::uniform_real_distribution< Real > > m_floatGenerators
our map to hold the generator data basically we are going to hold a name / function pair...
Definition: Random.h:178
std::mt19937 m_generator
the generator for rng class where all funcs and distribs are added. all we need to do is replace this...
Definition: Random.h:166
a simple singleton template inherited by other classes
GLsizei const GLchar *const * string
Definition: glew.h:1847
RANDDIST
enumerated list of the different distributions we can add to the generator,
Definition: Random.h:37
Singleton template added to NGL framework 20/04/10 by jmacey.
Definition: Singleton.h:40