00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef UTIL_H
00019 #define UTIL_H
00020
00021 #include <math.h>
00022 #include <stdlib.h>
00023 #include <iostream>
00024 #include <vector>
00025 #include <algorithm>
00026 #include <string>
00027 #include "constants.h"
00028 #include "map.h"
00029
00030 using namespace std;
00031
00032 class Map;
00033 class Location;
00034
00042 class CPathNode{
00043 public:
00044 int f, gone, heuristic;
00045 int x, y;
00046 int px, py;
00047
00048 inline bool operator<(const CPathNode &b) {
00049 return this->f < b.f;
00050 }
00051
00052 inline bool operator>(const CPathNode &b) {
00053 return this->f > b.f;
00054 }
00055
00056 };
00057
00058 class Util {
00059 public:
00060
00061 const static char PATH_SEPARATOR = '/';
00062
00063 private:
00064 const static float PI = 3.14159;
00065 public:
00066 Util();
00067 ~Util();
00068
00069 inline static float degreesToRadians(float angle) { return PI / (180.0 / angle); }
00070
00074 static void rotate(Sint16 x, Sint16 y, Sint16 *px, Sint16 *py, float angle);
00075
00076 static void findPath(Sint16 sx, Sint16 sy, Sint16 sz,
00077 Sint16 dx, Sint16 dy, Sint16 dz,
00078 vector<Location> *pVector, Map *map, Shape *shape);
00079
00080
00081 static float dot_product(float v1[3], float v2[3]);
00082 static void normalize(float v[3]);
00083 static void cross_product(const float *v1, const float *v2, float *out);
00084 static void multiply_vector_by_matrix(const float m[9], float v[3]);
00085 static void multiply_vector_by_matrix2(const float m[16], float v[4]);
00086
00087
00088
00089 static char * getOpenGLError();
00090
00091
00092 static string getNextWord(const string theInput, int fromPos, int &endWord);
00093
00094
00095 static float getAngle(float sx, float sy, float sw, float sd,
00096 float tx, float ty, float tw, float td);
00097
00098
00099 static float diffAngle(float a, float b);
00100
00101
00102 enum {
00103 HORIZONTAL_LAYOUT=0,
00104 VERTICAL_LAYOUT
00105 };
00106
00107 static void drawBar( int x, int y, float barLength, float value, float maxValue,
00108 float red=-1, float green=-1, float blue=-1, float gradient=true,
00109 GuiTheme *theme=NULL, int layout=HORIZONTAL_LAYOUT );
00110
00111 inline static float distance2( float x, float y, float z ) { return ( x * x ) + ( y * y ) + ( z * z ); }
00112
00113 };
00114
00115 #endif