Main Page | Class Hierarchy | Alphabetical List | Data Structures | Directories | File List | Data Fields

util.h

00001 /***************************************************************************
00002                           util.h  -  description
00003                              -------------------
00004     begin                : Sun Jun 22 2003
00005     copyright            : (C) 2003 by Gabor Torok
00006     email                : cctorok@yahoo.com
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
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>    // STL for Vector
00025 #include <algorithm> // STL for Heap
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; // f = gone + heuristic
00045   int x, y;               // Location of node
00046   int px, py;             // Locaton of parent node
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   // todo: make #ifdefs for this
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   // some math functions
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   // Return a string containing the last OpenGL error.
00088   // Useful to debug strange OpenGL behaviors
00089   static char * getOpenGLError();
00090         
00091   // Returns next word from the given position                                          
00092   static string getNextWord(const string theInput, int fromPos, int &endWord);
00093 
00094   // get the angle between two shapes (x,y,width,depth)
00095   static float getAngle(float sx, float sy, float sw, float sd,
00096                         float tx, float ty, float tw, float td);
00097 
00098   // get the difference between a and b ( returns a - b )
00099   static float diffAngle(float a, float b);
00100 
00101   // draw a percentage bar
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

Generated on Thu Jun 16 21:50:43 2005 for scourge by  doxygen 1.4.0