Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/atmospheric_engine/src/lib/graphics/effects/rain_effect.cc @ 7978

Last change on this file since 7978 was 7978, checked in by amaechler, 18 years ago

branches/atmospheric_engine: TODO update

File size: 4.7 KB
Line 
1/*
2   orxonox - the future of 3D-vertical-scrollers
3
4   Copyright (C) 2004 orx
5
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
11### File Specific:
12   main-programmer: hdavid, amaechler
13*/
14
15#include "rain_effect.h"
16
17#include "util/loading/load_param.h"
18#include "util/loading/factory.h"
19#include "util/loading/resource_manager.h"
20
21#include "glincl.h"
22#include "p_node.h"
23#include "state.h"
24#include "spark_particles.h"
25#include "plane_emitter.h"
26#include "shell_command.h"
27
28#include "parser/tinyxml/tinyxml.h"
29
30SHELL_COMMAND(activate, RainEffect, activateRain);
31SHELL_COMMAND(deactivate, RainEffect, deactivateRain);
32
33using namespace std;
34
35CREATE_FACTORY(RainEffect, CL_RAIN_EFFECT);
36
37// TODO: Dim Light with Rain, Finish preCaching, check out if multiple rain emitters work,  Think about what happens with building poss. to hang movewithcam off, sound volume, benchmark, possible to activate lightening, turn off visibility when in a building, variable emitter size depending on playable, also rain velocity
38
39RainEffect::RainEffect(const TiXmlElement* root)
40{
41        this->setClassID(CL_RAIN_EFFECT, "RainEffect");
42
43        this->init();
44
45        if (root != NULL)
46                this->loadParams(root);
47
48        //load rain sound
49        if (this->rainBuffer != NULL)
50                ResourceManager::getInstance()->unload(this->rainBuffer);
51        this->rainBuffer = (OrxSound::SoundBuffer*)ResourceManager::getInstance()->load("sound/rain.wav", WAV);
52
53        //load wind sound
54        if (this->rainWindForce > 0) {
55                if (this->windBuffer != NULL)
56                        ResourceManager::getInstance()->unload(this->windBuffer);
57                this->windBuffer = (OrxSound::SoundBuffer*)ResourceManager::getInstance()->load("sound/wind.wav", WAV);
58        }
59
60        this->activate();
61}
62
63RainEffect::~RainEffect()
64{
65        this->deactivate();
66
67        if (this->rainBuffer != NULL)
68                ResourceManager::getInstance()->unload(this->rainBuffer);
69
70        if (this->windBuffer != NULL)
71                ResourceManager::getInstance()->unload(this->windBuffer);
72}
73
74void RainEffect::loadParams(const TiXmlElement* root)
75{
76        WeatherEffect::loadParams(root);
77
78        LoadParam(root, "coord", this, RainEffect, setRainCoord);
79        LoadParam(root, "size", this, RainEffect, setRainSize);
80        LoadParam(root, "rate", this, RainEffect, setRainRate);
81        LoadParam(root, "velocity", this, RainEffect, setRainVelocity);
82        LoadParam(root, "life", this, RainEffect, setRainLife);
83        LoadParam(root, "wind", this, RainEffect, setRainWind);
84        LoadParam(root, "option", this, RainEffect, setRainOption);
85}
86
87
88bool RainEffect::init()
89{
90        //Default values
91        this->rainCoord = Vector(500, 500, 500);
92        this->rainSize = Vector2D(1000, 1000);
93        this->rainRate = 3000;
94        this->rainVelocity = -300;
95        this->rainLife = 4;
96        this->rainMaxParticles = this->rainRate * this->rainLife;
97        this->rainWindForce  = 0;
98
99        this->emitter = new PlaneEmitter(this->rainSize);
100}
101
102
103SparkParticles* RainEffect::rainParticles = NULL;
104
105bool RainEffect::activate()
106{
107        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" );
108
109        if (unlikely(RainEffect::rainParticles == NULL))
110        {
111                RainEffect::rainParticles = new SparkParticles((int) this->rainMaxParticles);
112                RainEffect::rainParticles->setName("RainParticles");
113                RainEffect::rainParticles->precache((int)this->rainLife);
114                RainEffect::rainParticles->setLifeSpan(this->rainLife, 2);
115                RainEffect::rainParticles->setRadius(0, 0.03);
116                RainEffect::rainParticles->setRadius(0.2, 0.02);
117                RainEffect::rainParticles->setRadius(1, 0.01);
118                RainEffect::rainParticles->setColor(0, 0.3, 0.3, 0.5, 0.2); // grey blue 1
119                RainEffect::rainParticles->setColor(0.5, 0.4, 0.4, 0.5, 0.2); // grey blue 2
120                RainEffect::rainParticles->setColor(1, 0.7, 0.7, 0.7, 0.2); // light grey
121        }
122
123        this->emitter->setSystem(RainEffect::rainParticles);
124
125        this->emitter->setRelCoor(this->rainCoord);
126
127        this->emitter->setEmissionRate(this->rainRate);
128        this->emitter->setEmissionVelocity(this->rainVelocity);
129
130        this->emitter->setSpread(this->rainWindForce / 50, 0.2);
131       
132        this->soundSource.loop(this->rainBuffer);
133        if (this->rainWindForce > 0)
134                this->soundSource.loop(this->windBuffer);
135}
136
137
138bool RainEffect::deactivate()
139{
140        PRINTF(0)("Deactivating RainEffect\n");
141        this->emitter->setSystem(NULL);
142
143        this->soundSource.stop();
144}
145
146void RainEffect::activateRain()
147{
148        this->activate();
149}
150
151void RainEffect::deactivateRain()
152{
153        this->deactivate();
154}
155
156
157void RainEffect::tick (float dt)
158{
159        if (this->rainMove) {
160                this->rainCoord = State::getCameraNode()->getAbsCoor();
161                this->emitter->setRelCoor(this->rainCoord.x , this->rainCoord.y+800, this->rainCoord.z);
162        }
163}
Note: See TracBrowser for help on using the repository browser.