Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 7679 was 7652, checked in by amaechler, 19 years ago

branches/atmosphere_engine: cosmetics2

File size: 3.8 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
27#include "parser/tinyxml/tinyxml.h"
28
29//SHELL_COMMAND(activate, RainEffect, activateRain);
30//SHELL_COMMAND(deactivate, RainEffect, deactivateRain);
31
32using namespace std;
33
34CREATE_FACTORY(RainEffect, CL_RAIN_EFFECT);
35
36RainEffect::RainEffect(const TiXmlElement* root)
37{
38        this->setClassID(CL_RAIN_EFFECT, "RainEffect");
39
40        this->init();
41
42        if (root != NULL)
43                this->loadParams(root);
44
45        //load sound
46        if (this->rainBuffer != NULL)
47                ResourceManager::getInstance()->unload(this->rainBuffer);
48        this->rainBuffer = (SoundBuffer*)ResourceManager::getInstance()->load("sound/rain.wav", WAV);
49
50        this->activate();
51}
52
53RainEffect::~RainEffect()
54{
55        this->deactivate();
56}
57
58void RainEffect::loadParams(const TiXmlElement* root)
59{
60        WeatherEffect::loadParams(root);
61
62        LoadParam(root, "moverain", this, RainEffect, setMoveRain);
63        LoadParam(root, "coord", this, RainEffect, setRainCoord);
64        LoadParam(root, "size", this, RainEffect, setRainSize);
65        LoadParam(root, "rate", this, RainEffect, setRainRate);
66        LoadParam(root, "velocity", this, RainEffect, setRainVelocity);
67        LoadParam(root, "life", this, RainEffect, setRainLife);
68}
69
70
71bool RainEffect::init()
72{
73        //Default values
74        this->rainCoord = Vector(500, 500, 500);
75        this->rainSize = Vector2D(1000, 1000);
76        this->rainRate = 5000;
77        this->rainVelocity = -300;
78        this->rainLife = 2;
79
80        this->emitter = new PlaneEmitter(this->rainSize);
81}
82
83
84SparkParticles* RainEffect::rainParticles = NULL;
85
86bool RainEffect::activate()
87{
88        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" );
89
90        if (unlikely(RainEffect::rainParticles == NULL))
91        {
92                RainEffect::rainParticles = new SparkParticles(50000);
93                RainEffect::rainParticles->setName("RainParticles");
94                RainEffect::rainParticles->setLifeSpan(this->rainLife, 2);
95                RainEffect::rainParticles->setRadius(0.02, 0.02);
96                RainEffect::rainParticles->setRadius(0.01, 0.01);
97                RainEffect::rainParticles->setRadius(0.03, 0.03);
98                RainEffect::rainParticles->setRadius(0.04, 0.04);
99                RainEffect::rainParticles->setColor(0.7, 0.3, 0.3, 0.5, 0.2); // grey blue 1
100                RainEffect::rainParticles->setColor(1, 0.4, 0.4, 0.5, 0.1); // grey blue 2
101                RainEffect::rainParticles->setColor(0.5, 0.7, 0.7, 0.7, 0); // light grey
102        }
103
104        this->emitter->setSystem(RainEffect::rainParticles);
105
106        this->emitter->setRelCoor(this->rainCoord);
107
108        this->emitter->setEmissionRate(this->rainRate);
109        this->emitter->setEmissionVelocity(this->rainVelocity);
110
111        this->emitter->setSpread(0, .2);
112
113        this->soundSource.loop(this->rainBuffer);
114        PRINTF(0)( "Playing RainSound\n" );
115}
116
117
118bool RainEffect::deactivate()
119{
120        PRINTF(0)("Deactivating RainEffect\n");
121
122        this->emitter->setSystem(NULL);
123}
124
125void RainEffect::tick (float dt)
126{
127        //float distance = (State::getCameraNode()->getAbsCoor() - rainCoord).len();
128       
129        // PRINTF(0)( "RainEffect, coords: %f, %f, %f\n", this->rainCoord.x, this->rainCoord.y, this->rainCoord.z );
130
131        //if (this->rainMove) {
132                //PRINTF(0)( "Moving Rain" );
133        //      this->rainCoord = State::getCameraNode()->getAbsCoor();
134        //      this->emitter->setRelCoor(this->rainCoord.x +150, this->rainCoord.y+700, this->rainCoord.z+150);
135        //}
136}
Note: See TracBrowser for help on using the repository browser.