Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

branches/atmosphere_engine: fog

File size: 3.8 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"
[7562]26
27#include "parser/tinyxml/tinyxml.h"
28
[7628]29//SHELL_COMMAND(activate, RainEffect, activateRain);
30//SHELL_COMMAND(deactivate, RainEffect, deactivateRain);
[7577]31
[7561]32using namespace std;
33
34CREATE_FACTORY(RainEffect, CL_RAIN_EFFECT);
35
36RainEffect::RainEffect(const TiXmlElement* root)
37{
[7652]38        this->setClassID(CL_RAIN_EFFECT, "RainEffect");
[7561]39
[7652]40        this->init();
[7561]41
[7652]42        if (root != NULL)
43                this->loadParams(root);
[7646]44
[7652]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);
[7646]49
[7652]50        this->activate();
[7561]51}
52
53RainEffect::~RainEffect()
54{
[7652]55        this->deactivate();
[7561]56}
57
58void RainEffect::loadParams(const TiXmlElement* root)
59{
[7628]60        WeatherEffect::loadParams(root);
[7561]61
[7682]62        // LoadParam(root, "moverain", this, RainEffect, setMoveRain);
[7628]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);
[7652]67        LoadParam(root, "life", this, RainEffect, setRainLife);
[7682]68        LoadParam(root, "wind", this, RainEffect, setRainWind);
[7685]69        LoadParam(root, "option", this, RainEffect, setRainOption);
[7628]70}
[7561]71
72
[7628]73bool RainEffect::init()
74{
[7652]75        //Default values
76        this->rainCoord = Vector(500, 500, 500);
77        this->rainSize = Vector2D(1000, 1000);
[7682]78        this->rainRate = 3000;
[7652]79        this->rainVelocity = -300;
[7682]80        this->rainLife = 4;
81        this->rainMaxParticles = this->rainRate * this->rainLife;
[7685]82        this->rainWindForce  = 0;
[7646]83
[7652]84        this->emitter = new PlaneEmitter(this->rainSize);
[7561]85}
86
87
[7577]88SparkParticles* RainEffect::rainParticles = NULL;
[7561]89
90bool RainEffect::activate()
91{
[7652]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" );
[7577]93
94        if (unlikely(RainEffect::rainParticles == NULL))
95        {
[7682]96                RainEffect::rainParticles = new SparkParticles((int) this->rainMaxParticles);
[7577]97                RainEffect::rainParticles->setName("RainParticles");
[7682]98                RainEffect::rainParticles->precache((int)this->rainLife);
[7652]99                RainEffect::rainParticles->setLifeSpan(this->rainLife, 2);
[7682]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
[7577]106        }
107
108        this->emitter->setSystem(RainEffect::rainParticles);
109
[7628]110        this->emitter->setRelCoor(this->rainCoord);
[7577]111
[7628]112        this->emitter->setEmissionRate(this->rainRate);
[7646]113        this->emitter->setEmissionVelocity(this->rainVelocity);
[7628]114
[7685]115        this->emitter->setSpread(this->rainWindForce / 50, 0.2);
[7646]116
117        this->soundSource.loop(this->rainBuffer);
118        PRINTF(0)( "Playing RainSound\n" );
[7561]119}
120
121
122bool RainEffect::deactivate()
123{
[7652]124        PRINTF(0)("Deactivating RainEffect\n");
[7577]125
[7652]126        this->emitter->setSystem(NULL);
[7561]127}
[7646]128
129void RainEffect::tick (float dt)
130{
[7685]131        if (this->rainMove) {
132                this->rainCoord = State::getCameraNode()->getAbsCoor();
[7691]133                this->emitter->setRelCoor(this->rainCoord.x , this->rainCoord.y+800, this->rainCoord.z);
[7685]134        }
[7646]135}
Note: See TracBrowser for help on using the repository browser.