Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/lib/graphics/effects/snow_effect.cc @ 9822

Last change on this file since 9822 was 9406, checked in by bensch, 18 years ago

orxonox/trunk: merged the proxy back

merged with commandsvn merge -r9346:HEAD https://svn.orxonox.net/orxonox/branches/proxy .

no conflicts

File size: 7.7 KB
RevLine 
[7573]1/*
[9406]2        orxonox - the future of 3D-vertical-scrollers
[7573]3
[9406]4        Copyright (C) 2004 orx
[7573]5
[9406]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.
[7573]10
11### File Specific:
[9406]12        main-programmer: hdavid, amaechler
[7573]13*/
14
15#include "snow_effect.h"
16
17#include "util/loading/load_param.h"
18#include "util/loading/factory.h"
[7696]19#include "util/loading/resource_manager.h"
[7573]20
21#include "glincl.h"
[7576]22#include "debug.h"
[7573]23
[7650]24#include "p_node.h"
[7573]25#include "state.h"
26#include "sprite_particles.h"
27#include "plane_emitter.h"
[7649]28#include "shell_command.h"
[9112]29#include "script_class.h"
[9235]30#include "cloud_effect.h"
[7573]31
32#include "parser/tinyxml/tinyxml.h"
33
[7649]34SHELL_COMMAND(activate, SnowEffect, activateSnow);
35SHELL_COMMAND(deactivate, SnowEffect, deactivateSnow);
[7576]36
[7573]37
[9112]38CREATE_SCRIPTABLE_CLASS(SnowEffect, CL_SNOW_EFFECT,
39                            addMethod("activate", ExecutorLua0<SnowEffect>(&SnowEffect::activate))
40                            ->addMethod("deactivate", ExecutorLua0<SnowEffect>(&SnowEffect::deactivate))
41                       );
42
[7573]43CREATE_FACTORY(SnowEffect, CL_SNOW_EFFECT);
44
45SnowEffect::SnowEffect(const TiXmlElement* root)
46{
[9406]47        this->setClassID(CL_SNOW_EFFECT, "SnowEffect");
[7573]48
[9406]49        this->init();
[7651]50
[9406]51        if (root != NULL)
52                this->loadParams(root);
[7573]53
[9406]54        this->windBuffer = NULL;
55        //load wind sound
56        if (this->snowWindForce >= 1) {
57          this->windBuffer = (OrxSound::SoundBuffer*)ResourceManager::getInstance()->load("sound/atmosphere/wind.wav", WAV);
58        }
[7696]59
[8495]60  if(snowActivate) {
[9406]61                this->activate();
[8495]62    SnowEffect::snowParticles->precache((int) this->snowLife);
[8793]63  }
[7573]64}
65
66
67SnowEffect::~SnowEffect()
68{
[9406]69        this->deactivate();
[7573]70}
71
72SpriteParticles* SnowEffect::snowParticles = NULL;
73
74void SnowEffect::loadParams(const TiXmlElement* root)
75{
[9406]76        WeatherEffect::loadParams(root);
[7573]77
[9406]78        LoadParam(root, "numParticles", this, SnowEffect, numParticles);
79        LoadParam(root, "materialTexture", this, SnowEffect, materialTexture);
80        LoadParam(root, "lifeSpans", this, SnowEffect, lifeSpan);
81        LoadParam(root, "radius", this, SnowEffect, radius);
82        LoadParam(root, "mass", this, SnowEffect, mass);
83        LoadParam(root, "emissionRate", this, SnowEffect, emissionRate);
84        LoadParam(root, "emissionVelocity", this, SnowEffect, emissionVelocity);
85        LoadParam(root, "wind", this, SnowEffect, wind);
86        LoadParam(root, "size", this, SnowEffect, size);
87        LoadParam(root, "coord", this, SnowEffect, coord);
[9235]88  LoadParam(root, "cloudcolor", this, SnowEffect, setCloudColor);
89  LoadParam(root, "skycolor", this, SnowEffect, setSkyColor);
90  LoadParam(root, "fadetime", this, SnowEffect, setFadeTime);
[8316]91
[9406]92        LOAD_PARAM_START_CYCLE(root, element);
93        {
94                LoadParam_CYCLE(element, "option", this, SnowEffect, setSnowOption);
95        }
96        LOAD_PARAM_END_CYCLE(element);
[7573]97}
98
[8495]99void SnowEffect::init()
[7573]100{
[9406]101        this->emitter = new PlaneEmitter();
[7651]102
[9406]103        // Default values
104        this->snowActivate = false;
105        this->snowMove = false;
106        this->particles = 12000;
107        this->texture = "maps/snow_flake_01_32x32.png";
108        this->snowLife = 8;
109        this->randomLife = 2;
110        this->snowRadius = 3.5;
111        this->randomRadius = 1;
112        this->snowMass = 1.0;
113        this->randomMass = 0.3;
114        this->rate = 900;
115        this->velocity = -100;
116        this->randomVelocity = 5;
117        this->angle = 0.5;
118        this->randomAngle = 0.2;
119        this->alpha = 0.5;
120        this->snowSize = Vector2D(2500, 2500);
121        this->snowCoord = Vector(100,450,400);
122        this->snowWindForce = 1;
123
[9235]124  this->fadeTime = 10;
125  this->cloudColor = Vector(0.2f, 0.2f, 0.2f);
126  this->skyColor = Vector(0.0f, 0.0f, 0.0f);
[7573]127}
128
[8495]129void SnowEffect::activate()
[7573]130{
[9406]131        PRINTF(3)("Activating SnowEffect\n");
[7576]132
[9406]133        this->snowActivate = true;
[8255]134
[9406]135        SnowEffect::snowParticles = new SpriteParticles(particles);
136        SnowEffect::snowParticles->setName("SnowEffectTrailParticles");
137        SnowEffect::snowParticles->setMaterialTexture(texture);
138        SnowEffect::snowParticles->setLifeSpan(snowLife, randomLife);
139        SnowEffect::snowParticles->setRadius(0.0, snowRadius, randomRadius);
140        SnowEffect::snowParticles->setRadius(0.2, snowRadius, randomRadius*0.8);
141        SnowEffect::snowParticles->setRadius(1.0, snowRadius, randomRadius*0.5);
142        SnowEffect::snowParticles->setMass(0, snowMass, randomMass);
143        SnowEffect::snowParticles->setColor(0,1, 1, 1, alpha);
144        SnowEffect::snowParticles->setColor(.5, .6, .6, .6, alpha/2);
145        SnowEffect::snowParticles->setColor(1, .0, .0, .0, .0);
[7652]146
[9406]147        this->emitter->setSystem(SnowEffect::snowParticles);
[7652]148
[9406]149        this->emitter->setRelCoor(snowCoord);
150        this->emitter->setEmissionRate(rate);
151        this->emitter->setEmissionVelocity(velocity, randomVelocity);
152        this->emitter->setSpread(angle * this->snowWindForce , randomAngle * this->snowWindForce);
153        this->emitter->setSize(snowSize);
[7696]154
[8495]155  if (this->snowWindForce != 0)
156    this->soundSource.play(this->windBuffer, 0.1f * this->snowWindForce, true);
[9406]157
[9235]158  // Store cloud- and sky color before the snow
159  this->oldCloudColor = CloudEffect::cloudColor;
160  this->oldSkyColor   = CloudEffect::skyColor;
[8793]161
[9235]162  // Change the colors
163  CloudEffect::changeCloudColor(this->cloudColor, this->fadeTime);
164  CloudEffect::changeSkyColor(this->skyColor, this->fadeTime);
165
[7573]166}
167
168
[8495]169void SnowEffect::deactivate()
[7573]170{
[9406]171        PRINTF(3)("Deactivating SnowEffect\n");
[7652]172
[9406]173        this->snowActivate = false;
174        this->emitter->setSystem(NULL);
[7696]175
[9406]176        if (this->windBuffer != NULL)
177                ResourceManager::getInstance()->unload(this->windBuffer);
178
[9235]179  // Restore the old cloud- and sky color
180  CloudEffect::changeCloudColor(this->oldCloudColor, this->fadeTime);
181  CloudEffect::changeSkyColor(this->oldSkyColor, this->fadeTime);
[7573]182}
183
184void SnowEffect::draw() const
185{
[9406]186        if (!this->snowActivate)
187                return;
[7573]188}
189
190void SnowEffect::tick(float dt)
191{
[9406]192        if (!this->snowActivate)
193                return;
[7683]194
[9406]195        /*
196        float distance = (State::getCameraNode()->getAbsCoor() - Vector(snowCoord.x, State::getCameraNode()->getAbsCoor().y, snowCoord.z)).len();
[8316]197
[9406]198        if(activated)
199        {
200        if(distance > 0.3*snowSize.x || distance > 0.3*snowSize.y)
201                        this->deactivate();
202        else if(distance > 0.25*snowSize.x || distance > 0.25*snowSize.y)
203        this->alpha = 0.15;
204        else if(distance > 0.2*snowSize.x || distance > 0.2*snowSize.y)
205        this->alpha = 0.25;
206        else if(distance > 0.1*snowSize.x || distance > 0.1*snowSize.y)
207        this->alpha = 0.4;
[8316]208
[9406]209        SnowEffect::snowParticles->setColor(0,1, 1, 1, alpha);
210        SnowEffect::snowParticles->setColor(.5, .6, .6, .6, alpha/2);
211        SnowEffect::snowParticles->setColor(1, .0, .0, .0, .0);
212        }
213        else
214        {
215        if(distance < 0.3*snowSize.x || distance < 0.3*snowSize.y )
216        this->activate();
217        if( distance < 0.25*snowSize.x || distance < 0.25*snowSize.y )
218        this->alpha = 0.25;
219        else if( distance < 0.2*snowSize.x || distance < 0.2*snowSize.y )
220        this->alpha = 0.4;
221        else if( distance < 0.1*snowSize.x || distance < 0.1*snowSize.y )
222        this->alpha = 0.5;
[8316]223
[9406]224        SnowEffect::snowParticles->setColor(0,1, 1, 1, alpha);
225        SnowEffect::snowParticles->setColor(.5, .6, .6, .6, alpha/2);
226        SnowEffect::snowParticles->setColor(1, .0, .0, .0, .0);
227        }*/
[7683]228
[9406]229        if (this->snowMove) {
230                this->snowCoord = State::getCameraNode()->getAbsCoor();
231                this->emitter->setRelCoor(this->snowCoord.x , this->snowCoord.y+300, this->snowCoord.z);
232        }
[7573]233}
Note: See TracBrowser for help on using the repository browser.