Changeset 8457 in orxonox.OLD for branches/atmospheric_engine/src/lib/graphics/effects/rain_effect.cc
- Timestamp:
- Jun 15, 2006, 1:43:24 PM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/atmospheric_engine/src/lib/graphics/effects/rain_effect.cc
r8455 r8457 39 39 40 40 /* TODO: 41 42 43 44 45 46 41 - preCaching 42 - test multiple rain emitters 43 - Think about what happens with building poss. to hang movewithcam off 44 - Possible to activate lightening 45 - turn off visibility when in a building 46 - variable emitter size depending on playable 47 47 */ 48 48 49 RainEffect::RainEffect(const TiXmlElement* root) 50 { 51 this->setClassID(CL_RAIN_EFFECT, "RainEffect"); 52 53 this->init(); 54 55 if (root != NULL) 56 this->loadParams(root); 57 58 //load rain sound 59 if (this->rainBuffer != NULL) 60 ResourceManager::getInstance()->unload(this->rainBuffer); 61 this->rainBuffer = (OrxSound::SoundBuffer*)ResourceManager::getInstance()->load("sound/atmosphere/rain.wav", WAV); 62 63 //load wind sound 64 if (this->rainWindForce != 0) { 65 if (this->windBuffer != NULL) 66 ResourceManager::getInstance()->unload(this->windBuffer); 67 this->windBuffer = (OrxSound::SoundBuffer*)ResourceManager::getInstance()->load("sound/atmosphere/wind.wav", WAV); 68 } 69 70 if(rainActivate) 71 this->activate(); 72 } 73 74 RainEffect::~RainEffect() 75 { 76 this->deactivate(); 77 78 if (this->rainBuffer != NULL) 79 ResourceManager::getInstance()->unload(this->rainBuffer); 80 81 if (this->windBuffer != NULL) 82 ResourceManager::getInstance()->unload(this->windBuffer); 83 } 84 85 void RainEffect::loadParams(const TiXmlElement* root) 86 { 87 WeatherEffect::loadParams(root); 88 89 LoadParam(root, "coord", this, RainEffect, setRainCoord); 90 LoadParam(root, "size", this, RainEffect, setRainSize); 91 LoadParam(root, "rate", this, RainEffect, setRainRate); 92 LoadParam(root, "velocity", this, RainEffect, setRainVelocity); 93 LoadParam(root, "life", this, RainEffect, setRainLife); 94 LoadParam(root, "wind", this, RainEffect, setRainWind); 95 LoadParam(root, "fadeinduration", this, RainEffect, setRainFadeIn); 96 LoadParam(root, "fadeoutduration", this, RainEffect, setRainFadeOut); 97 98 LOAD_PARAM_START_CYCLE(root, element); 99 { 100 LoadParam_CYCLE(element, "option", this, RainEffect, setRainOption); 101 } 102 LOAD_PARAM_END_CYCLE(element); 103 104 } 105 106 107 void RainEffect::init() 108 { 109 //Default values 110 this->rainActivate = false; 111 this->rainMove = false; 112 this->rainCoord = Vector(500, 500, 500); 113 this->rainSize = Vector2D(1000, 1000); 114 this->rainRate = 4000; 115 this->rainVelocity = -300; 116 this->rainLife = 4; 117 this->rainMaxParticles = this->rainRate * this->rainLife; 118 this->rainWindForce = 0; 119 this->rainFadeInDuration = 0; 120 this->rainFadeOutDuration = 0; 121 this->localTimer = 0; 122 this->soundRainVolume = 0.8f; 123 124 this->emitter = new PlaneEmitter(this->rainSize); 125 126 lightMan = LightManager::getInstance(); 127 this->rainAmbient = lightMan->getAmbientColor(); 49 RainEffect::RainEffect(const TiXmlElement* root) { 50 this->setClassID(CL_RAIN_EFFECT, "RainEffect"); 51 52 this->init(); 53 54 if (root != NULL) 55 this->loadParams(root); 56 57 //load rain sound 58 if (this->rainBuffer != NULL) 59 ResourceManager::getInstance()->unload(this->rainBuffer); 60 this->rainBuffer = (OrxSound::SoundBuffer*)ResourceManager::getInstance()->load("sound/atmosphere/rain.wav", WAV); 61 62 //load wind sound 63 if (this->rainWindForce != 0) { 64 if (this->windBuffer != NULL) 65 ResourceManager::getInstance()->unload(this->windBuffer); 66 this->windBuffer = (OrxSound::SoundBuffer*)ResourceManager::getInstance()->load("sound/atmosphere/wind.wav", WAV); 67 } 68 69 if(rainActivate) 70 this->activate(); 71 } 72 73 RainEffect::~RainEffect() { 74 this->deactivate(); 75 76 if (this->rainBuffer != NULL) 77 ResourceManager::getInstance()->unload(this->rainBuffer); 78 79 if (this->windBuffer != NULL) 80 ResourceManager::getInstance()->unload(this->windBuffer); 81 } 82 83 void RainEffect::loadParams(const TiXmlElement* root) { 84 WeatherEffect::loadParams(root); 85 86 LoadParam(root, "coord", this, RainEffect, setRainCoord); 87 LoadParam(root, "size", this, RainEffect, setRainSize); 88 LoadParam(root, "rate", this, RainEffect, setRainRate); 89 LoadParam(root, "velocity", this, RainEffect, setRainVelocity); 90 LoadParam(root, "life", this, RainEffect, setRainLife); 91 LoadParam(root, "wind", this, RainEffect, setRainWind); 92 LoadParam(root, "fadeinduration", this, RainEffect, setRainFadeIn); 93 LoadParam(root, "fadeoutduration", this, RainEffect, setRainFadeOut); 94 95 LOAD_PARAM_START_CYCLE(root, element); 96 { 97 LoadParam_CYCLE(element, "option", this, RainEffect, setRainOption); 98 } 99 LOAD_PARAM_END_CYCLE(element); 100 101 } 102 103 104 void RainEffect::init() { 105 //Default values 106 this->rainActivate = false; 107 this->rainMove = false; 108 this->rainCoord = Vector(500, 500, 500); 109 this->rainSize = Vector2D(1000, 1000); 110 this->rainRate = 4000; 111 this->rainVelocity = -300; 112 this->rainLife = 4; 113 this->rainMaxParticles = this->rainRate * this->rainLife; 114 this->rainWindForce = 0; 115 this->rainFadeInDuration = 0; 116 this->rainFadeOutDuration = 0; 117 this->localTimer = 0; 118 this->soundRainVolume = 0.8f; 119 120 this->emitter = new PlaneEmitter(this->rainSize); 121 122 lightMan = LightManager::getInstance(); 123 this->rainAmbient = lightMan->getAmbientColor(); 128 124 } 129 125 … … 131 127 SparkParticles* RainEffect::rainParticles = NULL; 132 128 133 void RainEffect::activate() 134 { 135 PRINTF(0)( "Activating RainEffect, coord: %f, %f, %f, size: %f, %f, rate: %f, velocity: %f, moveRain: %s\n", this->rainCoord.x, this->rainCoord.y, this->rainCoord.z, this->rainSize.x, this-> rainSize.y, this->rainRate, this->rainVelocity, this->rainMove ? "true" : "false" ); 136 137 this->rainActivate = true; 138 139 if (unlikely(RainEffect::rainParticles == NULL)) 140 { 141 RainEffect::rainParticles = new SparkParticles((int) this->rainMaxParticles); 142 RainEffect::rainParticles->setName("RainParticles"); 143 RainEffect::rainParticles->precache((int)this->rainLife, 30); // TODO: Why doesnt this work?? 144 RainEffect::rainParticles->setLifeSpan(this->rainLife, 2); 145 RainEffect::rainParticles->setRadius(0, 0.03); 146 RainEffect::rainParticles->setRadius(0.2, 0.02); 147 RainEffect::rainParticles->setRadius(1, 0.01); 148 RainEffect::rainParticles->setColor(0, 0.3, 0.3, 0.5, 0.2); // grey blue 1 149 RainEffect::rainParticles->setColor(0.5, 0.4, 0.4, 0.5, 0.2); // grey blue 2 150 RainEffect::rainParticles->setColor(1, 0.7, 0.7, 0.7, 0.2); // light grey 151 } 152 153 this->emitter->setSystem(RainEffect::rainParticles); 154 155 this->emitter->setRelCoor(this->rainCoord); 156 157 this->emitter->setEmissionRate(this->rainRate); 158 this->emitter->setEmissionVelocity(this->rainVelocity); 159 160 this->emitter->setSpread(this->rainWindForce / 50, 0.2); 161 162 this->soundSource.loop(this->rainBuffer, this->soundRainVolume); 163 if (this->rainWindForce != 0) this->soundSource.loop(this->windBuffer, 0.1f * this->rainWindForce); 164 165 if (this->rainFadeInDuration == 0) 166 lightMan->setAmbientColor(.1,.1,.1); 167 168 } 169 170 171 void RainEffect::deactivate() 172 { 173 PRINTF(0)("Deactivating RainEffect\n"); 174 175 this->rainActivate = false; 176 this->emitter->setSystem(NULL); 177 178 // Stop Sound 179 this->soundSource.stop(); 180 181 // Restore Light Ambient 182 lightMan->setAmbientColor(this->rainAmbient, this->rainAmbient, this->rainAmbient); 183 184 } 185 186 void RainEffect::tick (float dt) 187 { 188 if (!this->rainActivate) 189 return; 190 191 if (this->rainMove) { 192 this->rainCoord = State::getCameraNode()->getAbsCoor(); 193 this->emitter->setRelCoor(this->rainCoord.x , this->rainCoord.y+800, this->rainCoord.z); 194 } 195 196 if (this->rainFadeInDuration != 0 && this->localTimer < this->rainFadeInDuration) { 197 this->localTimer += dt; 198 float progress = this->localTimer / this->rainFadeInDuration; 199 200 // Dim Light 201 lightMan->setAmbientColor(1 - progress * 0.9, 1 - progress * 0.9, 1 - progress * 0.9); 202 203 // use alpha in color to fade in 204 RainEffect::rainParticles->setColor(0, 0.3, 0.3, 0.5, 0.2 * progress); // grey blue 1 205 RainEffect::rainParticles->setColor(0.5, 0.4, 0.4, 0.5, 0.2 * progress); // grey blue 2 206 RainEffect::rainParticles->setColor(1, 0.7, 0.7, 0.7, 0.2 * progress); // light grey 207 208 // increase radius for more "heavy" rain 209 RainEffect::rainParticles->setRadius(0, 0.03 * progress); 210 RainEffect::rainParticles->setRadius(0.2, 0.02 * progress); 211 RainEffect::rainParticles->setRadius(1, 0.01 * progress); 212 213 // increase sound volume 214 // this->soundSource.fadein(this->rainBuffer, 10); 215 } 216 else if ( this->rainFadeOutDuration != 0 ) { 217 if ( this->localTimer < this->rainFadeOutDuration ) { 218 this->localTimer += dt; 219 float progress = 1 - (this->localTimer / this->rainFadeOutDuration); 220 221 // Fade In Light 222 lightMan->setAmbientColor(1 - progress * 0.9, 1 - progress * 0.9, 1 - progress * 0.9); 223 224 // use alpha in color to fade out 225 RainEffect::rainParticles->setColor(0, 0.3, 0.3, 0.5, 0.2 * progress); // grey blue 1 226 RainEffect::rainParticles->setColor(0.5, 0.4, 0.4, 0.5, 0.2 * progress); // grey blue 2 227 RainEffect::rainParticles->setColor(1, 0.7, 0.7, 0.7, 0.2 * progress); // light grey 228 229 // decrease radius 230 RainEffect::rainParticles->setRadius(0, 0.03 * progress); 231 RainEffect::rainParticles->setRadius(0.2, 0.02 * progress); 232 RainEffect::rainParticles->setRadius(1, 0.01 * progress); 233 234 // decrease sound volume 235 // this->soundSource.fadeout(this->rainBuffer, 10); 236 } 237 else 238 this->deactivate(); 239 } 240 129 void RainEffect::activate() { 130 PRINTF(0)( "Activating RainEffect, coord: %f, %f, %f, size: %f, %f, rate: %f, velocity: %f, moveRain: %s\n", this->rainCoord.x, this->rainCoord.y, this->rainCoord.z, this->rainSize.x, this-> rainSize.y, this->rainRate, this->rainVelocity, this->rainMove ? "true" : "false" ); 131 132 this->rainActivate = true; 133 134 if (unlikely(RainEffect::rainParticles == NULL)) { 135 RainEffect::rainParticles = new SparkParticles((int) this->rainMaxParticles); 136 RainEffect::rainParticles->setName("RainParticles"); 137 RainEffect::rainParticles->setLifeSpan(this->rainLife, 2); 138 RainEffect::rainParticles->setRadius(0, 0.03); 139 RainEffect::rainParticles->setRadius(0.2, 0.02); 140 RainEffect::rainParticles->setRadius(1, 0.01); 141 RainEffect::rainParticles->setColor(0, 0.3, 0.3, 0.5, 0.2); // grey blue 1 142 RainEffect::rainParticles->setColor(0.5, 0.4, 0.4, 0.5, 0.2); // grey blue 2 143 RainEffect::rainParticles->setColor(1, 0.7, 0.7, 0.7, 0.2); // light grey 144 } 145 146 this->emitter->setSystem(RainEffect::rainParticles); 147 148 this->emitter->setRelCoor(this->rainCoord); 149 150 this->emitter->setEmissionRate(this->rainRate); 151 this->emitter->setEmissionVelocity(this->rainVelocity); 152 153 this->emitter->setSpread(this->rainWindForce / 50, 0.2); 154 155 RainEffect::rainParticles->precache((int)this->rainLife); 156 157 this->soundSource.loop(this->rainBuffer, this->soundRainVolume); 158 if (this->rainWindForce != 0) 159 this->soundSource.loop(this->windBuffer, 0.1f * this->rainWindForce); 160 161 if (this->rainFadeInDuration == 0) 162 lightMan->setAmbientColor(.1,.1,.1); 163 164 } 165 166 167 void RainEffect::deactivate() { 168 PRINTF(0)("Deactivating RainEffect\n"); 169 170 this->rainActivate = false; 171 this->emitter->setSystem(NULL); 172 173 // Stop Sound 174 this->soundSource.stop(); 175 176 // Restore Light Ambient 177 lightMan->setAmbientColor(this->rainAmbient, this->rainAmbient, this->rainAmbient); 178 179 } 180 181 void RainEffect::tick (float dt) { 182 if (!this->rainActivate) 183 return; 184 185 if (this->rainMove) { 186 this->rainCoord = State::getCameraNode()->getAbsCoor(); 187 this->emitter->setRelCoor(this->rainCoord.x , this->rainCoord.y+800, this->rainCoord.z); 188 } 189 190 if (this->rainFadeInDuration != 0 && this->localTimer < this->rainFadeInDuration) { 191 this->localTimer += dt; 192 float progress = this->localTimer / this->rainFadeInDuration; 193 194 // Dim Light 195 lightMan->setAmbientColor(1 - progress * 0.9, 1 - progress * 0.9, 1 - progress * 0.9); 196 197 // use alpha in color to fade in 198 RainEffect::rainParticles->setColor(0, 0.3, 0.3, 0.5, 0.2 * progress); // grey blue 1 199 RainEffect::rainParticles->setColor(0.5, 0.4, 0.4, 0.5, 0.2 * progress); // grey blue 2 200 RainEffect::rainParticles->setColor(1, 0.7, 0.7, 0.7, 0.2 * progress); // light grey 201 202 // increase radius for more "heavy" rain 203 RainEffect::rainParticles->setRadius(0, 0.03 * progress); 204 RainEffect::rainParticles->setRadius(0.2, 0.02 * progress); 205 RainEffect::rainParticles->setRadius(1, 0.01 * progress); 206 207 // increase sound volume 208 // this->soundSource.fadein(this->rainBuffer, 10); 209 } else if ( this->rainFadeOutDuration != 0 ) { 210 if ( this->localTimer < this->rainFadeOutDuration ) { 211 this->localTimer += dt; 212 float progress = 1 - (this->localTimer / this->rainFadeOutDuration); 213 214 // Fade In Light 215 lightMan->setAmbientColor(1 - progress * 0.9, 1 - progress * 0.9, 1 - progress * 0.9); 216 217 // use alpha in color to fade out 218 RainEffect::rainParticles->setColor(0, 0.3, 0.3, 0.5, 0.2 * progress); // grey blue 1 219 RainEffect::rainParticles->setColor(0.5, 0.4, 0.4, 0.5, 0.2 * progress); // grey blue 2 220 RainEffect::rainParticles->setColor(1, 0.7, 0.7, 0.7, 0.2 * progress); // light grey 221 222 // decrease radius 223 RainEffect::rainParticles->setRadius(0, 0.03 * progress); 224 RainEffect::rainParticles->setRadius(0.2, 0.02 * progress); 225 RainEffect::rainParticles->setRadius(1, 0.01 * progress); 226 227 // decrease sound volume 228 // this->soundSource.fadeout(this->rainBuffer, 10); 229 } else 230 this->deactivate(); 231 } 232 241 233 } 242 234 243 235 void RainEffect::startRaining() { 244 236 245 246 247 248 249 250 251 252 253 237 if (this->rainActivate) 238 this->deactivate(); 239 240 if (!this->rainFadeInDuration > 0) 241 this->rainFadeInDuration = 20; 242 243 this->localTimer = 0; 244 245 this->activate(); 254 246 255 247 } … … 257 249 void RainEffect::stopRaining() { 258 250 259 260 261 262 263 264 265 266 267 } 251 if (!this->rainActivate) 252 this->activate(); 253 254 if (!this->rainFadeOutDuration > 0) 255 this->rainFadeOutDuration = 20; 256 257 this->localTimer = 0; 258 259 }
Note: See TracChangeset
for help on using the changeset viewer.