Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/lib/graphics/effects/rain_effect.cc @ 7951

Last change on this file since 7951 was 7810, checked in by bensch, 18 years ago

orxonox/trunk: merged the Weather effects back here

File size: 4.4 KB
RevLine 
[7561]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"
[7646]19#include "util/loading/resource_manager.h"
[7561]20
21#include "glincl.h"
[7652]22#include "p_node.h"
[7562]23#include "state.h"
[7628]24#include "spark_particles.h"
25#include "plane_emitter.h"
[7696]26#include "shell_command.h"
[7562]27
28#include "parser/tinyxml/tinyxml.h"
29
[7696]30SHELL_COMMAND(activate, RainEffect, activateRain);
31SHELL_COMMAND(deactivate, RainEffect, deactivateRain);
[7577]32
[7561]33using namespace std;
34
35CREATE_FACTORY(RainEffect, CL_RAIN_EFFECT);
36
37RainEffect::RainEffect(const TiXmlElement* root)
38{
[7652]39        this->setClassID(CL_RAIN_EFFECT, "RainEffect");
[7561]40
[7652]41        this->init();
[7561]42
[7652]43        if (root != NULL)
44                this->loadParams(root);
[7646]45
[7696]46        //load rain sound
[7652]47        if (this->rainBuffer != NULL)
48                ResourceManager::getInstance()->unload(this->rainBuffer);
[7810]49        this->rainBuffer = (OrxSound::SoundBuffer*)ResourceManager::getInstance()->load("sound/rain.wav", WAV);
[7646]50
[7696]51        //load wind sound
52        if (this->rainWindForce > 0) {
53                if (this->windBuffer != NULL)
54                        ResourceManager::getInstance()->unload(this->windBuffer);
[7810]55                this->windBuffer = (OrxSound::SoundBuffer*)ResourceManager::getInstance()->load("sound/wind.wav", WAV);
[7696]56        }
57
[7652]58        this->activate();
[7561]59}
60
61RainEffect::~RainEffect()
62{
[7652]63        this->deactivate();
[7696]64
65        if (this->rainBuffer != NULL)
66                ResourceManager::getInstance()->unload(this->rainBuffer);
67
68        if (this->windBuffer != NULL)
69                ResourceManager::getInstance()->unload(this->windBuffer);
[7561]70}
71
72void RainEffect::loadParams(const TiXmlElement* root)
73{
[7628]74        WeatherEffect::loadParams(root);
[7561]75
[7628]76        LoadParam(root, "coord", this, RainEffect, setRainCoord);
77        LoadParam(root, "size", this, RainEffect, setRainSize);
78        LoadParam(root, "rate", this, RainEffect, setRainRate);
79        LoadParam(root, "velocity", this, RainEffect, setRainVelocity);
[7652]80        LoadParam(root, "life", this, RainEffect, setRainLife);
[7682]81        LoadParam(root, "wind", this, RainEffect, setRainWind);
[7685]82        LoadParam(root, "option", this, RainEffect, setRainOption);
[7628]83}
[7561]84
85
[7628]86bool RainEffect::init()
87{
[7652]88        //Default values
89        this->rainCoord = Vector(500, 500, 500);
90        this->rainSize = Vector2D(1000, 1000);
[7682]91        this->rainRate = 3000;
[7652]92        this->rainVelocity = -300;
[7682]93        this->rainLife = 4;
94        this->rainMaxParticles = this->rainRate * this->rainLife;
[7685]95        this->rainWindForce  = 0;
[7646]96
[7652]97        this->emitter = new PlaneEmitter(this->rainSize);
[7561]98}
99
100
[7577]101SparkParticles* RainEffect::rainParticles = NULL;
[7561]102
103bool RainEffect::activate()
104{
[7652]105        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" );
[7577]106
107        if (unlikely(RainEffect::rainParticles == NULL))
108        {
[7682]109                RainEffect::rainParticles = new SparkParticles((int) this->rainMaxParticles);
[7577]110                RainEffect::rainParticles->setName("RainParticles");
[7682]111                RainEffect::rainParticles->precache((int)this->rainLife);
[7652]112                RainEffect::rainParticles->setLifeSpan(this->rainLife, 2);
[7682]113                RainEffect::rainParticles->setRadius(0, 0.03);
114                RainEffect::rainParticles->setRadius(0.2, 0.02);
115                RainEffect::rainParticles->setRadius(1, 0.01);
116                RainEffect::rainParticles->setColor(0, 0.3, 0.3, 0.5, 0.2); // grey blue 1
117                RainEffect::rainParticles->setColor(0.5, 0.4, 0.4, 0.5, 0.2); // grey blue 2
118                RainEffect::rainParticles->setColor(1, 0.7, 0.7, 0.7, 0.2); // light grey
[7577]119        }
120
121        this->emitter->setSystem(RainEffect::rainParticles);
122
[7628]123        this->emitter->setRelCoor(this->rainCoord);
[7577]124
[7628]125        this->emitter->setEmissionRate(this->rainRate);
[7646]126        this->emitter->setEmissionVelocity(this->rainVelocity);
[7628]127
[7685]128        this->emitter->setSpread(this->rainWindForce / 50, 0.2);
[7696]129       
[7646]130        this->soundSource.loop(this->rainBuffer);
[7696]131        if (this->rainWindForce > 0)
132                this->soundSource.loop(this->windBuffer);
[7561]133}
134
135
136bool RainEffect::deactivate()
137{
[7652]138        PRINTF(0)("Deactivating RainEffect\n");
[7696]139        this->emitter->setSystem(NULL);
[7577]140
[7696]141        this->soundSource.stop();
[7561]142}
[7646]143
[7696]144void RainEffect::activateRain()
145{
146        this->activate();
147}
148
149void RainEffect::deactivateRain()
150{
151        this->deactivate();
152}
153
154
[7646]155void RainEffect::tick (float dt)
156{
[7685]157        if (this->rainMove) {
158                this->rainCoord = State::getCameraNode()->getAbsCoor();
[7691]159                this->emitter->setRelCoor(this->rainCoord.x , this->rainCoord.y+800, this->rainCoord.z);
[7685]160        }
[7646]161}
Note: See TracBrowser for help on using the repository browser.