00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
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;
00034 m_instance = new ExManagerFog;
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::Reset(void)
00057 {
00058 Guard(ExManagerFog::Reset(void))
00059 SetAlgo(GL_LINEAR);
00060 SetFogColor(0.3f,0.3f,0.3f,0.5f);
00061 SetStartPoint(300.0f);
00062 SetEndPoint(800.0f);
00063 SetDensity(0.50);
00064 m_State=false;
00065 DisableFog();
00066 UnGuard
00067 }
00068
00069 void ExManagerFog::EnableFog(void)
00070 {
00071 Guard(ExManagerFog::EnableFog(void))
00072 glEnable(GL_FOG);
00073 glFogi(GL_FOG_MODE,m_FogAlgo);
00074 glFogfv(GL_FOG_COLOR,m_FogColor);
00075 glFogf(GL_FOG_DENSITY,m_Density);
00076 glHint(GL_FOG_HINT,GL_DONT_CARE);
00077 glFogf(GL_FOG_START,m_StartPoint);
00078 glFogf(GL_FOG_END,m_EndPoint);
00079 m_State=true;
00080 UnGuard
00081 }
00082
00083 void ExManagerFog::DisableFog(void)
00084 {
00085 Guard(ExManagerFog::DisableFog(void))
00086 glDisable(GL_FOG);
00087 m_State=false;
00088 UnGuard
00089 }
00090
00091
00092 void ExManagerFog::SetFogColor(float R,float G,float B,float A)
00093 {
00094 Guard(ExManagerFog::SetFogColor(float R,float G,float B,float A))
00095 SetFogColorR(R);
00096 SetFogColorG(G);
00097 SetFogColorB(B);
00098 SetFogColorA(A);
00099 UnGuard
00100 }
00101
00102 void ExManagerFog::SetFogColorR(float R)
00103 {
00104 Guard(ExManagerFog::SetFogColorR(float R))
00105 if(R>1.0f)R=1.0f;
00106 if(R<0.0f)R=0.0f;
00107 m_FogColor[0]=R;
00108 glFogfv(GL_FOG_COLOR,m_FogColor);
00109 UnGuard
00110 }
00111
00112 void ExManagerFog::SetFogColorG(float G)
00113 {
00114 Guard(ExManagerFog::SetFogColorG(float G))
00115 if(G>1.0f)G=1.0f;
00116 if(G<0.0f)G=0.0f;
00117 m_FogColor[1]=G;
00118 glFogfv(GL_FOG_COLOR,m_FogColor);
00119 UnGuard
00120 }
00121
00122 void ExManagerFog::SetFogColorB(float B)
00123 {
00124 Guard(ExManagerFog::SetFogColorB(float B))
00125 if(B>1.0f)B=1.0f;
00126 if(B<0.0f)B=0.0f;
00127 m_FogColor[2]=B;
00128 glFogfv(GL_FOG_COLOR,m_FogColor);
00129 UnGuard
00130 }
00131
00132 void ExManagerFog::SetFogColorA(float A)
00133 {
00134 Guard(ExManagerFog::SetFogColorA(float A))
00135 if(A>1.0f)A=1.0f;
00136 if(A<0.0f)A=0.0f;
00137 m_FogColor[3]=A;
00138 glFogfv(GL_FOG_COLOR,m_FogColor);
00139 UnGuard
00140 }
00141
00142 void ExManagerFog::IncFogColorR(float inc)
00143 {
00144 Guard(ExManagerFog::IncFogColorR(float inc))
00145 SetFogColorR(GetFogColorR()+inc);
00146 UnGuard
00147 }
00148
00149 void ExManagerFog::IncFogColorG(float inc)
00150 {
00151 Guard(ExManagerFog::IncFogColorG(float inc))
00152 SetFogColorG(GetFogColorG()+inc);
00153 UnGuard
00154 }
00155
00156 void ExManagerFog::IncFogColorB(float inc)
00157 {
00158 Guard(ExManagerFog::IncFogColorB(float inc))
00159 SetFogColorB(GetFogColorB()+inc);
00160 UnGuard
00161 }
00162
00163 void ExManagerFog::IncFogColorA(float inc)
00164 {
00165 Guard(ExManagerFog::IncFogColorA(float inc))
00166 SetFogColorA(GetFogColorA()+inc);
00167 UnGuard
00168 }
00169
00170 void ExManagerFog::SetStartPoint(float P)
00171 {
00172 Guard(ExManagerFog::SetStartPoint(float P))
00173 m_StartPoint=P;
00174 glFogf(GL_FOG_START,m_StartPoint);
00175 UnGuard
00176 }
00177
00178 void ExManagerFog::IncStartPoint(float inc)
00179 {
00180 Guard(ExManagerFog::IncStartPoint(float inc))
00181 SetStartPoint(GetStarPoint()+inc);
00182 UnGuard
00183 }
00184
00185 void ExManagerFog::SetEndPoint(float P)
00186 {
00187 Guard(ExManagerFog::SetEndPoint(float P))
00188 m_EndPoint=P;
00189 glFogf(GL_FOG_END,m_EndPoint);
00190 UnGuard
00191 }
00192
00193 void ExManagerFog::IncEndPoint(float inc)
00194 {
00195 Guard(ExManagerFog::IncEndPoint(float inc))
00196 SetEndPoint(GetEndPoint()+inc);
00197 UnGuard
00198 }
00199
00200 void ExManagerFog::SetDensity(float P)
00201 {
00202 Guard(ExManagerFog::SetDensity(float P))
00203 m_Density=P;
00204 glFogf(GL_FOG_DENSITY,m_Density);
00205 UnGuard
00206 }
00207
00208 void ExManagerFog::IncDensity(float inc)
00209 {
00210 Guard(ExManagerFog::IncDensity(float inc))
00211 SetDensity(GetDensity()+inc);
00212 UnGuard
00213 }
00214
00215 void ExManagerFog::SetAlgo(GLenum algo)
00216 {
00217 Guard(ExManagerFog::SetAlgo(GLenum algo))
00218 switch(algo)
00219 {
00220 case GL_LINEAR:
00221 m_FogAlgo=GL_LINEAR;
00222 glFogi(GL_FOG_MODE,GL_LINEAR);
00223 break;
00224 case GL_EXP:
00225 m_FogAlgo=GL_EXP;
00226 glFogi(GL_FOG_MODE,GL_EXP);
00227 break;
00228 case GL_EXP2:
00229 m_FogAlgo=GL_EXP2;
00230 glFogi(GL_FOG_MODE,GL_EXP2);
00231 break;
00232 default :
00233 m_FogAlgo=GL_LINEAR;
00234 glFogi(GL_FOG_MODE,GL_LINEAR);
00235 break;
00236 }
00237 UnGuard
00238 }
00239
00240 ExCAction ExManagerFog::InputCommand(ExCCommand Command)
00241 {
00242 Guard(ExCAction ExManagerFog::InputCommand(ExCCommand Command))
00243 return NOTHING;
00244 UnGuard
00245 }
00246
00247 ExCAction ExManagerFog::InputAction(ExCAction Action)
00248 {
00249 Guard(ExCAction ExManagerFog::InputAction(ExCAction Action))
00250 switch(Action.m_Action)
00251 {
00252 case ENABLE_FOG:EnableFog();break;
00253 case DISABEL_FOG:DisableFog();break;
00254 case SET_FOG_ALGO_LINEAR:SetAlgo(GL_LINEAR);break;
00255 case SET_FOG_ALGO_EXP:SetAlgo(GL_EXP);break;
00256 case SET_FOG_ALGO_EXP2:SetAlgo(GL_LINEAR);break;
00257
00258 case SET_FOG_COLOR_R:
00259 try
00260 {
00261 SetFogColorR(atof(Action.m_Param.data()));
00262 }catch(...)
00263 {
00264 *Consol<<"Enter a float value"<<std::endl;
00265 }
00266 break;
00267
00268 case SET_FOG_COLOR_G:
00269 try
00270 {
00271 SetFogColorG(atof(Action.m_Param.data()));
00272 }catch(...)
00273 {
00274 *Consol<<"Enter a float value"<<std::endl;
00275 }
00276 break;
00277
00278 case SET_FOG_COLOR_B:
00279 try
00280 {
00281 SetFogColorB(atof(Action.m_Param.data()));
00282 }catch(...)
00283 {
00284 *Consol<<"Enter a float value"<<std::endl;
00285 }
00286 break;
00287
00288 case SET_FOG_START_POINT:
00289 try
00290 {
00291 SetStartPoint(atof(Action.m_Param.data()));
00292 }catch(...)
00293 {
00294 *Consol<<"Enter a float value"<<std::endl;
00295 }
00296 break;
00297
00298 case SET_FOG_END_POINT:
00299 try
00300 {
00301 SetEndPoint(atof(Action.m_Param.data()));
00302 }catch(...)
00303 {
00304 *Consol<<"Enter a float value"<<std::endl;
00305 }
00306 break;
00307
00308 case SET_FOG_DENSITY:
00309 try
00310 {
00311 SetDensity(atof(Action.m_Param.data()));
00312 }catch(...)
00313 {
00314 *Consol<<"Enter a float value"<<std::endl;
00315 }
00316 break;
00317
00318 default:
00319 *Consol<<"Can not file action in FOG_ACTION_MAP"<<std::endl;
00320 break;
00321 }
00322
00323 if(Action.m_NextAction){return *Action.m_NextAction;}
00324 else{return NOTHING;}
00325 UnGuard
00326 }