Page principale Liste des namespaces Hiérarchie des classes Liste par ordre alphabétique Liste des composants Liste des fichiers Membres des namespaces Composants Déclarations

# ExNihiloNameSpace.cpp

Aller à la documentation de ce fichier.

    00001 /*
    00002  * ExNihilo 3D Engine
    00003  *
    00004  *  This program is free software; you can redistribute it and/or modify
    00005  *  it under the terms of the GNU General Public License as published by
    00006  *  the Free Software Foundation; either version 2 of the License, or
    00007  *  (at your option) any later version.
    00008  *
    00009  *  This program is distributed in the hope that it will be useful,
    00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
    00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    00012  *  GNU Library General Public License for more details.
    00013  *
    00014  *  You should have received a copy of the GNU General Public License
    00015  *  along with this program; if not, write to the Free Software
    00016  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
    00017  *
    00018  * Please read AUTHORS file !!!
    00019  *
    00020  * $Id: ExNihiloNameSpace.cpp,v 1.6 2002/11/11 00:02:34 data Exp $
    00021  *
    00022  */
    00023
    00024 #include "ExNihiloNameSpace.h"
    00025
    00026 void ExNihilo::InitBasicObjectList(void)
    00027 {
    00028         float i;
    00029         glNewList(GRILLE,GL_COMPILE);
    00030         glDisable(GL_LIGHTING);
    00031         glBegin(GL_LINES);
    00032                 glColor3f(1.0f,0.0f,0.0f);
    00033                 for ( i=-100;i<101;i+=2)
    00034                 {
    00035                         glVertex3f(0.0f,      i, 100.0f);
    00036                         glVertex3f(0.0f,      i,-100.0f);
    00037                         glVertex3f(0.0f, 100.0f,      i);
    00038                         glVertex3f(0.0f,-100.0f,      i);
    00039                 }
    00040                 glColor3f(0.0,1.0f,0.0f);
    00041
    00042                 for ( i=-100;i<101;i+=2)
    00043                 {
    00044                         glVertex3f( 100.0f,     i,0.0f);
    00045                         glVertex3f(-100.0f,     i,0.0f);
    00046                         glVertex3f(     i, 100.0f,0.0f);
    00047                         glVertex3f(     i,-100.0f,0.0f);
    00048                 }
    00049                 glColor3f(0.0,0.0f,1.0f);
    00050                 for (i=-100;i<101;i+=2)
    00051                 {
    00052                         glVertex3f( 100.0f,0.0f,      i);
    00053                         glVertex3f(-100.0f,0.0f,      i);
    00054                         glVertex3f(      i,0.0f, 100.0f);
    00055                         glVertex3f(      i,0.0f,-100.0f);
    00056                 }
    00057         glEnd();
    00058         glEnable(GL_LIGHTING);
    00059         glEndList();
    00060
    00061
    00062 }
    00063
    00064 void ExNihilo::RenderBitmapString(float x, float y, void *font,std::string string)
    00065 {
    00066         const char *c;
    00067         glRasterPos2f(x, y);
    00068         for (c=string.data(); *c != '\0'; c++)
    00069         {
    00070            glutBitmapCharacter(font, *c);
    00071         }
    00072 }
    00073
    00074 void ExNihilo::EnterOrthoMode(void)
    00075 {
    00076         glMatrixMode(GL_PROJECTION);
    00077         glPushMatrix();
    00078         glLoadIdentity();
    00079         glOrtho( 0,glutGet(GLUT_WINDOW_WIDTH),glutGet(GLUT_WINDOW_HEIGHT),0,0,1);
    00080         glMatrixMode(GL_MODELVIEW);
    00081         glLoadIdentity();
    00082 }
    00083
    00084 void ExNihilo::LeaveOrthoMode(void)
    00085 {
    00086         glMatrixMode( GL_PROJECTION );
    00087         glPopMatrix();
    00088         glMatrixMode( GL_MODELVIEW );
    00089 }
    00090
    00091 void ExNihilo::WriteToScreen(float x,float y,std::string String)
    00092 {
    00093         ExNihilo::EnterOrthoMode();
    00094         ExNihilo::RenderBitmapString(x,y,(void *)GLUT_BITMAP_HELVETICA_12,String);
    00095         ExNihilo::LeaveOrthoMode();
    00096 }
    00097
    00098 void ExNihilo::WriteToScreen(float x,float y,float r,float g,float b,std::string String)
    00099 {
    00100         ExNihilo::EnterOrthoMode();
    00101         glPushAttrib(GL_ALL_ATTRIB_BITS);
    00102         glDisable(GL_LIGHTING);
    00103         glEnable(GL_BLEND);
    00104         glEnable(GL_ALPHA);
    00105         glBlendFunc(GL_ONE,GL_ONE);
    00106         glEnable(GL_ALPHA_TEST);
    00107         glAlphaFunc(GL_GREATER,0);
    00108         glDisable(GL_DEPTH_TEST);
    00109         glColor4f(r,g,b,1.0f);
    00110         ExNihilo::RenderBitmapString(x,y,(void *)GLUT_BITMAP_HELVETICA_12,String);
    00111         glPopAttrib();
    00112         ExNihilo::LeaveOrthoMode();
    00113
    00114 }
    00115
    00116 void ExNihilo::WriteToScreen24(float x,float y,float r,float g,float b,std::string String)
    00117 {
    00118         ExNihilo::EnterOrthoMode();
    00119         glPushAttrib(GL_ALL_ATTRIB_BITS);
    00120         glDisable(GL_LIGHTING);
    00121         glEnable(GL_BLEND);
    00122         glEnable(GL_ALPHA);
    00123         glBlendFunc(GL_ONE,GL_ONE);
    00124         glEnable(GL_ALPHA_TEST);
    00125         glAlphaFunc(GL_GREATER,0);
    00126         glDisable(GL_DEPTH_TEST);
    00127         glColor4f(r,g,b,1.0f);
    00128         ExNihilo::RenderBitmapString(x,y,(void *)GLUT_BITMAP_TIMES_ROMAN_24,String);
    00129         glPopAttrib();
    00130         ExNihilo::LeaveOrthoMode();
    00131
    00132 }
    00133
    00134 void ExNihilo::DrawCadre(float x,float y,float lx,float ly,float r,float g,float b,float blend)
    00135 {
    00136         ExNihilo::EnterOrthoMode();
    00137         glPushAttrib(GL_ALL_ATTRIB_BITS);
    00138         glDisable(GL_LIGHTING);
    00139         glEnable(GL_BLEND);
    00140         glEnable(GL_ALPHA);
    00141         glBlendFunc(GL_ONE,GL_ONE);
    00142         glEnable(GL_ALPHA_TEST);
    00143         glAlphaFunc(GL_GREATER,0);
    00144         glDisable(GL_DEPTH_TEST);
    00145         glColor4f(r,g,b,blend);
    00146         glBegin(GL_QUADS);
    00147                 glVertex2f(x,y);
    00148                 glVertex2f(x,y+ly);
    00149                 glVertex2f(x+lx,y+ly);
    00150                 glVertex2f(x+lx,y);
    00151         glEnd();
    00152         glDisable(GL_BLEND);
    00153         glDisable(GL_ALPHA);
    00154         glEnable(GL_DEPTH_TEST);
    00155         glBegin(GL_LINE_STRIP);
    00156                 glVertex2f(x,y);
    00157                 glVertex2f(x,y+ly);
    00158                 glVertex2f(x+lx,y+ly);
    00159                 glVertex2f(x+lx,y);
    00160                 glVertex2f(x,y);
    00161         glEnd();
    00162         glPopAttrib();
    00163         ExNihilo::LeaveOrthoMode();
    00164 }
    00165
    00166 std::string ExNihilo::ExtracValueFromSring(std::string buffstring,std::string start,std::string end)
    00167 {
    00168         char buffer[255];
    00169         memset(buffer,0,255);
    00170         try
    00171         {
    00172                 buffstring.copy(buffer,buffstring.find(end,buffstring.find(start)+start.size())-buffstring.find(start)-start.size(),buffstring.find(start)+start.size());
    00173         }
    00174         catch(...)
    00175         {
    00176                 throw ExCExpStringNotFound();
    00177         }
    00178         return buffer;
    00179 }
    00180
    00181 int ExNihilo::ExtractIntValueFromSring(std::string buffstring,std::string start,std::string end)
    00182 {
    00183         char buffer[255];
    00184         memset(buffer,0,255);
    00185         try{buffstring.copy(buffer,buffstring.find(end,buffstring.find(start)+start.size())-buffstring.find(start)-start.size(),buffstring.find(start)+start.size());}
    00186         catch(...){throw ExCExpStringNotFound();}
    00187         return atoi(buffer);
    00188 }
    00189
    00190 float ExNihilo::ExtractFloatValueFromSring(std::string buffstring,std::string start,std::string end)
    00191 {
    00192         char buffer[255];
    00193         memset(buffer,0,255);
    00194         try{buffstring.copy(buffer,buffstring.find(end,buffstring.find(start)+start.size())-buffstring.find(start)-start.size(),buffstring.find(start)+start.size());}
    00195         catch(...){throw ExCExpStringNotFound();}
    00196         return atof(buffer);
    00197 }
    00198
    00199 std::string ExNihilo::ExtracStringValueFromFile(std::string FileName, std::string start,std::string end)
    00200 {
    00201         char buffer[255],b[256];memset(buffer,0,255);
    00202         std::ifstream fin;
    00203         std::string buffstring;
    00204         fin.open(FileName.data(),std::ios::in);
    00205         if(fin.is_open())
    00206         {
    00207                 try
    00208                 {
    00209                         do
    00210                         {
    00211                                 memset(b,0,255);
    00212                                 fin.getline(b,256,'\n');
    00213                                 buffstring=buffstring+b;
    00214                         }while(!fin.eof());
    00215                         fin.close();
    00216                 }catch(...){throw ExCExpFileReadError();}
    00217         }else throw   ExCExpFileNotFound();
    00218         buffstring.copy(buffer,buffstring.find(end,buffstring.find(start)+start.size())-buffstring.find(start)-start.size(),buffstring.find(start)+start.size());
    00219         return buffer;
    00220 }
    00221
    00222 int ExNihilo::ExtractIntValueFromFile(std::string FileName, std::string start,std::string end)
    00223 {
    00224         return atoi(ExNihilo::ExtracStringValueFromFile(FileName,start,end).data());
    00225 }
    00226
    00227 float ExNihilo::ExtractFloatValueFromFile(std::string FileName, std::string start,std::string end)
    00228 {
    00229         return atof(ExNihilo::ExtracStringValueFromFile(FileName,start,end).data());
    00230 }
    00231
    00232 int ExNihilo::ExtracStringCommandFromString(std::string FileName,std::string command,std::string &TargetString)
    00233 {
    00234         return 1;
    00235 }
    00236
    00237 int ExNihilo::ExtracStringCommandFromFile(std::string FileName,std::string command,std::string &TargetString)
    00238 {
    00239         char buffer[255],b[256];memset(buffer,0,255);
    00240         std::ifstream fin;
    00241         std::string buffstring;
    00242         fin.open(FileName.data(),std::ios::in);
    00243         if(fin.is_open())
    00244         {
    00245                 try
    00246                 {
    00247                         do
    00248                         {
    00249                                 memset(b,0,255);
    00250                                 fin.getline(b,256,'\n');
    00251                                 buffstring=buffstring+b;
    00252                         }while(!fin.eof());
    00253                         fin.close();
    00254                 }catch(...){throw ExCExpFileReadError();}
    00255         }else throw   ExCExpFileNotFound();
    00256 //      buffstring.copy(buffer,buffstring.find(end,buffstring.find(start)+start.size())-buffstring.find(start)-start.size(),buffstring.find(start)+start.size());
    00257         TargetString=buffer;
    00258         return 1;
    00259 }