YSE sound engine  1.0
cross platform sound engine
 All Classes Namespaces Functions Pages
misc.hpp
1 /*
2  ==============================================================================
3 
4  misc.h
5  Created: 29 Jan 2014 11:11:59pm
6  Author: yvan
7 
8  ==============================================================================
9 */
10 
11 #ifndef MISC_H_INCLUDED
12 #define MISC_H_INCLUDED
13 
14 #include <cstdlib>
15 #include "../headers/types.hpp"
16 
17 namespace YSE {
18  template<typename T0, typename T1, typename T2>
19  inline API void Clamp(T0 &x, T1 min, T2 max) { if (x<min)x = min; else if (x>max)x = max; }
20  inline API Int Random(Int max) { return rand() % max; }
21  inline API Int Random(Int min, Int max) { return min + (rand() % (max - min)); }
22  inline API Flt RandomF() { return (float)rand() / (float)RAND_MAX; }
23  inline API Flt RandomF(Flt max) { return (float)rand() / (float)RAND_MAX * max; }
24  inline API Flt RandomF(Flt min, Flt max) { return min + ((float)rand() / (float)RAND_MAX * (max - min)); }
25 
26  const Flt Pi_6 = 0.52359878f; // PI/6 ( 30 deg)
27  const Flt Pi_4 = 0.78539816f; // PI/4 ( 45 deg)
28  const Flt Pi_3 = 1.04719755f; // PI/3 ( 60 deg)
29  const Flt Pi_2 = 1.57079633f; // PI/2 ( 90 deg)
30  const Flt Pi = 3.14159265f; // PI (180 deg)
31  const Flt Pi2 = 6.28318531f; // PI*2 (360 deg)
32  const Flt ToDegrees = 57.29577951f;
33  const Flt ToRadians = 0.017453293f;
34 
35  const Flt Sqrt2 = 1.4142135623730950f; // Sqrt(2)
36  const Flt Sqrt3 = 1.7320508075688773f; // Sqrt(3)
37  const Flt Sqrt2_2 = 0.7071067811865475f; // Sqrt(2)/2
38  const Flt Sqrt3_3 = 0.5773502691896257f; // Sqrt(3)/3
39 }
40 
41 
42 
43 
44 #endif // MISC_H_INCLUDED