include/utility.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *            utility.h
00003  *
00004  *  Sat Mar 26 08:48:31 2005
00005  *  Copyright  2005  Joe Venzon
00006  *  joe@venzon.net
00007  ****************************************************************************/
00008 
00009 /*
00010  *  This program is free software; you can redistribute it and/or modify
00011  *  it under the terms of the GNU General Public License as published by
00012  *  the Free Software Foundation; either version 2 of the License, or
00013  *  (at your option) any later version.
00014  *
00015  *  This program is distributed in the hope that it will be useful,
00016  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  *  GNU Library General Public License for more details.
00019  *
00020  *  You should have received a copy of the GNU General Public License
00021  *  along with this program; if not, write to the Free Software
00022  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00023  */
00024  
00025 //#define GL_GLEXT_PROTOTYPES
00026  
00027 #ifndef _UTILITY_H
00028 
00029 #include <stdio.h>
00030 #include <stdlib.h>
00031 #include <GL/gl.h>
00032 #include <GL/glu.h>
00033 #include <GL/glext.h>
00034 #include <SDL/SDL.h>
00035 #ifdef __APPLE__
00036 #include <SDL_image/SDL_image.h>
00037 #else
00038 #include <SDL/SDL_image.h>
00039 #endif
00040 #include <math.h>
00041 #include <string>
00042 #include <fstream>
00043 #include <iostream>
00044 
00045 #include <map>
00046 #include <list>
00047 
00048 #include "quat.h"
00049 #include "cardinfo.h"
00050 #include "globals.h"
00051 
00052 using namespace std;
00053 
00054 #define ENDOFFILESTRING "!!!END OF FILE!!!"
00055 
00056 #define EPSILON 0.000001
00057 //#define EPSILON 0.00001
00058 #define CROSS(dest,v1,v2) \
00059           dest[0]=v1[1]*v2[2]-v1[2]*v2[1]; \
00060           dest[1]=v1[2]*v2[0]-v1[0]*v2[2]; \
00061           dest[2]=v1[0]*v2[1]-v1[1]*v2[0];
00062 #define DOT(v1,v2) (v1[0]*v2[0]+v1[1]*v2[1]+v1[2]*v2[2])
00063 #define SUB(dest,v1,v2) \
00064           dest[0]=v1[0]-v2[0]; \
00065           dest[1]=v1[1]-v2[1]; \
00066           dest[2]=v1[2]-v2[2]; 
00067           
00068 #ifdef ENABLE_NLS
00069         #include <libintl.h>
00070         #include <locale.h>
00071         #define _(string) gettext (string.c_str ())
00072         #define _c(string) gettext (string)
00073 #else
00074         #define _(string) (string)
00075         #define _c(string) (string)
00076 #endif
00077 
00078 //#define TEST_CULL
00079 
00080 class TEXTURE_HANDLE;
00081 
00082 class UTILITY
00083 {
00084 private:
00085         ofstream error_log;
00086         GLint nb_multitexture;
00087         bool initdone;
00088         string texture_size;
00089         void initerror();
00090         
00091 public:
00092         UTILITY();
00093         ~UTILITY();
00094         void Init();
00095         GLuint TexLoad(string texfile, bool mipmap);
00096         GLuint TexLoad(string texfile, int format, bool mipmap);
00097         GLuint TexLoad(string texfile, int format, bool mipmap, int &w, int &h, const bool supresserror, bool &err);
00098         GLuint TexLoad(string texfile, int format, bool mipmap, int &w, int &h, const bool supresserror, bool &err, int attempt);
00099         void SelectTU(int TU);
00100         void Tex2D(int TU, bool enable);
00101         void TexCoord2d2f(int TU, float u, float v);
00102         string sGetLine(ifstream &ffrom);
00103         string sGetParam(ifstream &ffrom);
00104         int iGetParam(ifstream &ffrom);
00105         float fGetParam(ifstream &ffrom);
00106         bool bGetParam(ifstream &ffrom);
00107         int numTUs();
00108         void Draw2D(float x1, float y1, float x2, float y2, TEXTURE_HANDLE * texid);
00109         void Draw2D(float x1, float y1, float x2, float y2, TEXTURE_HANDLE * texid, float rotation);
00110         void Draw2D(float x1, float y1, float x2, float y2, TEXTURE_HANDLE * texid, float rotation, int texsize);
00111         void Draw2D(float x1, float y1, float x2, float y2, TEXTURE_HANDLE * texid, float rotation, int texsize, float opacity);
00112         void DrawButton(float x1, float y1, float x2, float y2, float sidewidth, TEXTURE_HANDLE * texid, float opacity);
00113         void DrawEllipse( float center_x, float center_y, float radius_x, float radius_y ) { DrawEllipse( center_x, center_y, radius_x, radius_y, 0.0f, 0.0f, 0.0f ); }
00114         void DrawEllipse( float center_x, float center_y, float radius_x, float radius_y, float color_r, float color_g, float color_b ) { DrawEllipse( center_x, center_y, radius_x, radius_y, color_r, color_g, color_b, 1.0f ); }
00115         void DrawEllipse( float center_x, float center_y, float radius_x, float radius_y, float color_r, float color_g, float color_b, float opacity );
00116         string GetEOFString() {return ENDOFFILESTRING;}
00117         float GetValue(SDL_Surface * surf, int channel, float x, float y, bool interpolate);
00118         float GetValue(SDL_Surface * surf, int channel, float x, float y, bool interpolate, bool wrap);
00119         bool FileExists(string filename);
00120         int IntersectTriangleD(double orig[3], double dir[3],
00121                    double vert0[3], double vert1[3], double vert2[3],
00122                    double *t, double *u, double *v);
00123         int IntersectTriangleF(float orig[3], float dir[3],
00124                    float vert0[3], float vert1[3], float vert2[3],
00125                    float *t, float *u, float *v);
00126         bool IntersectQuadrilateralF(VERTEX orig, VERTEX dir,
00127                                         VERTEX v_00, VERTEX v_10, VERTEX v_11, VERTEX v_01,
00128                                         float &t, float &u, float &v);
00129         bool IntersectQuadrilateralD(VERTEXD orig, VERTEXD dir,
00130                                         VERTEXD v_00, VERTEXD v_10, VERTEXD v_11, VERTEXD v_01,
00131                                         double &t, double &u, double &v);
00132         int BruteForceTriangleIntersectionF(VERTEX * tri1, VERTEX * tri2, 
00133                                         VERTEX & colpt, VERTEX & colseg, VERTEX & coldest, int & whichtri);
00134         int BruteForceTriangleIntersectionF2(VERTEX * tri1, VERTEX * tri2, 
00135                                         VERTEX & colpt, VERTEX & colseg, VERTEX & coldest, int & whichtri,
00136                                         float & destdepth, float & origdepth);
00137         int MollerTriTriIsectWithLine(float * V0, float * V1, float * V2,
00138                                         float * U0, float * U1, float * U2, int * coplanar,
00139                                         float * isectpt1, float * isectpt2);
00140         bool FileCopy(const string& srcfile, const string& dstfile) const;
00141         string GetPathFromFilename(string filename);
00142         bool isNaN(float val);
00143         bool GetFolderIndex(string folderpath, list <string> & outputfolderlist);
00144 };
00145 
00146 #define _UTILITY_H
00147 #endif /* _UTILITY_H */

Generated on Thu Oct 19 04:05:47 2006 by  doxygen 1.4.6