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