Changeset 7652 in orxonox.OLD for branches/atmospheric_engine/src/lib/graphics/effects/snow_effect.cc
- Timestamp:
- May 17, 2006, 6:41:58 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/atmospheric_engine/src/lib/graphics/effects/snow_effect.cc
r7651 r7652 1 1 /* 2 2 orxonox - the future of 3D-vertical-scrollers 3 3 4 4 Copyright (C) 2004 orx 5 5 6 7 8 9 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 … … 38 38 SnowEffect::SnowEffect(const TiXmlElement* root) 39 39 { 40 40 this->setClassID(CL_SNOW_EFFECT, "SnowEffect"); 41 41 42 42 this->init(); 43 43 44 45 44 if (root != NULL) 45 this->loadParams(root); 46 46 47 47 this->activate(); 48 48 } 49 49 … … 51 51 SnowEffect::~SnowEffect() 52 52 { 53 53 this->deactivate(); 54 54 } 55 55 … … 58 58 void SnowEffect::loadParams(const TiXmlElement* root) 59 59 { 60 60 WeatherEffect::loadParams(root); 61 61 62 63 64 65 66 67 68 69 70 71 62 LoadParam(root, "numParticles", this, SnowEffect, numParticles); 63 LoadParam(root, "materialTexture", this, SnowEffect, materialTexture); 64 LoadParam(root, "lifeSpans", this, SnowEffect, lifeSpan); 65 LoadParam(root, "radius", this, SnowEffect, radius); 66 LoadParam(root, "mass", this, SnowEffect, mass); 67 LoadParam(root, "emissionRate", this, SnowEffect, emissionRate); 68 LoadParam(root, "emissionVelocity", this, SnowEffect, emissionVelocity); 69 LoadParam(root, "spread", this, SnowEffect, spread); 70 LoadParam(root, "size", this, SnowEffect, size); 71 LoadParam(root, "coord", this, SnowEffect, coord); 72 72 } 73 73 74 74 bool SnowEffect::init() 75 75 { 76 76 this->emitter = new PlaneEmitter(); 77 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 78 // Default values 79 particles = 10000; 80 texture = "maps/snow_flake_01_32x32.png"; 81 life = 8; 82 randomLife = 2; 83 snowRadius = 3.5; 84 randomRadius = 1; 85 snowMass = 1.0; 86 randomMass = 0.3; 87 rate = 900; 88 velocity = -100; 89 randomVelocity = 5; 90 angle = 0; 91 randomAngle = 0.3; 92 alpha = 0.5; 93 snowSize = Vector2D(1200, 1200); 94 snowCoord = Vector(100, 600, 200); 95 95 96 96 activated = false; 97 97 } 98 98 99 99 bool SnowEffect::activate() 100 100 { 101 PRINTF(0)("Activating SnowEffect\n"); 102 activated = true; 103 104 SnowEffect::snowParticles = new SpriteParticles(particles); 105 SnowEffect::snowParticles->setName("SnowEffectTrailParticles"); 106 SnowEffect::snowParticles->setMaterialTexture(texture); 107 SnowEffect::snowParticles->setLifeSpan(life, randomLife); 108 SnowEffect::snowParticles->setRadius(0.0, snowRadius, randomRadius); 109 SnowEffect::snowParticles->setRadius(0.2, snowRadius, randomRadius); 110 SnowEffect::snowParticles->setRadius(1.0, snowRadius, randomRadius); 111 SnowEffect::snowParticles->setMass(0, snowMass, randomMass); 112 SnowEffect::snowParticles->setColor(0,1, 1, 1, alpha); 113 SnowEffect::snowParticles->setColor(.5, .6, .6, .6, alpha/2); 114 SnowEffect::snowParticles->setColor(1, .0, .0, .0, .0); 101 PRINTF(0)("Activating SnowEffect\n"); 102 activated = true; 115 103 116 117 this->emitter->setSystem(SnowEffect::snowParticles); 118 119 // this->updateNode(0); 120 this->emitter->setRelCoor(snowCoord); 121 this->emitter->setEmissionRate(rate); 122 this->emitter->setEmissionVelocity(velocity, randomVelocity); 123 this->emitter->setSpread(angle, randomAngle); 124 this->emitter->setSize(snowSize); 104 SnowEffect::snowParticles = new SpriteParticles(particles); 105 SnowEffect::snowParticles->setName("SnowEffectTrailParticles"); 106 SnowEffect::snowParticles->setMaterialTexture(texture); 107 SnowEffect::snowParticles->setLifeSpan(life, randomLife); 108 SnowEffect::snowParticles->setRadius(0.0, snowRadius, randomRadius); 109 SnowEffect::snowParticles->setRadius(0.2, snowRadius, randomRadius); 110 SnowEffect::snowParticles->setRadius(1.0, snowRadius, randomRadius); 111 SnowEffect::snowParticles->setMass(0, snowMass, randomMass); 112 SnowEffect::snowParticles->setColor(0,1, 1, 1, alpha); 113 SnowEffect::snowParticles->setColor(.5, .6, .6, .6, alpha/2); 114 SnowEffect::snowParticles->setColor(1, .0, .0, .0, .0); 115 116 this->emitter->setSystem(SnowEffect::snowParticles); 117 118 // this->updateNode(0); 119 this->emitter->setRelCoor(snowCoord); 120 this->emitter->setEmissionRate(rate); 121 this->emitter->setEmissionVelocity(velocity, randomVelocity); 122 this->emitter->setSpread(angle, randomAngle); 123 this->emitter->setSize(snowSize); 125 124 } 126 125 … … 128 127 bool SnowEffect::deactivate() 129 128 { 130 131 132 133 129 PRINTF(0)("Deactivating SnowEffect\n"); 130 activated = false; 131 132 this->emitter->setSystem(NULL); 134 133 } 135 134 136 135 void SnowEffect::activateSnow() 137 136 { 138 137 this->activate(); 139 138 } 140 139 141 140 void SnowEffect::deactivateSnow() 142 141 { 143 142 this->deactivate(); 144 143 } 145 144 … … 150 149 void SnowEffect::tick(float dt) 151 150 { 152 153 154 155 156 151 float distance = (State::getCameraNode()->getAbsCoor() - snowCoord).len(); 152 if( activated && ( distance > 0.6*snowSize.x || distance > 0.6*snowSize.y) ) 153 this->deactivate(); 154 if( !activated && ( distance < 0.6*snowSize.x || distance < 0.6*snowSize.y )) 155 this->activate(); 157 156 } 158 157
Note: See TracChangeset
for help on using the changeset viewer.