Changeset 8771 in orxonox.OLD for branches/atmospheric_engine
- Timestamp:
- Jun 24, 2006, 3:35:07 PM (18 years ago)
- Location:
- branches/atmospheric_engine/src/lib
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/atmospheric_engine/src/lib/graphics/effects/cloud_effect.h
r8733 r8771 1 1 /** 2 * @file cloud_effect.h 2 * @file cloud_effect.h 3 * Creates clouds 3 4 */ 4 5 -
branches/atmospheric_engine/src/lib/graphics/effects/fog_effect.cc
r8734 r8771 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.005; 72 this->fogStart = 0; 73 this->fogEnd = 300; 74 this->colorVector = Vector(0.6, 0.0, 0.0); 75 76 // init variables 77 this->fogFadeInDuration = 0; 78 this->fogFadeOutDuration = 0; 79 this->fogFadeDensity = 0; 80 this->fogFadeEnd = 0; 81 82 this->localTimer = 0; 83 this->fogActivate = false; 84 this->fogFadeInActivate = false; 85 this->fogFadeOutActivate = false; 86 87 } 88 89 101 /** 102 * @brief activates the fog effect 103 */ 90 104 void FogEffect::activate() { 91 105 PRINTF(0)( "Activating FogEffect\n"); … … 103 117 104 118 glEnable(GL_FOG); 105 106 } 107 108 119 } 120 121 /** 122 * @brief deactivates the fog effect 123 */ 109 124 void FogEffect::deactivate() { 110 125 PRINTF(0)("Deactivating FogEffect\n"); … … 115 130 116 131 glDisable(GL_FOG); 117 118 } 119 132 } 133 134 /** 135 * @brief draws the fog effect 136 */ 120 137 void FogEffect::draw() const { 121 138 … … 123 140 return; 124 141 125 // If Fog Fade142 // If fog is fading 126 143 if ( this->fogFadeInActivate || this->fogFadeOutActivate ) { 127 144 if ( this->fogMode == GL_LINEAR) … … 132 149 } 133 150 151 /** 152 * @brief ticks the fog effect 153 * @param dt: tick float 154 */ 134 155 void FogEffect::tick(float dt) { 135 156 … … 137 158 return; 138 159 160 // If fog is fading in 139 161 if ( this->fogFadeInActivate ) { 140 162 this->localTimer += dt; … … 149 171 } 150 172 173 // If fog is fading out 151 174 if ( this->fogFadeOutActivate ) { 152 175 this->localTimer += dt; … … 162 185 } 163 186 187 /** 188 * @brief fades the fog in 189 */ 164 190 void FogEffect::fadeInFog() { 165 191 … … 183 209 // set FogFadeIn activate 184 210 this->fogFadeInActivate = true; 185 186 } 187 188 211 } 212 213 /** 214 * @brief fades the fog out 215 */ 189 216 void FogEffect::fadeOutFog() { 190 217 … … 205 232 // Reset local timer 206 233 this->localTimer = 0; 207 208 } 209 234 } 235 -
branches/atmospheric_engine/src/lib/graphics/effects/fog_effect.h
r8716 r8771 1 1 /** 2 * @file fog_effect.h 2 * @file fog_effect.h 3 * Generates simple openGL fog 3 4 */ 4 5 … … 10 11 #include "vector.h" 11 12 12 class FogEffect : public WeatherEffect { 13 class FogEffect : public WeatherEffect 14 { 13 15 public: 14 15 16 FogEffect(const TiXmlElement* root = NULL); 17 virtual ~FogEffect(); 16 18 17 19 virtual void loadParams(const TiXmlElement* root); 18 20 19 21 virtual void init(); 20 22 21 22 23 virtual void activate(); 24 virtual void deactivate(); 23 25 24 void activateFog() { 25 this->activate(); 26 } 27 void deactivateFog() { 28 this->deactivate(); 29 } 26 void activateFog() 27 { 28 this->activate(); 29 } 30 30 31 virtual void draw() const; 32 virtual void tick(float dt); 31 void deactivateFog() 32 { 33 this->deactivate(); 34 } 33 35 34 inline void setFogMode(const std::string& mode) { 35 this->fogMode = this->stringToFogMode(mode); 36 } 37 inline void setFogDensity(float density) { 38 this->fogDensity = density; 39 } 40 inline void setFogRange(float start, float end) { 41 this->fogStart = start; 42 this->fogEnd = end; 43 } 44 inline void setFogColor(float r, float g, float b) { 45 this->colorVector = Vector(r, g, b); 46 } 47 inline void setFogFadeIn(float fadein) { 48 this->fogFadeInDuration = fadein; 49 } 50 inline void setFogFadeOut(float fadeout) { 51 this->fogFadeOutDuration = fadeout; 52 } 36 virtual void draw() const; 37 virtual void tick(float dt); 53 38 54 inline void setFogOption(const std::string& option) {55 if (option == "activate")56 this->fogActivate = true;57 39 inline void setFogMode(const std::string& mode) 40 { 41 this->fogMode = this->stringToFogMode(mode); 42 } 58 43 59 void fadeInFog(); 60 void fadeOutFog(); 44 inline void setFogDensity(float density) 45 { 46 this->fogDensity = density; 47 } 48 49 inline void setFogRange(float start, float end) 50 { 51 this->fogStart = start; 52 this->fogEnd = end; 53 } 54 55 inline void setFogColor(float r, float g, float b) 56 { 57 this->colorVector = Vector(r, g, b); 58 } 59 60 inline void setFogFadeIn(float fadein) 61 { 62 this->fogFadeInDuration = fadein; 63 } 64 65 inline void setFogFadeOut(float fadeout) 66 { 67 this->fogFadeOutDuration = fadeout; 68 } 69 70 inline void setFogOption(const std::string& option) 71 { 72 if (option == "activate") 73 this->fogActivate = true; 74 } 75 76 void fadeInFog(); 77 void fadeOutFog(); 61 78 62 79 63 80 private: 64 inline GLint stringToFogMode(const std::string& mode) { 65 if(mode == "GL_LINEAR") 66 return GL_LINEAR; 67 else if(mode == "GL_EXP") 68 return GL_EXP; 69 else if(mode == "GL_EXP2" ) 70 return GL_EXP2; 71 else 72 return -1; 73 } 81 inline GLint stringToFogMode(const std::string& mode) 82 { 83 if(mode == "GL_LINEAR") 84 return GL_LINEAR; 85 else if(mode == "GL_EXP") 86 return GL_EXP; 87 else if(mode == "GL_EXP2" ) 88 return GL_EXP2; 89 else 90 return -1; 91 } 74 92 75 93 bool fogActivate; 76 94 77 78 95 bool fogFadeInActivate; 96 bool fogFadeOutActivate; 79 97 80 81 98 GLfloat fogFadeInDuration; 99 GLfloat fogFadeOutDuration; 82 100 83 float localTimer; 101 GLint fogMode; 102 GLfloat fogDensity; 103 GLfloat fogFadeDensity; 84 104 85 GLint fogMode;86 GLfloat fogDensity;87 GLfloat fogFadeDensity;105 GLfloat fogStart; 106 GLfloat fogEnd; 107 GLfloat fogFadeEnd; 88 108 89 GLfloat fogStart; 90 GLfloat fogEnd; 91 GLfloat fogFadeEnd; 92 93 Vector colorVector; 109 Vector colorVector; 110 float localTimer; 94 111 }; 95 112 96 97 113 #endif /* _FOG_EFFECT */ -
branches/atmospheric_engine/src/lib/graphics/effects/rain_effect.cc
r8734 r8771 1 1 /* 2 2 orxonox - the future of 3D-vertical-scrollers 3 3 4 4 Copyright (C) 2004 orx 5 5 6 6 This program is free software; you can redistribute it and/or modify 7 7 it under the terms of the GNU General Public License as published by 8 8 the Free Software Foundation; either version 2, or (at your option) 9 9 any later version. 10 10 11 11 ### File Specific: 12 12 main-programmer: hdavid, amaechler … … 29 29 #include "parser/tinyxml/tinyxml.h" 30 30 31 // Define shell commands 31 32 SHELL_COMMAND(activate, RainEffect, activateRain); 32 33 SHELL_COMMAND(deactivate, RainEffect, deactivateRain); … … 38 39 CREATE_FACTORY(RainEffect, CL_RAIN_EFFECT); 39 40 40 /* TODO: 41 - test multiple rain emitters <-- doesn't work 42 - Think about what happens with building poss. to hang movewithcam off 43 - Possible to activate lightening 44 - turn off visibility when in a building 45 - variable emitter size depending on playable 41 /** 42 * @brief standard constructor 43 */ 44 RainEffect::RainEffect(const TiXmlElement* root) 45 { 46 this->setClassID(CL_RAIN_EFFECT, "RainEffect"); 47 48 this->init(); 49 50 if (root != NULL) 51 this->loadParams(root); 52 53 //load rain sound 54 if (this->rainBuffer != NULL) 55 ResourceManager::getInstance()->unload(this->rainBuffer); 56 this->rainBuffer = (OrxSound::SoundBuffer*)ResourceManager::getInstance()->load("sound/atmosphere/rain.wav", WAV); 57 58 //load wind sound 59 if (this->rainWindForce != 0) 60 { 61 if (this->windBuffer != NULL) 62 ResourceManager::getInstance()->unload(this->windBuffer); 63 this->windBuffer = (OrxSound::SoundBuffer*)ResourceManager::getInstance()->load("sound/atmosphere/wind.wav", WAV); 64 } 65 66 if(rainActivate) 67 { 68 this->activate(); 69 RainEffect::rainParticles->precache((int)this->rainLife * 2); 70 } 71 } 72 73 /** 74 * @brief standard deconstructor 75 */ 76 RainEffect::~RainEffect() 77 { 78 this->deactivate(); 79 80 if (this->rainBuffer != NULL) 81 ResourceManager::getInstance()->unload(this->rainBuffer); 82 83 if (this->windBuffer != NULL) 84 ResourceManager::getInstance()->unload(this->windBuffer); 85 } 86 87 /** 88 * @brief initalizes the rain effect with default values 89 */ 90 void RainEffect::init() 91 { 92 //Default values 93 this->rainActivate = false; 94 this->rainMove = false; 95 this->rainCoord = Vector(500, 500, 500); 96 this->rainSize = Vector2D(1000, 1000); 97 this->rainRate = 4000; 98 this->rainVelocity = -300; 99 this->rainLife = 4; 100 this->rainWindForce = 0; 101 this->rainFadeInDuration = 0; 102 this->rainFadeOutDuration = 0; 103 104 this->rainMaxParticles = this->rainRate * this->rainLife; 105 this->localTimer = 0; 106 this->soundRainVolume = 0.3f; 107 this->emitter = new PlaneEmitter(this->rainSize); 108 109 lightMan = LightManager::getInstance(); 110 this->rainAmbient = lightMan->getAmbientColor(); 111 } 112 113 /** 114 * @brief loads the rain effect parameters. 115 * @param root: the XML-Element to load the data from 116 */ 117 void RainEffect::loadParams(const TiXmlElement* root) 118 { 119 WeatherEffect::loadParams(root); 120 121 LoadParam(root, "coord", this, RainEffect, setRainCoord); 122 LoadParam(root, "size", this, RainEffect, setRainSize); 123 LoadParam(root, "rate", this, RainEffect, setRainRate); 124 LoadParam(root, "velocity", this, RainEffect, setRainVelocity); 125 LoadParam(root, "life", this, RainEffect, setRainLife); 126 LoadParam(root, "wind", this, RainEffect, setRainWind); 127 LoadParam(root, "fadeinduration", this, RainEffect, setRainFadeIn); 128 LoadParam(root, "fadeoutduration", this, RainEffect, setRainFadeOut); 129 130 LOAD_PARAM_START_CYCLE(root, element); 131 { 132 LoadParam_CYCLE(element, "option", this, RainEffect, setRainOption); 133 } 134 LOAD_PARAM_END_CYCLE(element); 135 } 136 137 SparkParticles* RainEffect::rainParticles = NULL; 138 139 /** 140 * @brief activates the rain effect 141 */ 142 void RainEffect::activate() 143 { 144 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" ); 145 146 this->rainActivate = true; 147 148 if (unlikely(RainEffect::rainParticles == NULL)) 149 { 150 RainEffect::rainParticles = new SparkParticles((int) this->rainMaxParticles); 151 RainEffect::rainParticles->setName("RainParticles"); 152 RainEffect::rainParticles->setLifeSpan(this->rainLife, 2); 153 RainEffect::rainParticles->setRadius(0, 0.03); 154 RainEffect::rainParticles->setRadius(0.2, 0.02); 155 RainEffect::rainParticles->setRadius(1, 0.01); 156 RainEffect::rainParticles->setColor(0, 0.3, 0.3, 0.5, 0.2); // grey blue 1 157 RainEffect::rainParticles->setColor(0.5, 0.4, 0.4, 0.5, 0.2); // grey blue 2 158 RainEffect::rainParticles->setColor(1, 0.7, 0.7, 0.7, 0.2); // light grey 159 } 160 161 this->emitter->setSystem(RainEffect::rainParticles); 162 163 this->emitter->setRelCoor(this->rainCoord); 164 165 this->emitter->setEmissionRate(this->rainRate); 166 this->emitter->setEmissionVelocity(this->rainVelocity); 167 168 this->emitter->setSpread(this->rainWindForce / 50, 0.2); 169 170 // plays the rain sound and loops it 171 this->soundSource.play(this->rainBuffer, this->soundRainVolume, true); 172 173 // if there is wind, play the wind sound 174 if (this->rainWindForce != 0) 175 this->soundSource.play(this->windBuffer, 0.1f * this->rainWindForce, true); 176 177 if (this->rainFadeInDuration == 0) 178 lightMan->setAmbientColor(.1,.1,.1); 179 } 180 181 /** 182 * @brief deactivates the rain effect 183 */ 184 void RainEffect::deactivate() 185 { 186 PRINTF(0)("Deactivating RainEffect\n"); 187 188 this->rainActivate = false; 189 this->emitter->setSystem(NULL); 190 191 // Stop Sound 192 this->soundSource.stop(); 193 194 // Restore Light Ambient 195 lightMan->setAmbientColor(this->rainAmbient, this->rainAmbient, this->rainAmbient); 196 } 197 198 /** 199 * @brief ticks the rain effect 200 * @param dt: tick float 201 */ 202 void RainEffect::tick (float dt) 203 { 204 if (!this->rainActivate) 205 return; 206 207 if (this->rainMove) 208 { 209 this->rainCoord = State::getCameraNode()->getAbsCoor(); 210 this->emitter->setRelCoor(this->rainCoord.x , this->rainCoord.y+800, this->rainCoord.z); 211 } 212 213 if (this->rainFadeInDuration != 0 && this->localTimer < this->rainFadeInDuration) 214 { 215 this->localTimer += dt; 216 float progress = this->localTimer / this->rainFadeInDuration; 217 218 // Dim Light 219 lightMan->setAmbientColor(1 - progress * 0.9, 1 - progress * 0.9, 1 - progress * 0.9); 220 221 // use alpha in color to fade in 222 RainEffect::rainParticles->setColor(0, 0.3, 0.3, 0.5, 0.2 * progress); // grey blue 1 223 RainEffect::rainParticles->setColor(0.5, 0.4, 0.4, 0.5, 0.2 * progress); // grey blue 2 224 RainEffect::rainParticles->setColor(1, 0.7, 0.7, 0.7, 0.2 * progress); // light grey 225 226 // increase radius for more "heavy" rain 227 RainEffect::rainParticles->setRadius(0, 0.03 * progress); 228 RainEffect::rainParticles->setRadius(0.2, 0.02 * progress); 229 RainEffect::rainParticles->setRadius(1, 0.01 * progress); 230 231 // increase sound volume 232 if (!this->soundSource.isPlaying()) 233 this->soundSource.play(this->rainBuffer, this->soundRainVolume, true); 234 235 this->soundSource.gain(this->rainBuffer, this->soundRainVolume * progress); 236 } 237 else if ( this->rainFadeOutDuration != 0 ) 238 { 239 if ( this->localTimer < this->rainFadeOutDuration ) 240 { 241 this->localTimer += dt; 242 float progress = 1 - (this->localTimer / this->rainFadeOutDuration); 243 244 // Fade In Light 245 lightMan->setAmbientColor(1 - progress * 0.9, 1 - progress * 0.9, 1 - progress * 0.9); 246 247 // use alpha in color to fade out 248 RainEffect::rainParticles->setColor(0, 0.3, 0.3, 0.5, 0.2 * progress); // grey blue 1 249 RainEffect::rainParticles->setColor(0.5, 0.4, 0.4, 0.5, 0.2 * progress); // grey blue 2 250 RainEffect::rainParticles->setColor(1, 0.7, 0.7, 0.7, 0.2 * progress); // light grey 251 252 // decrease radius 253 RainEffect::rainParticles->setRadius(0, 0.03 * progress); 254 RainEffect::rainParticles->setRadius(0.2, 0.02 * progress); 255 RainEffect::rainParticles->setRadius(1, 0.01 * progress); 256 257 // decrease sound volume 258 if (!this->soundSource.isPlaying()) 259 this->soundSource.play(this->rainBuffer, this->soundRainVolume, true); 260 261 this->soundSource.gain(this->rainBuffer, this->soundRainVolume * progress); 262 } 263 else 264 this->deactivate(); 265 } 266 } 267 268 /** 269 * @brief starts raining slowly 46 270 */ 47 48 RainEffect::RainEffect(const TiXmlElement* root) { 49 this->setClassID(CL_RAIN_EFFECT, "RainEffect"); 50 51 this->init(); 52 53 if (root != NULL) 54 this->loadParams(root); 55 56 //load rain sound 57 if (this->rainBuffer != NULL) 58 ResourceManager::getInstance()->unload(this->rainBuffer); 59 this->rainBuffer = (OrxSound::SoundBuffer*)ResourceManager::getInstance()->load("sound/atmosphere/rain.wav", WAV); 60 61 //load wind sound 62 if (this->rainWindForce != 0) { 63 if (this->windBuffer != NULL) 64 ResourceManager::getInstance()->unload(this->windBuffer); 65 this->windBuffer = (OrxSound::SoundBuffer*)ResourceManager::getInstance()->load("sound/atmosphere/wind.wav", WAV); 66 } 67 68 if(rainActivate) { 69 this->activate(); 70 RainEffect::rainParticles->precache((int)this->rainLife * 5); // TODO: Figure out the correct value 71 } 72 } 73 74 RainEffect::~RainEffect() { 271 void RainEffect::startRaining() 272 { 273 274 if (this->rainActivate) 75 275 this->deactivate(); 76 276 77 if (this->rainBuffer != NULL) 78 ResourceManager::getInstance()->unload(this->rainBuffer); 79 80 if (this->windBuffer != NULL) 81 ResourceManager::getInstance()->unload(this->windBuffer); 82 } 83 84 void RainEffect::loadParams(const TiXmlElement* root) { 85 WeatherEffect::loadParams(root); 86 87 LoadParam(root, "coord", this, RainEffect, setRainCoord); 88 LoadParam(root, "size", this, RainEffect, setRainSize); 89 LoadParam(root, "rate", this, RainEffect, setRainRate); 90 LoadParam(root, "velocity", this, RainEffect, setRainVelocity); 91 LoadParam(root, "life", this, RainEffect, setRainLife); 92 LoadParam(root, "wind", this, RainEffect, setRainWind); 93 LoadParam(root, "fadeinduration", this, RainEffect, setRainFadeIn); 94 LoadParam(root, "fadeoutduration", this, RainEffect, setRainFadeOut); 95 96 LOAD_PARAM_START_CYCLE(root, element); 97 { 98 LoadParam_CYCLE(element, "option", this, RainEffect, setRainOption); 99 } 100 LOAD_PARAM_END_CYCLE(element); 101 102 } 103 104 105 void RainEffect::init() { 106 //Default values 107 this->rainActivate = false; 108 this->rainMove = false; 109 this->rainCoord = Vector(500, 500, 500); 110 this->rainSize = Vector2D(1000, 1000); 111 this->rainRate = 4000; 112 this->rainVelocity = -300; 113 this->rainLife = 4; 114 this->rainMaxParticles = this->rainRate * this->rainLife; 115 this->rainWindForce = 0; 116 this->rainFadeInDuration = 0; 117 this->rainFadeOutDuration = 0; 118 this->localTimer = 0; 119 this->soundRainVolume = 0.3f; 120 121 this->emitter = new PlaneEmitter(this->rainSize); 122 123 lightMan = LightManager::getInstance(); 124 this->rainAmbient = lightMan->getAmbientColor(); 125 } 126 127 128 SparkParticles* RainEffect::rainParticles = NULL; 129 130 void RainEffect::activate() { 131 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" ); 132 133 this->rainActivate = true; 134 135 if (unlikely(RainEffect::rainParticles == NULL)) { 136 RainEffect::rainParticles = new SparkParticles((int) this->rainMaxParticles); 137 RainEffect::rainParticles->setName("RainParticles"); 138 RainEffect::rainParticles->setLifeSpan(this->rainLife, 2); 139 RainEffect::rainParticles->setRadius(0, 0.03); 140 RainEffect::rainParticles->setRadius(0.2, 0.02); 141 RainEffect::rainParticles->setRadius(1, 0.01); 142 RainEffect::rainParticles->setColor(0, 0.3, 0.3, 0.5, 0.2); // grey blue 1 143 RainEffect::rainParticles->setColor(0.5, 0.4, 0.4, 0.5, 0.2); // grey blue 2 144 RainEffect::rainParticles->setColor(1, 0.7, 0.7, 0.7, 0.2); // light grey 145 } 146 147 this->emitter->setSystem(RainEffect::rainParticles); 148 149 this->emitter->setRelCoor(this->rainCoord); 150 151 this->emitter->setEmissionRate(this->rainRate); 152 this->emitter->setEmissionVelocity(this->rainVelocity); 153 154 this->emitter->setSpread(this->rainWindForce / 50, 0.2); 155 156 this->soundSource.play(this->rainBuffer, this->soundRainVolume, true); 157 158 if (this->rainWindForce != 0) 159 this->soundSource.play(this->windBuffer, 0.1f * this->rainWindForce, true); 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 210 } else if ( this->rainFadeOutDuration != 0 ) { 211 if ( this->localTimer < this->rainFadeOutDuration ) { 212 this->localTimer += dt; 213 float progress = 1 - (this->localTimer / this->rainFadeOutDuration); 214 215 // Fade In Light 216 lightMan->setAmbientColor(1 - progress * 0.9, 1 - progress * 0.9, 1 - progress * 0.9); 217 218 // use alpha in color to fade out 219 RainEffect::rainParticles->setColor(0, 0.3, 0.3, 0.5, 0.2 * progress); // grey blue 1 220 RainEffect::rainParticles->setColor(0.5, 0.4, 0.4, 0.5, 0.2 * progress); // grey blue 2 221 RainEffect::rainParticles->setColor(1, 0.7, 0.7, 0.7, 0.2 * progress); // light grey 222 223 // decrease radius 224 RainEffect::rainParticles->setRadius(0, 0.03 * progress); 225 RainEffect::rainParticles->setRadius(0.2, 0.02 * progress); 226 RainEffect::rainParticles->setRadius(1, 0.01 * progress); 227 228 // decrease sound volume 229 // this->soundSource.fadeout(this->rainBuffer, 10); 230 231 } else 232 this->deactivate(); 233 } 234 235 } 236 237 void RainEffect::startRaining() { 238 239 if (this->rainActivate) 240 this->deactivate(); 241 242 if (!this->rainFadeInDuration > 0) 243 this->rainFadeInDuration = 20; 244 245 this->localTimer = 0; 246 277 if (!this->rainFadeInDuration > 0) 278 this->rainFadeInDuration = 20; 279 280 this->localTimer = 0; 281 282 this->activate(); 283 } 284 285 /** 286 * @brief stops raining slowly 287 */ 288 void RainEffect::stopRaining() 289 { 290 291 if (!this->rainActivate) 247 292 this->activate(); 248 293 249 } 250 251 void RainEffect::stopRaining() { 252 253 if (!this->rainActivate) 254 this->activate(); 255 256 if (!this->rainFadeOutDuration > 0) 257 this->rainFadeOutDuration = 20; 258 259 this->localTimer = 0; 260 261 } 262 263 void RainEffect::hideRain() { 264 294 if (!this->rainFadeOutDuration > 0) 295 this->rainFadeOutDuration = 20; 296 297 this->localTimer = 0; 298 } 299 300 /** 301 * @brief hides the rain 302 */ 303 void RainEffect::hideRain() 304 { 265 305 RainEffect::rainParticles->setColor(0, 0,0,0, 0); 266 306 RainEffect::rainParticles->setColor(0, 0,0,0, 0); 267 268 } 307 } -
branches/atmospheric_engine/src/lib/graphics/effects/rain_effect.h
r8521 r8771 1 1 /** 2 * @file rain_effect.h 2 * @file rain_effect.h 3 * Generates rain using the particle engine 3 4 */ 4 5 5 6 #ifndef _RAIN_EFFECT 6 7 #define _RAIN_EFFECT 8 9 #include "weather_effect.h" 7 10 8 11 #include "vector.h" … … 16 19 class LightManager; 17 20 18 #include "weather_effect.h"19 20 21 #include "sound_buffer.h" 21 22 #include "sound_source.h" 22 23 24 class RainEffect : public WeatherEffect 25 { 26 public: 27 RainEffect(const TiXmlElement* root = NULL); 28 virtual ~RainEffect(); 23 29 24 class RainEffect : public WeatherEffect { 25 public: 26 RainEffect(const TiXmlElement* root = NULL); 27 virtual ~RainEffect(); 30 virtual void loadParams(const TiXmlElement* root); 28 31 29 virtual void loadParams(const TiXmlElement* root);32 virtual void init(); 30 33 31 virtual void init(); 34 virtual void activate(); 35 virtual void deactivate(); 32 36 33 virtual void activate(); 34 virtual void deactivate(); 37 inline void activateRain() 38 { 39 this->activate(); 40 } 35 41 36 inline void activateRain() { 37 this->activate(); 38 } 42 inline void deactivateRain() 43 { 44 this->deactivate(); 45 } 39 46 40 inline void deactivateRain() { 41 this->deactivate(); 42 } 47 virtual void tick(float dt); 43 48 44 virtual void tick(float dt); 49 void startRaining(); 50 void stopRaining(); 45 51 46 void startRaining(); 47 void stopRaining(); 52 void hideRain(); 48 53 49 void hideRain(); 54 inline void setRainCoord(float x, float y, float z) 55 { 56 this->rainCoord = Vector(x, y, z); 57 } 58 inline void setRainSize(float x, float y) 59 { 60 this->rainSize = Vector2D(x, y); 61 } 62 inline void setRainRate(float rate) 63 { 64 this->rainRate = rate; 65 } 66 inline void setRainVelocity(float velocity) 67 { 68 this->rainVelocity = -velocity; 69 } 70 inline void setRainLife(float life) 71 { 72 this->rainLife = life; 73 } 74 inline void setRainWind(int force) 75 { 76 this->rainWindForce = force; 77 } 50 78 51 inline void setRainCoord(float x, float y, float z) { 52 this->rainCoord = Vector(x, y, z); 53 } 54 inline void setRainSize(float x, float y) { 55 this->rainSize = Vector2D(x, y); 56 } 57 inline void setRainRate(float rate) { 58 this->rainRate = rate; 59 } 60 inline void setRainVelocity(float velocity) { 61 this->rainVelocity = -velocity; 62 } 63 inline void setRainLife(float life) { 64 this->rainLife = life; 65 } 66 inline void setRainWind(int force) { 67 this->rainWindForce = force; 68 } 79 inline void setRainFadeIn(float fadein) 80 { 81 this->rainFadeInDuration = fadein; 82 } 83 inline void setRainFadeOut(float fadeout) 84 { 85 this->rainFadeOutDuration = fadeout; 86 } 69 87 70 inline void setRainFadeIn(float fadein) { 71 this->rainFadeInDuration = fadein; 72 } 73 inline void setRainFadeOut(float fadeout) { 74 this->rainFadeOutDuration = fadeout; 75 } 76 77 inline void setRainOption(const std::string& option) { 78 if (option == "moverain") 79 this->rainMove = true; 80 if (option == "activate") 81 this->rainActivate = true; 82 } 88 inline void setRainOption(const std::string& option) 89 { 90 if (option == "moverain") 91 this->rainMove = true; 92 if (option == "activate") 93 this->rainActivate = true; 94 } 83 95 84 96 85 97 private: 86 87 98 static SparkParticles* rainParticles; 99 ParticleEmitter* emitter; 88 100 89 GLfloat rainFadeInDuration; 90 GLfloat rainFadeOutDuration; 91 float localTimer; 101 float localTimer; 92 102 93 Vector rainCoord; 94 Vector2D rainSize; 95 GLfloat rainRate; 96 GLfloat rainVelocity; 97 GLfloat rainLife; 98 GLfloat rainMaxParticles; 99 int rainWindForce; 100 bool rainMove; 101 bool rainActivate; 103 GLfloat rainFadeInDuration; 104 GLfloat rainFadeOutDuration; 102 105 103 OrxSound::SoundSource soundSource; 104 OrxSound::SoundBuffer* rainBuffer; 105 OrxSound::SoundBuffer* windBuffer; 106 Vector rainCoord; 107 Vector2D rainSize; 108 GLfloat rainRate; 109 GLfloat rainVelocity; 110 GLfloat rainLife; 111 GLfloat rainMaxParticles; 112 int rainWindForce; 113 bool rainMove; 114 bool rainActivate; 106 115 107 float soundRainVolume; 116 OrxSound::SoundSource soundSource; 117 OrxSound::SoundBuffer* rainBuffer; 118 OrxSound::SoundBuffer* windBuffer; 108 119 109 LightManager* lightMan; 110 GLfloat rainAmbient; 120 float soundRainVolume; 121 122 LightManager* lightMan; 123 GLfloat rainAmbient; 111 124 112 125 }; -
branches/atmospheric_engine/src/lib/sound/sound_source.cc
r8495 r8771 164 164 165 165 /** 166 * @brief Plays back buffer on this Source with gain 167 * @param buffer the buffer to play back on this Source 166 * @brief Plays back buffer on this Source with gain 167 * @param buffer the buffer to play back on this Source 168 * @param gain the gain of the sound buffer 168 169 */ 169 170 void SoundSource::play(const SoundBuffer* buffer, float gain) … … 189 190 SoundEngine::checkError("Play Source", __LINE__); 190 191 } 191 192 192 193 /** 193 194 * @brief Plays back buffer on this Source with gain and looping possibility 194 195 * @param buffer the buffer to play back on this Source 195 */ 196 * @param gain the gain of the sound buffer 197 * @param loop if true, sound gets looped 198 */ 196 199 void SoundSource::play(const SoundBuffer* buffer, float gain, bool loop) 197 200 { … … 204 207 alSourceStop(this->sourceID); 205 208 alSourcei (this->sourceID, AL_BUFFER, buffer->getID()); 206 209 207 210 if (loop) 208 211 alSourcei (this->sourceID, AL_LOOPING, AL_TRUE); 209 212 else 210 211 213 alSourcei (this->sourceID, AL_LOOPING, AL_FALSE); 214 212 215 alSourcef (this->sourceID, AL_GAIN, gain); 213 216 … … 220 223 if (DEBUG_LEVEL >= 3) 221 224 SoundEngine::checkError("Play Source", __LINE__); 222 } 223 224 225 /** 226 * @brief Stops playback of a SoundSource 227 */ 225 } 226 227 /** 228 * @brief Changes the volume of an (active) buffer 229 * @param buffer the buffer to play back on this Source 230 * @param gain the new gain value 231 */ 232 void SoundSource::gain(const SoundBuffer* buffer, float gain) 233 { 234 // alSourcei (this->sourceID, AL_BUFFER, buffer->getID()); 235 alSourcef (this->sourceID, AL_GAIN, gain); 236 } 237 238 /** 239 * @brief Stops playback of a SoundSource 240 */ 228 241 void SoundSource::stop() 229 242 { -
branches/atmospheric_engine/src/lib/sound/sound_source.h
r8495 r8771 14 14 namespace OrxSound 15 15 { 16 class SoundBuffer; 17 //! A class that represents a SoundSource 18 class SoundSource : public BaseObject 19 { 20 public: 21 SoundSource(const PNode* sourceNode = NULL, const SoundBuffer* buffer = NULL); 22 SoundSource(const SoundSource& source); 23 SoundSource& operator=(const SoundSource& source); 24 bool operator==(const SoundSource& source); 25 26 virtual ~SoundSource(); 27 28 // user interaction 29 void play(); 30 void play(const SoundBuffer* buffer); 31 void play(const SoundBuffer* buffer, float gain); 32 void play(const SoundBuffer* buffer, float gain, bool loop); 16 class SoundBuffer; 17 //! A class that represents a SoundSource 18 class SoundSource : public BaseObject 19 { 20 public: 21 SoundSource(const PNode* sourceNode = NULL, const SoundBuffer* buffer = NULL); 22 SoundSource(const SoundSource& source); 23 SoundSource& operator=(const SoundSource& source); 24 bool operator==(const SoundSource& source); 33 25 34 void stop(); 35 void pause(); 36 void rewind(); 37 void fadein(const SoundBuffer* buffer, ALfloat duration); 38 39 40 // development functions 41 /** @returns The ID of this Source */ 42 inline ALuint getID() const { return this->sourceID; }; 43 /** @returns true, if the Source is Playing */ 44 inline bool isPlaying() const { return this->bPlay; }; 45 void setSourceNode(const PNode* sourceNode); 46 /** @returns the SoundBuffer of this Source */ 47 inline const SoundBuffer* getBuffer() const { return this->buffer; }; 48 /** @returns the SourceNode of this Source */ 49 inline const PNode* getNode() const { return this->sourceNode; }; 50 /** @param resident if the Source is Resident */ 51 inline void setResident(bool resident) { this->resident = resident; }; 52 /** @returns true if the alSource is Resident */ 53 inline bool isResident() const { return this->resident; }; 54 55 void setRolloffFactor(ALfloat rolloffFactor); 56 57 static void resetSource(ALuint sourceID); 58 59 private: 60 bool retrieveSource(); 61 62 private: 63 bool bPlay; //!< If the Source is Playing. 64 bool resident; //!< If the alSource should be resident (if true, the alSource will be returned on deletion). 65 ALuint sourceID; //!< The ID of the Source 66 const SoundBuffer* buffer; //!< The buffer to play in this source. 67 const PNode* sourceNode; //!< The SourceNode representing the position/velocity... of this source. 68 }; 26 virtual ~SoundSource(); 27 28 // user interaction 29 void play(); 30 void play(const SoundBuffer* buffer); 31 void play(const SoundBuffer* buffer, float gain); 32 void play(const SoundBuffer* buffer, float gain, bool loop); 33 34 void gain(const SoundBuffer* buffer, float gain); 35 36 void stop(); 37 void pause(); 38 void rewind(); 39 void fadein(const SoundBuffer* buffer, ALfloat duration); 40 41 // development functions 42 /** @returns The ID of this Source */ 43 inline ALuint getID() const { return this->sourceID; }; 44 /** @returns true, if the Source is Playing */ 45 inline bool isPlaying() const { return this->bPlay; }; 46 void setSourceNode(const PNode* sourceNode); 47 /** @returns the SoundBuffer of this Source */ 48 inline const SoundBuffer* getBuffer() const { return this->buffer; }; 49 /** @returns the SourceNode of this Source */ 50 inline const PNode* getNode() const { return this->sourceNode; }; 51 /** @param resident if the Source is Resident */ 52 inline void setResident(bool resident) { this->resident = resident; }; 53 /** @returns true if the alSource is Resident */ 54 inline bool isResident() const { return this->resident; }; 55 56 void setRolloffFactor(ALfloat rolloffFactor); 57 58 static void resetSource(ALuint sourceID); 59 60 private: 61 bool retrieveSource(); 62 63 private: 64 bool bPlay; //!< If the Source is Playing. 65 bool resident; //!< If the alSource should be resident (if true, the alSource will be returned on deletion). 66 ALuint sourceID; //!< The ID of the Source 67 const SoundBuffer* buffer; //!< The buffer to play in this source. 68 const PNode* sourceNode; //!< The SourceNode representing the position/velocity... of this source. 69 }; 69 70 } 70 71 #endif /* _SOUND_SOURCE_H */
Note: See TracChangeset
for help on using the changeset viewer.