843c97f18e75fef8b4c99f1ab9a7e474143525a1
[matthijs/ABM2.git] / ABM2 / Engine / misc.h
1 #ifndef MISC_H_INCLUDED\r
2 #define MISC_H_INCLUDED\r
3 \r
4 \r
5 \r
6 inline float clamp(float val, float minVal, float maxVal)\r
7 {\r
8         return min(max(val,minVal),maxVal);\r
9 }\r
10 \r
11 struct frect\r
12 {\r
13         float x1, y1, x2, y2;\r
14         frect(){x1=y1=x2=y1=0;}\r
15         frect(float ux1, float uy1, float ux2, float uy2){x1=ux1; y1=uy1; x2=ux2; y2=uy2; Normalize();}\r
16         void Normalize(){if(x1>x2)std::swap(x1,x2); if(y1>y2)std::swap(y1,y2);}\r
17         frect &operator =(frect &rc){x1=rc.x1; y1=rc.y1; x2=rc.x2; y2=rc.y2; return *this;}\r
18 };\r
19 /*\r
20 float inline pow(float base, int power)\r
21 {\r
22         if(power==1)return base;\r
23         if(power==0)return 1;\r
24         return base*pow(base, power-1);\r
25 }\r
26 */\r
27 float inline frand(int precis=4)\r
28 {\r
29         int val=(int)pow(10.0f,precis);\r
30         return (rand()%val)/(float)val;\r
31 }\r
32 \r
33 void inline InitRandomNumbers()\r
34 {\r
35         srand((unsigned int)time(0));\r
36 }\r
37 \r
38 template<class T>\r
39 T qAbs(T v)\r
40 {\r
41         return (v>0)?v:-v;\r
42 }\r
43 \r
44 class rgba \r
45\r
46 public:\r
47         float r,g,b,a; \r
48         rgba(){r=g=b=a=0.0f;}\r
49         rgba &operator =(rgba &c){r=c.r; g=c.g; b=c.b; a=c.a; return *this;}\r
50 };\r
51 \r
52 \r
53 \r
54 #endif\r