Changeset 9805 in orxonox.OLD for branches/new_class_id/src/world_entities/weather_effects/snow_effect.cc
- Timestamp:
- Sep 24, 2006, 3:21:12 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/new_class_id/src/world_entities/weather_effects/snow_effect.cc
r9760 r9805 17 17 #include "util/loading/load_param.h" 18 18 #include "util/loading/factory.h" 19 #include " util/loading/resource_manager.h"19 #include "sound/resource_sound_buffer.h" 20 20 21 21 #include "glincl.h" … … 38 38 39 39 CREATE_SCRIPTABLE_CLASS(SnowEffect, 40 41 40 addMethod("activate", Executor0<SnowEffect, lua_State*>(&SnowEffect::activate)) 41 ->addMethod("deactivate", Executor0<SnowEffect, lua_State*>(&SnowEffect::deactivate)) 42 42 ); 43 43 … … 48 48 this->registerObject(this, SnowEffect::_objectList); 49 49 50 this->init(); 51 52 if (root != NULL) 53 this->loadParams(root); 54 55 this->windBuffer = NULL; 56 //load wind sound 57 if (this->snowWindForce >= 1) { 58 this->windBuffer = (OrxSound::SoundBuffer*)ResourceManager::getInstance()->load("sound/atmosphere/wind.wav", WAV); 59 } 60 61 if(snowActivate) { 62 this->activate(); 50 this->init(); 51 52 if (root != NULL) 53 this->loadParams(root); 54 55 //load wind sound 56 if (this->snowWindForce >= 1) 57 { 58 this->windBuffer = OrxSound::ResourceSoundBuffer("sound/atmosphere/wind.wav"); 59 } 60 61 if(snowActivate) 62 { 63 this->activate(); 63 64 SnowEffect::snowParticles->precache((int) this->snowLife); 64 65 } … … 68 69 SnowEffect::~SnowEffect() 69 70 { 70 71 this->deactivate(); 71 72 } 72 73 … … 75 76 void SnowEffect::loadParams(const TiXmlElement* root) 76 77 { 77 78 79 80 81 82 83 84 85 86 87 88 78 WeatherEffect::loadParams(root); 79 80 LoadParam(root, "numParticles", this, SnowEffect, numParticles); 81 LoadParam(root, "materialTexture", this, SnowEffect, materialTexture); 82 LoadParam(root, "lifeSpans", this, SnowEffect, lifeSpan); 83 LoadParam(root, "radius", this, SnowEffect, radius); 84 LoadParam(root, "mass", this, SnowEffect, mass); 85 LoadParam(root, "emissionRate", this, SnowEffect, emissionRate); 86 LoadParam(root, "emissionVelocity", this, SnowEffect, emissionVelocity); 87 LoadParam(root, "wind", this, SnowEffect, wind); 88 LoadParam(root, "size", this, SnowEffect, size); 89 LoadParam(root, "coord", this, SnowEffect, coord); 89 90 LoadParam(root, "cloudcolor", this, SnowEffect, setCloudColor); 90 91 LoadParam(root, "skycolor", this, SnowEffect, setSkyColor); 91 92 LoadParam(root, "fadetime", this, SnowEffect, setFadeTime); 92 93 93 94 95 96 97 94 LOAD_PARAM_START_CYCLE(root, element); 95 { 96 LoadParam_CYCLE(element, "option", this, SnowEffect, setSnowOption); 97 } 98 LOAD_PARAM_END_CYCLE(element); 98 99 } 99 100 100 101 void SnowEffect::init() 101 102 { 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 103 this->emitter = new PlaneEmitter(); 104 105 // Default values 106 this->snowActivate = false; 107 this->snowMove = false; 108 this->particles = 12000; 109 this->texture = "maps/snow_flake_01_32x32.png"; 110 this->snowLife = 8; 111 this->randomLife = 2; 112 this->snowRadius = 3.5; 113 this->randomRadius = 1; 114 this->snowMass = 1.0; 115 this->randomMass = 0.3; 116 this->rate = 900; 117 this->velocity = -100; 118 this->randomVelocity = 5; 119 this->angle = 0.5; 120 this->randomAngle = 0.2; 121 this->alpha = 0.5; 122 this->snowSize = Vector2D(2500, 2500); 123 this->snowCoord = Vector(100,450,400); 124 this->snowWindForce = 1; 124 125 125 126 this->fadeTime = 10; … … 130 131 void SnowEffect::activate() 131 132 { 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 133 PRINTF(3)("Activating SnowEffect\n"); 134 135 this->snowActivate = true; 136 137 SnowEffect::snowParticles = new SpriteParticles(particles); 138 SnowEffect::snowParticles->setName("SnowEffectTrailParticles"); 139 SnowEffect::snowParticles->setMaterialTexture(texture); 140 SnowEffect::snowParticles->setLifeSpan(snowLife, randomLife); 141 SnowEffect::snowParticles->setRadius(0.0, snowRadius, randomRadius); 142 SnowEffect::snowParticles->setRadius(0.2, snowRadius, randomRadius*0.8); 143 SnowEffect::snowParticles->setRadius(1.0, snowRadius, randomRadius*0.5); 144 SnowEffect::snowParticles->setMass(0, snowMass, randomMass); 145 SnowEffect::snowParticles->setColor(0,1, 1, 1, alpha); 146 SnowEffect::snowParticles->setColor(.5, .6, .6, .6, alpha/2); 147 SnowEffect::snowParticles->setColor(1, .0, .0, .0, .0); 148 149 this->emitter->setSystem(SnowEffect::snowParticles); 150 151 this->emitter->setRelCoor(snowCoord); 152 this->emitter->setEmissionRate(rate); 153 this->emitter->setEmissionVelocity(velocity, randomVelocity); 154 this->emitter->setSpread(angle * this->snowWindForce , randomAngle * this->snowWindForce); 155 this->emitter->setSize(snowSize); 155 156 156 157 if (this->snowWindForce != 0) … … 170 171 void SnowEffect::deactivate() 171 172 { 172 PRINTF(3)("Deactivating SnowEffect\n"); 173 174 this->snowActivate = false; 175 this->emitter->setSystem(NULL); 176 177 if (this->windBuffer != NULL) 178 ResourceManager::getInstance()->unload(this->windBuffer); 173 PRINTF(3)("Deactivating SnowEffect\n"); 174 175 this->snowActivate = false; 176 this->emitter->setSystem(NULL); 179 177 180 178 // Restore the old cloud- and sky color … … 185 183 void SnowEffect::draw() const 186 184 { 187 188 185 if (!this->snowActivate) 186 return; 189 187 } 190 188 191 189 void SnowEffect::tick(float dt) 192 190 { 193 if (!this->snowActivate) 194 return; 195 196 /* 197 float distance = (State::getCameraNode()->getAbsCoor() - Vector(snowCoord.x, State::getCameraNode()->getAbsCoor().y, snowCoord.z)).len(); 198 199 if(activated) 200 { 201 if(distance > 0.3*snowSize.x || distance > 0.3*snowSize.y) 202 this->deactivate(); 203 else if(distance > 0.25*snowSize.x || distance > 0.25*snowSize.y) 204 this->alpha = 0.15; 205 else if(distance > 0.2*snowSize.x || distance > 0.2*snowSize.y) 206 this->alpha = 0.25; 207 else if(distance > 0.1*snowSize.x || distance > 0.1*snowSize.y) 208 this->alpha = 0.4; 209 210 SnowEffect::snowParticles->setColor(0,1, 1, 1, alpha); 211 SnowEffect::snowParticles->setColor(.5, .6, .6, .6, alpha/2); 212 SnowEffect::snowParticles->setColor(1, .0, .0, .0, .0); 213 } 214 else 215 { 216 if(distance < 0.3*snowSize.x || distance < 0.3*snowSize.y ) 217 this->activate(); 218 if( distance < 0.25*snowSize.x || distance < 0.25*snowSize.y ) 219 this->alpha = 0.25; 220 else if( distance < 0.2*snowSize.x || distance < 0.2*snowSize.y ) 221 this->alpha = 0.4; 222 else if( distance < 0.1*snowSize.x || distance < 0.1*snowSize.y ) 223 this->alpha = 0.5; 224 225 SnowEffect::snowParticles->setColor(0,1, 1, 1, alpha); 226 SnowEffect::snowParticles->setColor(.5, .6, .6, .6, alpha/2); 227 SnowEffect::snowParticles->setColor(1, .0, .0, .0, .0); 228 }*/ 229 230 if (this->snowMove) { 231 this->snowCoord = State::getCameraNode()->getAbsCoor(); 232 this->emitter->setRelCoor(this->snowCoord.x , this->snowCoord.y+300, this->snowCoord.z); 233 } 234 } 191 if (!this->snowActivate) 192 return; 193 194 /* 195 float distance = (State::getCameraNode()->getAbsCoor() - Vector(snowCoord.x, State::getCameraNode()->getAbsCoor().y, snowCoord.z)).len(); 196 197 if(activated) 198 { 199 if(distance > 0.3*snowSize.x || distance > 0.3*snowSize.y) 200 this->deactivate(); 201 else if(distance > 0.25*snowSize.x || distance > 0.25*snowSize.y) 202 this->alpha = 0.15; 203 else if(distance > 0.2*snowSize.x || distance > 0.2*snowSize.y) 204 this->alpha = 0.25; 205 else if(distance > 0.1*snowSize.x || distance > 0.1*snowSize.y) 206 this->alpha = 0.4; 207 208 SnowEffect::snowParticles->setColor(0,1, 1, 1, alpha); 209 SnowEffect::snowParticles->setColor(.5, .6, .6, .6, alpha/2); 210 SnowEffect::snowParticles->setColor(1, .0, .0, .0, .0); 211 } 212 else 213 { 214 if(distance < 0.3*snowSize.x || distance < 0.3*snowSize.y ) 215 this->activate(); 216 if( distance < 0.25*snowSize.x || distance < 0.25*snowSize.y ) 217 this->alpha = 0.25; 218 else if( distance < 0.2*snowSize.x || distance < 0.2*snowSize.y ) 219 this->alpha = 0.4; 220 else if( distance < 0.1*snowSize.x || distance < 0.1*snowSize.y ) 221 this->alpha = 0.5; 222 223 SnowEffect::snowParticles->setColor(0,1, 1, 1, alpha); 224 SnowEffect::snowParticles->setColor(.5, .6, .6, .6, alpha/2); 225 SnowEffect::snowParticles->setColor(1, .0, .0, .0, .0); 226 }*/ 227 228 if (this->snowMove) 229 { 230 this->snowCoord = State::getCameraNode()->getAbsCoor(); 231 this->emitter->setRelCoor(this->snowCoord.x , this->snowCoord.y+300, this->snowCoord.z); 232 } 233 }
Note: See TracChangeset
for help on using the changeset viewer.