11 #ifndef MISC_H_INCLUDED
12 #define MISC_H_INCLUDED
15 #include "../headers/types.hpp"
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)); }
26 const Flt Pi_6 = 0.52359878f;
27 const Flt Pi_4 = 0.78539816f;
28 const Flt Pi_3 = 1.04719755f;
29 const Flt Pi_2 = 1.57079633f;
30 const Flt Pi = 3.14159265f;
31 const Flt Pi2 = 6.28318531f;
32 const Flt ToDegrees = 57.29577951f;
33 const Flt ToRadians = 0.017453293f;
35 const Flt Sqrt2 = 1.4142135623730950f;
36 const Flt Sqrt3 = 1.7320508075688773f;
37 const Flt Sqrt2_2 = 0.7071067811865475f;
38 const Flt Sqrt3_3 = 0.5773502691896257f;
44 #endif // MISC_H_INCLUDED