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