Changeset 8255 in orxonox.OLD for trunk/src/lib/graphics/effects/rain_effect.cc
- Timestamp:
- Jun 8, 2006, 3:44:12 PM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/graphics/effects/rain_effect.cc
r7810 r8255 1 1 /* 2 3 4 5 6 7 8 9 2 orxonox - the future of 3D-vertical-scrollers 3 4 Copyright (C) 2004 orx 5 6 This program is free software; you can redistribute it and/or modify 7 it under the terms of the GNU General Public License as published by 8 the Free Software Foundation; either version 2, or (at your option) 9 any later version. 10 10 11 11 ### File Specific: 12 12 main-programmer: hdavid, amaechler 13 13 */ 14 14 … … 25 25 #include "plane_emitter.h" 26 26 #include "shell_command.h" 27 #include "light.h" 27 28 28 29 #include "parser/tinyxml/tinyxml.h" … … 31 32 SHELL_COMMAND(deactivate, RainEffect, deactivateRain); 32 33 34 SHELL_COMMAND(startRaining, RainEffect, startRaining); 35 33 36 using namespace std; 34 37 35 38 CREATE_FACTORY(RainEffect, CL_RAIN_EFFECT); 39 40 // TODO: Dim Light with Rain, Finish preCaching, check out if multiple rain emitters work, Think about what happens with building poss. to hang movewithcam off, benchmark, possible to activate lightening, turn off visibility when in a building, variable emitter size depending on playable, also rain velocity 36 41 37 42 RainEffect::RainEffect(const TiXmlElement* root) … … 50 55 51 56 //load wind sound 52 if (this->rainWindForce >0) {57 if (this->rainWindForce != 0) { 53 58 if (this->windBuffer != NULL) 54 59 ResourceManager::getInstance()->unload(this->windBuffer); … … 56 61 } 57 62 58 this->activate(); 63 if(rainActivate) 64 this->activate(); 59 65 } 60 66 … … 80 86 LoadParam(root, "life", this, RainEffect, setRainLife); 81 87 LoadParam(root, "wind", this, RainEffect, setRainWind); 82 LoadParam(root, "option", this, RainEffect, setRainOption); 88 LoadParam(root, "startraining", this, RainEffect, setRainStart); 89 90 LOAD_PARAM_START_CYCLE(root, element); 91 { 92 LoadParam_CYCLE(element, "option", this, RainEffect, setRainOption); 93 } 94 LOAD_PARAM_END_CYCLE(element); 95 83 96 } 84 97 … … 87 100 { 88 101 //Default values 102 this->rainActivate = false; 103 this->rainMove = false; 89 104 this->rainCoord = Vector(500, 500, 500); 90 105 this->rainSize = Vector2D(1000, 1000); … … 94 109 this->rainMaxParticles = this->rainRate * this->rainLife; 95 110 this->rainWindForce = 0; 111 this->rainStartDuration = 0; 112 this->localTimer = 0; 113 this->soundRainVolume = 0.8f; 96 114 97 115 this->emitter = new PlaneEmitter(this->rainSize); 116 117 lightMan = LightManager::getInstance(); 118 this->rainAmbient = lightMan->getAmbientColor(); 98 119 } 99 120 … … 104 125 { 105 126 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" ); 127 128 this->rainActivate = true; 106 129 107 130 if (unlikely(RainEffect::rainParticles == NULL)) … … 114 137 RainEffect::rainParticles->setRadius(0.2, 0.02); 115 138 RainEffect::rainParticles->setRadius(1, 0.01); 116 RainEffect::rainParticles->setColor(0, 0.3, 0.3, 0.5, 0.2); 117 RainEffect::rainParticles->setColor(0.5, 0.4, 0.4, 0.5, 0.2); 118 RainEffect::rainParticles->setColor(1, 0.7, 0.7, 0.7, 0.2); 139 RainEffect::rainParticles->setColor(0, 0.3, 0.3, 0.5, 0.2); // grey blue 1 140 RainEffect::rainParticles->setColor(0.5, 0.4, 0.4, 0.5, 0.2); // grey blue 2 141 RainEffect::rainParticles->setColor(1, 0.7, 0.7, 0.7, 0.2); // light grey 119 142 } 120 143 … … 128 151 this->emitter->setSpread(this->rainWindForce / 50, 0.2); 129 152 130 this->soundSource.loop(this->rainBuffer); 131 if (this->rainWindForce > 0) 132 this->soundSource.loop(this->windBuffer); 153 this->soundSource.loop(this->rainBuffer, this->soundRainVolume); 154 if (this->rainWindForce != 0) this->soundSource.loop(this->windBuffer, 0.1f * this->rainWindForce); 155 156 lightMan->setAmbientColor(.1,.1,.1); 133 157 } 134 158 … … 137 161 { 138 162 PRINTF(0)("Deactivating RainEffect\n"); 163 164 this->rainActivate = false; 139 165 this->emitter->setSystem(NULL); 140 166 167 // Stop Sound 141 168 this->soundSource.stop(); 142 } 143 144 void RainEffect::activateRain() 145 { 146 this->activate(); 147 } 148 149 void RainEffect::deactivateRain() 150 { 151 this->deactivate(); 152 } 153 169 170 // Restore Light Ambient 171 lightMan->setAmbientColor(this->rainAmbient, this->rainAmbient, this->rainAmbient); 172 } 154 173 155 174 void RainEffect::tick (float dt) 156 175 { 176 if (!this->rainActivate) 177 return; 178 157 179 if (this->rainMove) { 158 180 this->rainCoord = State::getCameraNode()->getAbsCoor(); 159 181 this->emitter->setRelCoor(this->rainCoord.x , this->rainCoord.y+800, this->rainCoord.z); 160 182 } 161 } 183 184 if (this->rainStartDuration != 0 && this->localTimer < this->rainStartDuration) { 185 this->localTimer += dt; 186 float progress = this->localTimer / this->rainStartDuration; 187 188 // Dim Light 189 lightMan->setAmbientColor(1.1 - progress, 1.1 - progress, 1.1 - progress); 190 191 // use alpha in color to fade in 192 RainEffect::rainParticles->setColor(0, 0.3, 0.3, 0.5, 0.2 * progress); // grey blue 1 193 RainEffect::rainParticles->setColor(0.5, 0.4, 0.4, 0.5, 0.2 * progress); // grey blue 2 194 RainEffect::rainParticles->setColor(1, 0.7, 0.7, 0.7, 0.2 * progress); // light grey 195 196 // increase radius for more "heavy" rain 197 RainEffect::rainParticles->setRadius(0, 0.03 * progress); 198 RainEffect::rainParticles->setRadius(0.2, 0.02 * progress); 199 RainEffect::rainParticles->setRadius(1, 0.01 * progress); 200 201 // increase sound volume 202 // this->soundSource.fadein(this->rainBuffer, 10); 203 } 204 205 } 206 207 void RainEffect::startRaining() { 208 209 if (this->rainActivate) 210 this->deactivate(); 211 212 this->rainStartDuration = 10; 213 this->localTimer = 0; 214 this->activate(); 215 216 }
Note: See TracChangeset
for help on using the changeset viewer.