Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

branches/atmosphere_engine: fog weirdness…

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