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 | |
---|
20 | #include "glincl.h" |
---|
21 | #include "debug.h" |
---|
22 | |
---|
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 | |
---|
32 | using namespace std; |
---|
33 | |
---|
34 | CREATE_FACTORY(RainEffect, CL_RAIN_EFFECT); |
---|
35 | |
---|
36 | RainEffect::RainEffect(const TiXmlElement* root) |
---|
37 | { |
---|
38 | this->setClassID(CL_RAIN_EFFECT, "RainEffect"); |
---|
39 | |
---|
40 | if (root != NULL) |
---|
41 | this->loadParams(root); |
---|
42 | |
---|
43 | this->init(); |
---|
44 | |
---|
45 | this->activate(); |
---|
46 | } |
---|
47 | |
---|
48 | RainEffect::~RainEffect() |
---|
49 | { |
---|
50 | this->deactivate(); |
---|
51 | } |
---|
52 | |
---|
53 | void RainEffect::loadParams(const TiXmlElement* root) |
---|
54 | { |
---|
55 | WeatherEffect::loadParams(root); |
---|
56 | |
---|
57 | LoadParam(root, "coord", this, RainEffect, setRainCoord); |
---|
58 | LoadParam(root, "size", this, RainEffect, setRainSize); |
---|
59 | LoadParam(root, "rate", this, RainEffect, setRainRate); |
---|
60 | LoadParam(root, "velocity", this, RainEffect, setRainVelocity); |
---|
61 | } |
---|
62 | |
---|
63 | |
---|
64 | bool RainEffect::init() |
---|
65 | { |
---|
66 | this->emitter = new PlaneEmitter(this->rainSize); |
---|
67 | } |
---|
68 | |
---|
69 | |
---|
70 | SparkParticles* RainEffect::rainParticles = NULL; |
---|
71 | |
---|
72 | bool RainEffect::activate() |
---|
73 | { |
---|
74 | 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 ); |
---|
75 | |
---|
76 | if (unlikely(RainEffect::rainParticles == NULL)) |
---|
77 | { |
---|
78 | RainEffect::rainParticles = new SparkParticles(10000); |
---|
79 | RainEffect::rainParticles->setName("RainParticles"); |
---|
80 | RainEffect::rainParticles->setLifeSpan(2, 2); |
---|
81 | RainEffect::rainParticles->setRadius(0.05, 0.05); |
---|
82 | RainEffect::rainParticles->setRadius(0.04, 0.04); |
---|
83 | RainEffect::rainParticles->setRadius(0.03, 0.03); |
---|
84 | RainEffect::rainParticles->setColor(0, 0, 0, 1, .3); |
---|
85 | RainEffect::rainParticles->setColor(0.5, 0.5, 0.5, 1, 0.2); |
---|
86 | RainEffect::rainParticles->setColor(0.8, 0.8, 0.2, 0.3, 0.3); |
---|
87 | RainEffect::rainParticles->setColor(1, 0.5, 0.5, 1, 0); |
---|
88 | } |
---|
89 | |
---|
90 | this->emitter->setSystem(RainEffect::rainParticles); |
---|
91 | |
---|
92 | RainEffect::rainParticles->debug(); |
---|
93 | |
---|
94 | this->emitter->setRelCoor(this->rainCoord); |
---|
95 | |
---|
96 | this->emitter->setEmissionRate(this->rainRate); |
---|
97 | this->emitter->setEmissionVelocity(-this->rainVelocity); |
---|
98 | |
---|
99 | this->emitter->setSpread(0, .3); |
---|
100 | } |
---|
101 | |
---|
102 | |
---|
103 | bool RainEffect::deactivate() |
---|
104 | { |
---|
105 | PRINTF(0)("Deactivating RainEffect\n"); |
---|
106 | |
---|
107 | this->emitter->setSystem(NULL); |
---|
108 | } |
---|