Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 8471 was 8316, checked in by bensch, 18 years ago

trunk: fixed most -Wall warnings… but there are still many missing :/

File size: 5.8 KB
RevLine 
[7573]1/*
[7652]2        orxonox - the future of 3D-vertical-scrollers
[7573]3
[7652]4        Copyright (C) 2004 orx
[7573]5
[7652]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:
[7652]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"
[7573]29
30#include "parser/tinyxml/tinyxml.h"
31
[7649]32SHELL_COMMAND(activate, SnowEffect, activateSnow);
33SHELL_COMMAND(deactivate, SnowEffect, deactivateSnow);
[7576]34
[7573]35using namespace std;
36
37CREATE_FACTORY(SnowEffect, CL_SNOW_EFFECT);
38
39SnowEffect::SnowEffect(const TiXmlElement* root)
40{
[7652]41        this->setClassID(CL_SNOW_EFFECT, "SnowEffect");
[7573]42
[7652]43        this->init();
[7651]44
[7652]45        if (root != NULL)
46                this->loadParams(root);
[7573]47
[7696]48        //load wind sound
49        if (this->snowWindForce > 1) {
50                if (this->windBuffer != NULL)
51                        ResourceManager::getInstance()->unload(this->windBuffer);
[7810]52                        this->windBuffer = (OrxSound::SoundBuffer*)ResourceManager::getInstance()->load("sound/wind.wav", WAV);
[7696]53        }
54
[8255]55        if(snowActivate)
56                this->activate();
[7573]57}
58
59
60SnowEffect::~SnowEffect()
61{
[7652]62        this->deactivate();
[7573]63}
64
65SpriteParticles* SnowEffect::snowParticles = NULL;
66
67void SnowEffect::loadParams(const TiXmlElement* root)
68{
[7652]69        WeatherEffect::loadParams(root);
[7573]70
[7652]71        LoadParam(root, "numParticles", this, SnowEffect, numParticles);
72        LoadParam(root, "materialTexture", this, SnowEffect, materialTexture);
73        LoadParam(root, "lifeSpans", this, SnowEffect, lifeSpan);
74        LoadParam(root, "radius", this, SnowEffect, radius);
75        LoadParam(root, "mass", this, SnowEffect, mass);
76        LoadParam(root, "emissionRate", this, SnowEffect, emissionRate);
77        LoadParam(root, "emissionVelocity", this, SnowEffect, emissionVelocity);
[8255]78        LoadParam(root, "wind", this, SnowEffect, wind);
[7652]79        LoadParam(root, "size", this, SnowEffect, size);
80        LoadParam(root, "coord", this, SnowEffect, coord);
[8316]81
[8255]82        LOAD_PARAM_START_CYCLE(root, element);
83        {
84                LoadParam_CYCLE(element, "option", this, SnowEffect, setSnowOption);
85        }
86        LOAD_PARAM_END_CYCLE(element);
[7573]87}
88
89bool SnowEffect::init()
90{
[7652]91        this->emitter = new PlaneEmitter();
[7651]92
[7652]93        // Default values
[8255]94        this->snowActivate = false;
95        this->snowMove = false;
[7696]96        this->particles = 12000;
97        this->texture = "maps/snow_flake_01_32x32.png";
98        this->life = 8;
99        this->randomLife = 2;
100        this->snowRadius = 3.5;
101        this->randomRadius = 1;
102        this->snowMass = 1.0;
103        this->randomMass = 0.3;
104        this->rate = 900;
105        this->velocity = -100;
106        this->randomVelocity = 5;
107        this->angle = 0.5;
108        this->randomAngle = 0.2;
109        this->alpha = 0.5;
110        this->snowSize = Vector2D(2500, 2500);
[8255]111        this->snowCoord = Vector(100,450,400);
[7696]112        this->snowWindForce = 1;
[8316]113
114        return true;
[7573]115}
116
117bool SnowEffect::activate()
118{
[7652]119        PRINTF(0)("Activating SnowEffect\n");
[7576]120
[8255]121        this->snowActivate = true;
122
[7652]123        SnowEffect::snowParticles = new SpriteParticles(particles);
124        SnowEffect::snowParticles->setName("SnowEffectTrailParticles");
125        SnowEffect::snowParticles->setMaterialTexture(texture);
126        SnowEffect::snowParticles->setLifeSpan(life, randomLife);
127        SnowEffect::snowParticles->setRadius(0.0, snowRadius, randomRadius);
[7683]128        SnowEffect::snowParticles->setRadius(0.2, snowRadius, randomRadius*0.8);
129        SnowEffect::snowParticles->setRadius(1.0, snowRadius, randomRadius*0.5);
[7652]130        SnowEffect::snowParticles->setMass(0, snowMass, randomMass);
131        SnowEffect::snowParticles->setColor(0,1, 1, 1, alpha);
132        SnowEffect::snowParticles->setColor(.5, .6, .6, .6, alpha/2);
133        SnowEffect::snowParticles->setColor(1, .0, .0, .0, .0);
134
135        this->emitter->setSystem(SnowEffect::snowParticles);
136
137        this->emitter->setRelCoor(snowCoord);
138        this->emitter->setEmissionRate(rate);
139        this->emitter->setEmissionVelocity(velocity, randomVelocity);
[7696]140        this->emitter->setSpread(angle * this->snowWindForce , randomAngle * this->snowWindForce);
[7652]141        this->emitter->setSize(snowSize);
[7696]142
[8255]143        // SnowEffect::snowParticles->precache(8);
[7696]144
145        if (this->snowWindForce > 1)
146                this->soundSource.loop(this->windBuffer);
[8316]147
148        return true;
[7573]149}
150
151
152bool SnowEffect::deactivate()
153{
[7652]154        PRINTF(0)("Deactivating SnowEffect\n");
155
[8255]156        this->snowActivate = false;
[7652]157        this->emitter->setSystem(NULL);
[7696]158
159        if (this->windBuffer != NULL)
160                ResourceManager::getInstance()->unload(this->windBuffer);
161
[8316]162        return true;
[7573]163}
164
165void SnowEffect::draw() const
166{
[8255]167        if (!this->snowActivate)
168                return;
[7573]169}
170
171void SnowEffect::tick(float dt)
172{
[8255]173        if (!this->snowActivate)
174                return;
[7683]175
[8255]176        /*
177        float distance = (State::getCameraNode()->getAbsCoor() - Vector(snowCoord.x, State::getCameraNode()->getAbsCoor().y, snowCoord.z)).len();
[8316]178
[8255]179        if(activated)
180        {
181        if(distance > 0.3*snowSize.x || distance > 0.3*snowSize.y)
182                        this->deactivate();
183        else if(distance > 0.25*snowSize.x || distance > 0.25*snowSize.y)
184        this->alpha = 0.15;
185        else if(distance > 0.2*snowSize.x || distance > 0.2*snowSize.y)
186        this->alpha = 0.25;
187        else if(distance > 0.1*snowSize.x || distance > 0.1*snowSize.y)
188        this->alpha = 0.4;
[8316]189
[8255]190        SnowEffect::snowParticles->setColor(0,1, 1, 1, alpha);
191        SnowEffect::snowParticles->setColor(.5, .6, .6, .6, alpha/2);
192        SnowEffect::snowParticles->setColor(1, .0, .0, .0, .0);
193        }
194        else
195        {
196        if(distance < 0.3*snowSize.x || distance < 0.3*snowSize.y )
197        this->activate();
198        if( distance < 0.25*snowSize.x || distance < 0.25*snowSize.y )
199        this->alpha = 0.25;
200        else if( distance < 0.2*snowSize.x || distance < 0.2*snowSize.y )
201        this->alpha = 0.4;
202        else if( distance < 0.1*snowSize.x || distance < 0.1*snowSize.y )
203        this->alpha = 0.5;
[8316]204
[8255]205        SnowEffect::snowParticles->setColor(0,1, 1, 1, alpha);
206        SnowEffect::snowParticles->setColor(.5, .6, .6, .6, alpha/2);
207        SnowEffect::snowParticles->setColor(1, .0, .0, .0, .0);
208        }*/
[7683]209
[8255]210        if (this->snowMove) {
211                this->snowCoord = State::getCameraNode()->getAbsCoor();
212                this->emitter->setRelCoor(this->snowCoord.x , this->snowCoord.y+300, this->snowCoord.z);
213        }
[7573]214}
Note: See TracBrowser for help on using the repository browser.