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

ExManagerFog.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: ExManagerFog.cpp,v 1.8 2002/12/13 11:45:01 data Exp $
00021  *
00022  */
00023 
00024 #include "ExManagerFog.h"
00025 
00026 bool ExManagerFog::m_flag = false; 
00027 ExManagerFog* ExManagerFog::m_instance = NULL; 
00028 
00029 ExManagerFog* ExManagerFog::CreateSingleton(void){
00030 Guard(ExManagerFog* ExManagerFog::CreateSingleton(void))
00031         if(!m_flag)
00032         {
00033                 m_flag = true; // We are creating the error log now, so set flag to true
00034                 m_instance = new ExManagerFog; // Create the error log
00035         }else
00036         {
00037                 std::cout<<"Error singleton already created"<<std::endl;
00038         }
00039         return m_instance; 
00040 UnGuard
00041 }
00042 
00043 ExManagerFog::ExManagerFog(void)
00044 {
00045 Guard(ExManagerFog::ExManagerFog(void))
00046         Reset();
00047 UnGuard
00048 }
00049 
00050 ExManagerFog::~ExManagerFog(void)
00051 {
00052 Guard(ExManagerFog::~ExManagerFog(void))
00053 UnGuard
00054 }
00055 
00056 void ExManagerFog::Init(void)
00057 {
00058 Guard(ExManagerFog::Init(void))
00059         glFogCoordfEXT = NULL;
00060 
00061         char *blah = (char *) glGetString(GL_EXTENSIONS);
00062         //--------------------------------
00063         //VOLUMETRIC FOG EXTENSION
00064         //--------------------------------
00065         if (strstr( (const char *)blah, "GL_EXT_fog_coord" )) 
00066         { 
00067                 glFogCoordfEXT = (PFNGLFOGCOORDFEXTPROC) wglGetProcAddress("glFogCoordfEXT");
00068                 *Consol<<"ExManagerFog::glFogCoordfEXT found and enable"<<std::endl;
00069         }else
00070         {
00071                 *Consol<<"ExManagerFog::OpenGl glFogCoordfEXT extension missing"<<std::endl; 
00072         }
00073 UnGuard
00074 }
00075 
00076 void ExManagerFog::Reset(void)
00077 {
00078 Guard(ExManagerFog::Reset(void))
00079         SetAlgo(GL_LINEAR);
00080         SetFogColor(0.8f,0.8f,0.8f,1.0f);
00081         SetStartPoint(100.0f);
00082         SetEndPoint(300.0f);
00083         SetDensity(0.50);
00084         m_State=false;
00085         DisableFog();
00086 UnGuard
00087 }
00088 
00089 void ExManagerFog::Draw(void)
00090 {
00091 Guard(ExManagerFog::Draw(void))
00092 EnableFog();
00093 glPushAttrib(GL_ALL_ATTRIB_BITS);
00094         glColor3f(0.0f,0.0f,0.5f);
00095         glBegin(GL_QUADS);                                                                                                      // Back Wall
00096                 glFogCoordfEXT( 0.0f);  glVertex3f(-100.0f,-100.0f,-100.0f);
00097                 glFogCoordfEXT( 0.0f);  glVertex3f( 100.0f,-100.0f,-100.0f);
00098                 glFogCoordfEXT( 0.0f);  glVertex3f( 100.0f, 100.0f,-100.0f);
00099                 glFogCoordfEXT( 0.0f);  glVertex3f(-100.0f, 100.0f,-100.0f);
00100         glEnd();
00101 
00102         glBegin(GL_QUADS);                                                                                                      // Floor
00103                 glFogCoordfEXT( 0.0f);  glVertex3f(-100.0f,-100.0f,-100.0f);
00104                 glFogCoordfEXT( 0.0f);  glVertex3f( 100.0f,-100.0f,-100.0f);
00105                 glFogCoordfEXT( 1.0f);  glVertex3f( 100.0f,-100.0f, 100.0f);
00106                 glFogCoordfEXT( 1.0f);  glVertex3f(-100.0f,-100.0f, 100.0f);
00107         glEnd();
00108 
00109         glBegin(GL_QUADS);                                                                                                      // Roof
00110                 glFogCoordfEXT( 0.0f);  glVertex3f(-100.0f, 100.0f,-100.0f);
00111                 glFogCoordfEXT( 0.0f);  glVertex3f( 100.0f, 100.0f,-100.0f);
00112                 glFogCoordfEXT( 1.0f);  glVertex3f( 100.0f, 100.0f, 100.0f);
00113                 glFogCoordfEXT( 1.0f);  glVertex3f(-100.0f, 100.0f, 100.0f);
00114         glEnd();
00115 
00116         glBegin(GL_QUADS);                                                                                                      // Right Wall
00117                 glFogCoordfEXT( 1.0f);  glVertex3f( 100.0f,-100.0f, 100.0f);
00118                 glFogCoordfEXT( 1.0f);  glVertex3f( 100.0f, 100.0f, 100.0f);
00119                 glFogCoordfEXT( 0.0f);  glVertex3f( 100.0f, 100.0f,-100.0f);
00120                 glFogCoordfEXT( 0.0f);  glVertex3f( 100.0f,-100.0f,-100.0f);
00121         glEnd();
00122 
00123         glBegin(GL_QUADS);                                                                                                      // Left Wall
00124                 glFogCoordfEXT( 1.0f);  glVertex3f(-100.0f,-100.0f, 100.0f);
00125                 glFogCoordfEXT( 1.0f);  glVertex3f(-100.0f, 100.0f, 100.0f);
00126                 glFogCoordfEXT( 0.0f);  glVertex3f(-100.0f, 100.0f,-100.0f);
00127                 glFogCoordfEXT( 0.0f);  glVertex3f(-100.0f,-100.0f,-100.0f);
00128         glEnd();
00129 
00130         glPopAttrib();
00131 DisableFog();
00132 UnGuard
00133 }
00134 
00135 void ExManagerFog::SetVolumetricFogCoord(GLfloat Value)
00136 {
00137 Guard(ExManagerFog::SetVolumetricFogCoord(GLfloat Value))
00138         //stay to Check if extension ok....
00139         glFogCoordfEXT(Value);  
00140 UnGuard
00141 }
00142 
00143 void ExManagerFog::EnableFog(void)
00144 {
00145 Guard(ExManagerFog::EnableFog(void))
00146         m_State=true;
00147 /*      glEnable(GL_FOG);
00148         glFogi(GL_FOG_MODE,m_FogAlgo);//GL_EXP,GL_EXP2,GL_LINEAR
00149         glFogfv(GL_FOG_COLOR,m_FogColor);
00150         glFogf(GL_FOG_START,m_StartPoint);
00151         glFogf(GL_FOG_END,m_EndPoint);
00152 
00153         glFogf(GL_FOG_DENSITY,m_Density);
00154         glHint(GL_FOG_HINT,GL_DONT_CARE);
00155 
00156         glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FOG_COORDINATE_EXT);
00157 */
00158         /*glEnable(GL_FOG);                                                                                                     // Enable Fog
00159         glFogi(GL_FOG_MODE, GL_LINEAR);                                                                         // Fog Fade Is Linear
00160         glFogfv(GL_FOG_COLOR, m_FogColor);                                                                      // Set The Fog Color
00161         glFogf(GL_FOG_START,  1.0f);                                                                            // Set The Fog Start
00162         glFogf(GL_FOG_END,    0.0f);                                                                            // Set The Fog End
00163         glHint(GL_FOG_HINT, GL_NICEST);                                                                         // Per-Pixel Fog Calculation
00164         glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FOG_COORDINATE_EXT);            // Set Fog Based On Vertice Coordinates
00165         */
00166         float fogColor[4] = {0.8f, 0.8f, 0.8f, 1.0f};
00167 
00168         glEnable(GL_FOG);                                               // Turn on fog
00169         glFogi(GL_FOG_MODE, GL_LINEAR);                 // Set the fog mode to LINEAR (Important)
00170         glFogfv(GL_FOG_COLOR, fogColor);                // Give OpenGL our fog color
00171         glFogf(GL_FOG_START, 0.0);                              // Set the start position for the depth at 0
00172         glFogf(GL_FOG_END, 50.0);                               // Set the end position for the detph at 50
00173         glHint(GL_FOG_HINT, GL_NICEST); 
00174 
00175         // Now we tell OpenGL that we are using our fog extension for per vertex
00176         // fog calculations.  For each vertex that needs fog applied to it we must
00177         // use the glFogCoordfEXT() function with a depth value passed in.
00178         // These flags are defined in main.h and are not apart of the normal opengl headers.
00179         glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FOG_COORDINATE_EXT);
00180 
00181 UnGuard
00182 }
00183 
00184 void ExManagerFog::DisableFog(void)
00185 {
00186 Guard(ExManagerFog::DisableFog(void))
00187         glDisable(GL_FOG);
00188         m_State=false;
00189 UnGuard
00190 }
00191 
00192 
00193 void ExManagerFog::SetFogColor(float R,float G,float B,float A)
00194 {
00195 Guard(ExManagerFog::SetFogColor(float R,float G,float B,float A))
00196         SetFogColorR(R);
00197         SetFogColorG(G);
00198         SetFogColorB(B);
00199         SetFogColorA(A);
00200 UnGuard
00201 }
00202 
00203 void ExManagerFog::SetFogColorR(float R)
00204 {
00205 Guard(ExManagerFog::SetFogColorR(float R))
00206         if(R>1.0f)R=1.0f;
00207         if(R<0.0f)R=0.0f;
00208         m_FogColor[0]=R;
00209         glFogfv(GL_FOG_COLOR,m_FogColor);
00210 UnGuard
00211 }
00212 
00213 void ExManagerFog::SetFogColorG(float G)
00214 {
00215 Guard(ExManagerFog::SetFogColorG(float G))
00216         if(G>1.0f)G=1.0f;
00217         if(G<0.0f)G=0.0f;
00218         m_FogColor[1]=G;
00219         glFogfv(GL_FOG_COLOR,m_FogColor);
00220 UnGuard
00221 }
00222 
00223 void ExManagerFog::SetFogColorB(float B)
00224 {
00225 Guard(ExManagerFog::SetFogColorB(float B))
00226         if(B>1.0f)B=1.0f;
00227         if(B<0.0f)B=0.0f;
00228         m_FogColor[2]=B;
00229         glFogfv(GL_FOG_COLOR,m_FogColor);
00230 UnGuard
00231 }
00232 
00233 void ExManagerFog::SetFogColorA(float A)
00234 {
00235 Guard(ExManagerFog::SetFogColorA(float A))
00236         if(A>1.0f)A=1.0f;
00237         if(A<0.0f)A=0.0f;
00238         m_FogColor[3]=A;
00239         glFogfv(GL_FOG_COLOR,m_FogColor);
00240 UnGuard
00241 }
00242 
00243 void ExManagerFog::IncFogColorR(float inc)
00244 {
00245 Guard(ExManagerFog::IncFogColorR(float inc))
00246         SetFogColorR(GetFogColorR()+inc);
00247 UnGuard
00248 }
00249 
00250 void ExManagerFog::IncFogColorG(float inc)
00251 {
00252 Guard(ExManagerFog::IncFogColorG(float inc))
00253         SetFogColorG(GetFogColorG()+inc);
00254 UnGuard
00255 }
00256 
00257 void ExManagerFog::IncFogColorB(float inc)
00258 {
00259 Guard(ExManagerFog::IncFogColorB(float inc))
00260         SetFogColorB(GetFogColorB()+inc);
00261 UnGuard
00262 }
00263 
00264 void ExManagerFog::IncFogColorA(float inc)
00265 {
00266 Guard(ExManagerFog::IncFogColorA(float inc))
00267         SetFogColorA(GetFogColorA()+inc);
00268 UnGuard
00269 }
00270 
00271 void ExManagerFog::SetStartPoint(float P)
00272 {
00273 Guard(ExManagerFog::SetStartPoint(float P))
00274         m_StartPoint=P;
00275         glFogf(GL_FOG_START,m_StartPoint);
00276 UnGuard
00277 }
00278 
00279 void ExManagerFog::IncStartPoint(float inc)
00280 {
00281 Guard(ExManagerFog::IncStartPoint(float inc))
00282         SetStartPoint(GetStarPoint()+inc);
00283 UnGuard
00284 }
00285 
00286 void ExManagerFog::SetEndPoint(float P)
00287 {
00288 Guard(ExManagerFog::SetEndPoint(float P))
00289         m_EndPoint=P;
00290         glFogf(GL_FOG_END,m_EndPoint);
00291 UnGuard
00292 }
00293 
00294 void ExManagerFog::IncEndPoint(float inc)
00295 {
00296 Guard(ExManagerFog::IncEndPoint(float inc))
00297         SetEndPoint(GetEndPoint()+inc);
00298 UnGuard
00299 }
00300 
00301 void ExManagerFog::SetDensity(float P)
00302 {
00303 Guard(ExManagerFog::SetDensity(float P))
00304         m_Density=P;
00305         glFogf(GL_FOG_DENSITY,m_Density);
00306 UnGuard
00307 }
00308 
00309 void ExManagerFog::IncDensity(float inc)
00310 {
00311 Guard(ExManagerFog::IncDensity(float inc))
00312         SetDensity(GetDensity()+inc);
00313 UnGuard
00314 }
00315 
00316 void ExManagerFog::SetAlgo(GLenum algo)
00317 {
00318 Guard(ExManagerFog::SetAlgo(GLenum algo))
00319         switch(algo)
00320         {
00321                 case GL_LINEAR:
00322                         m_FogAlgo=GL_LINEAR;
00323                         glFogi(GL_FOG_MODE,GL_LINEAR);
00324                         break;
00325                 case GL_EXP:
00326                         m_FogAlgo=GL_EXP;
00327                         glFogi(GL_FOG_MODE,GL_EXP);
00328                         break;
00329                 case GL_EXP2:
00330                         m_FogAlgo=GL_EXP2;
00331                         glFogi(GL_FOG_MODE,GL_EXP2);
00332                         break;
00333                 default :
00334                         m_FogAlgo=GL_LINEAR;
00335                         glFogi(GL_FOG_MODE,GL_LINEAR);
00336                         break;
00337         }
00338 UnGuard
00339 }
00340 
00341 ExCAction ExManagerFog::InputCommand(ExCCommand Command)
00342 {
00343 Guard(ExCAction ExManagerFog::InputCommand(ExCCommand Command))
00344         return NOTHING;
00345 UnGuard
00346 }
00347 
00348 ExCAction ExManagerFog::InputAction(ExCAction Action)
00349 {
00350 Guard(ExCAction ExManagerFog::InputAction(ExCAction Action))
00351         switch(Action.m_Action)
00352         {
00353         case ENABLE_FOG:EnableFog();break;
00354         case DISABEL_FOG:DisableFog();break;
00355         case SET_FOG_ALGO_LINEAR:SetAlgo(GL_LINEAR);break;
00356         case SET_FOG_ALGO_EXP:SetAlgo(GL_EXP);break;
00357         case SET_FOG_ALGO_EXP2:SetAlgo(GL_LINEAR);break;
00358 
00359         case SET_FOG_COLOR_R:
00360                 try
00361                 {
00362                         SetFogColorR(atof(Action.m_Param.data()));
00363                 }catch(...)
00364                 {
00365                         *Consol<<"Enter a float value"<<std::endl;
00366                 }
00367                 break;
00368 
00369         case SET_FOG_COLOR_G:
00370                 try
00371                 {
00372                         SetFogColorG(atof(Action.m_Param.data()));
00373                 }catch(...)
00374                 {
00375                         *Consol<<"Enter a float value"<<std::endl;
00376                 }
00377                 break;
00378                 
00379         case SET_FOG_COLOR_B:
00380                 try
00381                 {
00382                         SetFogColorB(atof(Action.m_Param.data()));
00383                 }catch(...)
00384                 {
00385                         *Consol<<"Enter a float value"<<std::endl;
00386                 }
00387                 break;
00388                                 
00389         case SET_FOG_START_POINT:
00390                 try
00391                 {
00392                         SetStartPoint(atof(Action.m_Param.data()));
00393                 }catch(...)
00394                 {
00395                         *Consol<<"Enter a float value"<<std::endl;
00396                 }
00397                 break;
00398                 
00399         case SET_FOG_END_POINT:
00400                 try
00401                 {
00402                         SetEndPoint(atof(Action.m_Param.data()));
00403                 }catch(...)
00404                 {
00405                         *Consol<<"Enter a float value"<<std::endl;
00406                 }
00407                 break;
00408 
00409         case SET_FOG_DENSITY:
00410                 try
00411                 {
00412                         SetDensity(atof(Action.m_Param.data()));
00413                 }catch(...)
00414                 {
00415                         *Consol<<"Enter a float value"<<std::endl;
00416                 }
00417                 break;
00418     
00419         default:
00420                 *Consol<<"Can not file action in FOG_ACTION_MAP"<<std::endl;
00421                 break;
00422         }       
00423 
00424         if(Action.m_NextAction){return *Action.m_NextAction;}
00425         else{return NOTHING;}
00426 UnGuard
00427 }

Généré le Tue Oct 28 12:43:35 2003 pour ExNihilo par doxygen 1.3.4