00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 #ifndef DIRECTION_H
00024 #define DIRECTION_H
00025 
00026 
00027 
00028 
00029 enum Direction
00030 {
00031         north = 0,
00032         northeast = 1,
00033         east = 2,
00034         southeast = 3,
00035         south = 4,
00036         southwest = 5,
00037         west = 6,
00038         northwest = 7
00039 };
00040 
00041 
00042 
00043 
00044 const int x_fact[] = {  0, +1, +1, +1,  0, -1, -1, -1 };
00045 const int y_fact[] = { -1, -1,  0, +1, +1, +1,  0, -1 };
00046 
00047 
00048 
00049 
00050 
00051 
00052 
00053 
00054 
00055 
00056 inline Direction Get_direction (int deltay, int deltax)
00057 {
00058         if (deltax == 0)
00059                 return deltay > 0 ? northwest : southeast;
00060         int dydx = (1024*deltay)/deltax;
00061         if (dydx >= 0)
00062                 if (deltax > 0) 
00063                         return dydx <= 424 ? northeast : dydx <= 2472 ? north
00064                                                                 : northwest;
00065                 else                    
00066                         return dydx <= 424 ? southwest : dydx <= 2472 ? south
00067                                                                 : southeast;
00068         else
00069                 if (deltax > 0) 
00070                         return dydx >= -424 ? northeast : dydx >= -2472 ? east
00071                                                                 : southeast;
00072                 else                    
00073                         return dydx >= -424 ? southwest : dydx >= -2472 ? west
00074                                                                 : northwest;
00075 }
00076 
00077 
00078 inline Direction Get_WorldDirection (int deltay, int deltax)
00079 {
00080         if (deltax == 0)
00081                 return deltay > 0 ? south : north;
00082         int dydx = (1024*deltay)/deltax;
00083 
00084         if (dydx >= 0)
00085                 if (deltax > 0) 
00086                         return dydx <= 424 ? east : dydx <= 2472 ? southeast : south;
00087                 else            
00088                         return dydx <= 424 ? west : dydx <= 2472 ? northwest : north;
00089         else
00090                 if (deltax > 0) 
00091                         return dydx >= -424 ? east : dydx >= -2472 ? northeast : north;
00092                 else            
00093                         return dydx >= -424 ? west : dydx >= -2472 ? southwest : south;
00094 }
00095 
00096 
00097 #endif