rag
graphic 2d engine
Math.h
1 #ifndef _rag_Math_h
2 #define _rag_Math_h
3 
4 #include <cstdlib>
5 #include <glm/glm.hpp>
6 #include "core/Platform.h"
7 
8 #define DEG2RAD 0.017453292519943
9 #define RAD2DEG 57.2957
10 
11 namespace rag
12 {
13  class Math
14  {
15  public:
16  static float random()
17  {
18  return ((float)rand())/RAND_MAX;
19  }
20 
21  static float random(float min, float max)
22  {
23  return (min + ((max - min) * random()));
24  }
25 
26  // pseudo-random sequence
27  static void resetRandom(unsigned int _seed = 0)
28  {
29  seed = _seed;
30  }
31 
32  static float random(bool fromSequence, const char* log = NULL)
33  {
34  if (fromSequence && seed) {
35  seed = (8253729 * seed + 2396403);
36  float result = (float)(seed & RAND_MAX) / RAND_MAX;
37  LOGI("Math::random : (%s) result=%f", log, result);
38  return result;
39  }
40  else
41  return random();
42  }
43 
44  static float random(float min, float max, bool fromSequence)
45  {
46  return (min + ((max - min) * random(fromSequence)));
47  }
48 
49  static glm::vec2 random2(float minRadius, float maxRadius, bool fromSequence = false)
50  {
51  glm::vec2 result;
52  float radius = 0;
53  do
54  {
55  result.x = random(-maxRadius, maxRadius, fromSequence);
56  result.y = random(-maxRadius, maxRadius, fromSequence);
57 
58  radius = glm::length(result);
59  }
60  while (radius < minRadius && radius > maxRadius);
61  return result;
62  }
63 
64  static const float PI;
65 
66  private:
67  static unsigned int seed;
68  };
69 
70 } //rag
71 
72 
73 #endif
Definition: Bitmap.h:8
Definition: Math.h:13