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