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