| 1 | /** | 
|---|
| 2 |  * @file fog_effect.h | 
|---|
| 3 |  * Generates simple openGL fog | 
|---|
| 4 | */ | 
|---|
| 5 |  | 
|---|
| 6 | #ifndef _FOG_EFFECT | 
|---|
| 7 | #define _FOG_EFFECT | 
|---|
| 8 |  | 
|---|
| 9 | #include "weather_effect.h" | 
|---|
| 10 | #include "glincl.h" | 
|---|
| 11 | #include "vector.h" | 
|---|
| 12 |  | 
|---|
| 13 | class FogEffect : public WeatherEffect | 
|---|
| 14 | { | 
|---|
| 15 | public: | 
|---|
| 16 |   FogEffect(const TiXmlElement* root = NULL); | 
|---|
| 17 |   virtual ~FogEffect(); | 
|---|
| 18 |  | 
|---|
| 19 |   virtual void loadParams(const TiXmlElement* root); | 
|---|
| 20 |  | 
|---|
| 21 |   virtual void init(); | 
|---|
| 22 |  | 
|---|
| 23 |   virtual void activate(); | 
|---|
| 24 |   virtual void deactivate(); | 
|---|
| 25 |  | 
|---|
| 26 |   void activateFog() | 
|---|
| 27 |   { | 
|---|
| 28 |     this->activate(); | 
|---|
| 29 |   } | 
|---|
| 30 |  | 
|---|
| 31 |   void deactivateFog() | 
|---|
| 32 |   { | 
|---|
| 33 |     this->deactivate(); | 
|---|
| 34 |   } | 
|---|
| 35 |  | 
|---|
| 36 |   virtual void draw() const; | 
|---|
| 37 |   virtual void tick(float dt); | 
|---|
| 38 |  | 
|---|
| 39 |   inline void setFogMode(const std::string& mode) | 
|---|
| 40 |   { | 
|---|
| 41 |     this->fogMode = this->stringToFogMode(mode); | 
|---|
| 42 |   } | 
|---|
| 43 |  | 
|---|
| 44 |   inline void setFogDensity(float density) | 
|---|
| 45 |   { | 
|---|
| 46 |     this->fogDensity = density; | 
|---|
| 47 |   } | 
|---|
| 48 |  | 
|---|
| 49 |   inline void setFogRange(float start, float end) | 
|---|
| 50 |   { | 
|---|
| 51 |     this->fogStart = start; | 
|---|
| 52 |     this->fogEnd = end; | 
|---|
| 53 |   } | 
|---|
| 54 |  | 
|---|
| 55 |   inline void setFogColor(float r, float g, float b) | 
|---|
| 56 |   { | 
|---|
| 57 |     this->colorVector = Vector(r, g, b); | 
|---|
| 58 |   } | 
|---|
| 59 |  | 
|---|
| 60 |   inline void setFogFadeIn(float fadein) | 
|---|
| 61 |   { | 
|---|
| 62 |     this->fogFadeInDuration = fadein; | 
|---|
| 63 |   } | 
|---|
| 64 |  | 
|---|
| 65 |   inline void setFogFadeOut(float fadeout) | 
|---|
| 66 |   { | 
|---|
| 67 |     this->fogFadeOutDuration = fadeout; | 
|---|
| 68 |   } | 
|---|
| 69 |  | 
|---|
| 70 |   inline void setFogOption(const std::string& option) | 
|---|
| 71 |   { | 
|---|
| 72 |     if (option == "activate") | 
|---|
| 73 |       this->fogActivate = true; | 
|---|
| 74 |   } | 
|---|
| 75 |  | 
|---|
| 76 |   void fadeInFog(); | 
|---|
| 77 |   void fadeOutFog(); | 
|---|
| 78 |  | 
|---|
| 79 |  | 
|---|
| 80 | private: | 
|---|
| 81 |   inline GLint stringToFogMode(const std::string& mode) | 
|---|
| 82 |   { | 
|---|
| 83 |     if(mode == "GL_LINEAR") | 
|---|
| 84 |       return GL_LINEAR; | 
|---|
| 85 |     else if(mode == "GL_EXP") | 
|---|
| 86 |       return GL_EXP; | 
|---|
| 87 |     else if(mode == "GL_EXP2" ) | 
|---|
| 88 |       return GL_EXP2; | 
|---|
| 89 |     else | 
|---|
| 90 |       return -1; | 
|---|
| 91 |   } | 
|---|
| 92 |  | 
|---|
| 93 |   bool          fogActivate; | 
|---|
| 94 |  | 
|---|
| 95 |   bool          fogFadeInActivate; | 
|---|
| 96 |   bool          fogFadeOutActivate; | 
|---|
| 97 |  | 
|---|
| 98 |   GLfloat       fogFadeInDuration; | 
|---|
| 99 |   GLfloat       fogFadeOutDuration; | 
|---|
| 100 |  | 
|---|
| 101 |   GLint         fogMode; | 
|---|
| 102 |   GLfloat       fogDensity; | 
|---|
| 103 |   GLfloat       fogFadeDensity; | 
|---|
| 104 |  | 
|---|
| 105 |   GLfloat       fogStart; | 
|---|
| 106 |   GLfloat       fogEnd; | 
|---|
| 107 |   GLfloat       fogFadeEnd; | 
|---|
| 108 |  | 
|---|
| 109 |   Vector        colorVector; | 
|---|
| 110 |   float         localTimer;  | 
|---|
| 111 | }; | 
|---|
| 112 |  | 
|---|
| 113 | #endif  /* _FOG_EFFECT */ | 
|---|