Changeset 8793 in orxonox.OLD for trunk/src/lib/graphics/effects/fog_effect.cc
- Timestamp:
- Jun 26, 2006, 3:36:16 PM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/graphics/effects/fog_effect.cc
r8495 r8793 20 20 #include "shell_command.h" 21 21 22 // Define shell commands 22 23 SHELL_COMMAND(activate, FogEffect, activateFog); 23 24 SHELL_COMMAND(deactivate, FogEffect, deactivateFog); … … 25 26 SHELL_COMMAND(fadeout, FogEffect, fadeOutFog); 26 27 27 // TODO: Fix fades28 29 28 using namespace std; 30 29 31 30 CREATE_FACTORY(FogEffect, CL_FOG_EFFECT); 32 31 32 /** 33 * @brief standard constructor 34 */ 33 35 FogEffect::FogEffect(const TiXmlElement* root) { 34 36 this->setClassID(CL_FOG_EFFECT, "FogEffect"); 35 37 38 // Initialize values 36 39 this->init(); 37 40 41 // Load XML params 38 42 if (root != NULL) 39 43 this->loadParams(root); 40 44 45 // Activate fog, if chosen to be activated by default 41 46 if (this->fogActivate) 42 47 this->activate(); 43 48 } 44 49 45 50 /** 51 * @brief standard destructor 52 */ 46 53 FogEffect::~FogEffect() { 47 54 this->deactivate(); 48 55 } 49 56 50 57 /** 58 * @brief initalizes the fog effect with default values 59 */ 60 void FogEffect::init() { 61 // default values 62 this->fogMode = GL_LINEAR; 63 this->fogDensity = 0.005; 64 this->fogStart = 0; 65 this->fogEnd = 300; 66 this->colorVector = Vector(0.6, 0.0, 0.0); 67 68 // init variables 69 this->fogFadeInDuration = 0; 70 this->fogFadeOutDuration = 0; 71 this->fogFadeDensity = 0; 72 this->fogFadeEnd = 0; 73 74 this->localTimer = 0; 75 this->fogActivate = false; 76 this->fogFadeInActivate = false; 77 this->fogFadeOutActivate = false; 78 } 79 80 /** 81 * @brief loads the fog effect parameters. 82 * @param root: the XML-Element to load the data from 83 */ 51 84 void FogEffect::loadParams(const TiXmlElement* root) { 52 85 WeatherEffect::loadParams(root); 53 86 54 LoadParam(root, "mode", this, FogEffect, setFogMode) ;55 LoadParam(root, "density", this, FogEffect, setFogDensity) ;56 LoadParam(root, "range", this, FogEffect, setFogRange) ;57 LoadParam(root, "color", this, FogEffect, setFogColor) ;58 LoadParam(root, "fadeinduration", this, FogEffect, setFogFadeIn) ;59 LoadParam(root, "fadeoutduration", this, FogEffect, setFogFadeOut) ;87 LoadParam(root, "mode", this, FogEffect, setFogMode).describe("fog mode (linear, exponential)");; 88 LoadParam(root, "density", this, FogEffect, setFogDensity).describe("fog density if exp. fog");; 89 LoadParam(root, "range", this, FogEffect, setFogRange).describe("fog range: start, end");; 90 LoadParam(root, "color", this, FogEffect, setFogColor).describe("fog color: r,g,b");; 91 LoadParam(root, "fadeinduration", this, FogEffect, setFogFadeIn).describe("duration of the fade in");; 92 LoadParam(root, "fadeoutduration", this, FogEffect, setFogFadeOut).describe("duration of the fade out");; 60 93 61 94 LOAD_PARAM_START_CYCLE(root, element); 62 95 { 63 LoadParam_CYCLE(element, "option", this, FogEffect, setFogOption);96 LoadParam_CYCLE(element, "option", this, FogEffect, setFogOption).describe("sets a fog option: activate");; 64 97 } 65 98 LOAD_PARAM_END_CYCLE(element); 66 99 } 67 100 68 void FogEffect::init() { 69 // default values 70 this->fogMode = GL_LINEAR; 71 this->fogDensity = 0.03; 72 this->fogStart = 0; 73 this->fogEnd = 50; 74 this->colorVector = Vector(0.3, 0.3, 0.3); 75 76 // init variables 77 this->fogFadeInDuration = 0; 78 this->fogFadeOutDuration = 0; 79 this->fogFadeDensity = 0; 80 this->localTimer = 0; 81 this->fogActivate = false; 82 this->fogFadeInActivate = false; 83 this->fogFadeOutActivate = false; 84 85 } 86 87 101 /** 102 * @brief activates the fog effect 103 */ 88 104 void FogEffect::activate() { 89 PRINTF(0)( "Enabling FogEffect, mode: %i, density: %f, start: %f, end: %f, color %f, %f, %f\n", this->fogMode, this->fogDensity, this->fogStart, this->fogEnd, this->colorVector.x, this->colorVector.y, this->colorVector.z); 90 91 this->fogActivate = true; 92 105 PRINTF(0)( "Activating FogEffect\n"); 106 107 // init fogGL 93 108 GLfloat fogColor[4] = { colorVector.x, colorVector.y, colorVector.z, 1.0}; 94 109 glFogi(GL_FOG_MODE, this->fogMode); … … 99 114 glFogf(GL_FOG_END, this->fogEnd); 100 115 116 this->fogActivate = true; 117 101 118 glEnable(GL_FOG); 102 103 } 104 105 119 } 120 121 /** 122 * @brief deactivates the fog effect 123 */ 106 124 void FogEffect::deactivate() { 107 125 PRINTF(0)("Deactivating FogEffect\n"); … … 112 130 113 131 glDisable(GL_FOG); 114 115 } 116 132 } 133 134 /** 135 * @brief draws the fog effect 136 */ 117 137 void FogEffect::draw() const { 118 138 … … 120 140 return; 121 141 122 // If Fog Fade 123 if ( this->fogFadeInActivate || this->fogFadeOutActivate ) 124 glFogf(GL_FOG_DENSITY, this->fogFadeDensity); 125 126 } 127 142 // If fog is fading 143 if ( this->fogFadeInActivate || this->fogFadeOutActivate ) { 144 if ( this->fogMode == GL_LINEAR) 145 glFogf(GL_FOG_END, this->fogFadeEnd); 146 else 147 glFogf(GL_FOG_DENSITY, this->fogFadeDensity); 148 } 149 } 150 151 /** 152 * @brief ticks the fog effect 153 * @param dt: tick float 154 */ 128 155 void FogEffect::tick(float dt) { 156 129 157 if (!this->fogActivate) 130 158 return; 131 159 160 // If fog is fading in 132 161 if ( this->fogFadeInActivate ) { 133 162 this->localTimer += dt; 134 this->fogFadeDensity = ( this->localTimer / this->fogFadeInDuration ) * this->fogDensity; 135 136 if ( this->localTimer >= this->fogFadeOutDuration ) 163 164 if ( this->fogMode == GL_LINEAR) 165 this->fogFadeEnd = 2000 * (1 - ( this->localTimer / this->fogFadeInDuration )) + this->fogEnd; 166 else 167 this->fogFadeDensity = ( this->localTimer / this->fogFadeInDuration ) * this->fogDensity; 168 169 if ( this->localTimer >= this->fogFadeInDuration ) 137 170 this->fogFadeInActivate = false; 138 171 } 139 172 173 // If fog is fading out 140 174 if ( this->fogFadeOutActivate ) { 141 175 this->localTimer += dt; 142 this->fogFadeDensity = 1 - (( this->localTimer / this->fogFadeInDuration ) * this->fogDensity); 176 177 if ( this->fogMode == GL_LINEAR) 178 this->fogFadeEnd = 2000 * ( this->localTimer / this->fogFadeInDuration ) + this->fogEnd; 179 else 180 this->fogFadeDensity = 1 - (( this->localTimer / this->fogFadeInDuration ) * this->fogDensity); 143 181 144 182 if ( this->localTimer >= this->fogFadeOutDuration ) … … 147 185 } 148 186 187 /** 188 * @brief fades the fog in 189 */ 149 190 void FogEffect::fadeInFog() { 150 191 … … 163 204 this->localTimer = 0; 164 205 206 // Activate Fog 207 this->activate(); 208 165 209 // set FogFadeIn activate 166 210 this->fogFadeInActivate = true; 167 168 // Activate Fog 169 this->activate(); 170 171 } 172 173 211 } 212 213 /** 214 * @brief fades the fog out 215 */ 174 216 void FogEffect::fadeOutFog() { 175 217 … … 190 232 // Reset local timer 191 233 this->localTimer = 0; 192 193 } 194 195 196 GLint FogEffect::stringToFogMode(const std::string& mode) { 197 if(mode == "GL_LINEAR") 198 return GL_LINEAR; 199 else if(mode == "GL_EXP") 200 return GL_EXP; 201 else if(mode == "GL_EXP2" ) 202 return GL_EXP2; 203 else 204 return -1; 205 } 206 207 234 } 235
Note: See TracChangeset
for help on using the changeset viewer.