Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

branches/atmospheric_engine: added loop function in sound_source

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