Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

branches/atmosphere_engine: wind, rain changes

File size: 4.2 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        LoadParam(root, "wind", this, RainEffect, setRainWind);
69
70//      LOAD_PARAM_START_CYCLE(root, element);
71//      {
72//              element->ToText();
73//              LoadParam_CYCLE(element, "option", this, RainEffect, setRainOption);
74//      }
75//      LOAD_PARAM_END_CYCLE(element);
76
77}
78
79
80bool RainEffect::init()
81{
82        //Default values
83        this->rainCoord = Vector(500, 500, 500);
84        this->rainSize = Vector2D(1000, 1000);
85        this->rainRate = 3000;
86        this->rainVelocity = -300;
87        this->rainLife = 4;
88        this->rainMaxParticles = this->rainRate * this->rainLife;
89
90        this->emitter = new PlaneEmitter(this->rainSize);
91}
92
93
94SparkParticles* RainEffect::rainParticles = NULL;
95
96bool RainEffect::activate()
97{
98        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" );
99
100        if (unlikely(RainEffect::rainParticles == NULL))
101        {
102                RainEffect::rainParticles = new SparkParticles((int) this->rainMaxParticles);
103                RainEffect::rainParticles->setName("RainParticles");
104                RainEffect::rainParticles->precache((int)this->rainLife);
105                RainEffect::rainParticles->setLifeSpan(this->rainLife, 2);
106                RainEffect::rainParticles->setRadius(0, 0.03);
107                RainEffect::rainParticles->setRadius(0.2, 0.02);
108                RainEffect::rainParticles->setRadius(1, 0.01);
109                RainEffect::rainParticles->setColor(0, 0.3, 0.3, 0.5, 0.2); // grey blue 1
110                RainEffect::rainParticles->setColor(0.5, 0.4, 0.4, 0.5, 0.2); // grey blue 2
111                RainEffect::rainParticles->setColor(1, 0.7, 0.7, 0.7, 0.2); // light grey
112        }
113
114        this->emitter->setSystem(RainEffect::rainParticles);
115
116        this->emitter->setRelCoor(this->rainCoord);
117
118        this->emitter->setEmissionRate(this->rainRate);
119        this->emitter->setEmissionVelocity(this->rainVelocity);
120
121        this->emitter->setSpread(this->rainWindForce / 5, .2);
122
123        this->soundSource.loop(this->rainBuffer);
124        PRINTF(0)( "Playing RainSound\n" );
125}
126
127
128bool RainEffect::deactivate()
129{
130        PRINTF(0)("Deactivating RainEffect\n");
131
132        this->emitter->setSystem(NULL);
133}
134
135void RainEffect::tick (float dt)
136{
137        //float distance = (State::getCameraNode()->getAbsCoor() - rainCoord).len();
138       
139        // PRINTF(0)( "RainEffect, coords: %f, %f, %f\n", this->rainCoord.x, this->rainCoord.y, this->rainCoord.z );
140
141        //if (this->rainMove) {
142                //PRINTF(0)( "Moving Rain" );
143        //      this->rainCoord = State::getCameraNode()->getAbsCoor();
144        //      this->emitter->setRelCoor(this->rainCoord.x +150, this->rainCoord.y+700, this->rainCoord.z+150);
145        //}
146}
Note: See TracBrowser for help on using the repository browser.