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 "snow_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 "p_node.h" |
---|
24 | #include "state.h" |
---|
25 | #include "sprite_particles.h" |
---|
26 | #include "plane_emitter.h" |
---|
27 | #include "shell_command.h" |
---|
28 | |
---|
29 | #include "parser/tinyxml/tinyxml.h" |
---|
30 | |
---|
31 | SHELL_COMMAND(activate, SnowEffect, activateSnow); |
---|
32 | SHELL_COMMAND(deactivate, SnowEffect, deactivateSnow); |
---|
33 | |
---|
34 | using namespace std; |
---|
35 | |
---|
36 | CREATE_FACTORY(SnowEffect, CL_SNOW_EFFECT); |
---|
37 | |
---|
38 | SnowEffect::SnowEffect(const TiXmlElement* root) |
---|
39 | { |
---|
40 | this->setClassID(CL_SNOW_EFFECT, "SnowEffect"); |
---|
41 | |
---|
42 | this->init(); |
---|
43 | |
---|
44 | if (root != NULL) |
---|
45 | this->loadParams(root); |
---|
46 | |
---|
47 | this->activate(); |
---|
48 | } |
---|
49 | |
---|
50 | |
---|
51 | SnowEffect::~SnowEffect() |
---|
52 | { |
---|
53 | this->deactivate(); |
---|
54 | } |
---|
55 | |
---|
56 | SpriteParticles* SnowEffect::snowParticles = NULL; |
---|
57 | |
---|
58 | void SnowEffect::loadParams(const TiXmlElement* root) |
---|
59 | { |
---|
60 | WeatherEffect::loadParams(root); |
---|
61 | |
---|
62 | LoadParam(root, "numParticles", this, SnowEffect, numParticles); |
---|
63 | LoadParam(root, "materialTexture", this, SnowEffect, materialTexture); |
---|
64 | LoadParam(root, "lifeSpans", this, SnowEffect, lifeSpan); |
---|
65 | LoadParam(root, "radius", this, SnowEffect, radius); |
---|
66 | LoadParam(root, "mass", this, SnowEffect, mass); |
---|
67 | LoadParam(root, "emissionRate", this, SnowEffect, emissionRate); |
---|
68 | LoadParam(root, "emissionVelocity", this, SnowEffect, emissionVelocity); |
---|
69 | LoadParam(root, "spread", this, SnowEffect, spread); |
---|
70 | LoadParam(root, "size", this, SnowEffect, size); |
---|
71 | LoadParam(root, "coord", this, SnowEffect, coord); |
---|
72 | } |
---|
73 | |
---|
74 | bool SnowEffect::init() |
---|
75 | { |
---|
76 | this->emitter = new PlaneEmitter(); |
---|
77 | |
---|
78 | // Default values |
---|
79 | particles = 10000; |
---|
80 | texture = "maps/snow_flake_01_32x32.png"; |
---|
81 | life = 8; |
---|
82 | randomLife = 2; |
---|
83 | snowRadius = 3.5; |
---|
84 | randomRadius = 1; |
---|
85 | snowMass = 1.0; |
---|
86 | randomMass = 0.3; |
---|
87 | rate = 900; |
---|
88 | velocity = -100; |
---|
89 | randomVelocity = 5; |
---|
90 | angle = 0; |
---|
91 | randomAngle = 0.3; |
---|
92 | alpha = 0.5; |
---|
93 | snowSize = Vector2D(1200, 1200); |
---|
94 | snowCoord = Vector(100, 600, 200); |
---|
95 | |
---|
96 | activated = false; |
---|
97 | } |
---|
98 | |
---|
99 | bool SnowEffect::activate() |
---|
100 | { |
---|
101 | PRINTF(0)("Activating SnowEffect\n"); |
---|
102 | activated = true; |
---|
103 | |
---|
104 | SnowEffect::snowParticles = new SpriteParticles(particles); |
---|
105 | SnowEffect::snowParticles->setName("SnowEffectTrailParticles"); |
---|
106 | SnowEffect::snowParticles->setMaterialTexture(texture); |
---|
107 | SnowEffect::snowParticles->setLifeSpan(life, randomLife); |
---|
108 | SnowEffect::snowParticles->setRadius(0.0, snowRadius, randomRadius); |
---|
109 | SnowEffect::snowParticles->setRadius(0.2, snowRadius, randomRadius); |
---|
110 | SnowEffect::snowParticles->setRadius(1.0, snowRadius, randomRadius); |
---|
111 | SnowEffect::snowParticles->setMass(0, snowMass, randomMass); |
---|
112 | SnowEffect::snowParticles->setColor(0,1, 1, 1, alpha); |
---|
113 | SnowEffect::snowParticles->setColor(.5, .6, .6, .6, alpha/2); |
---|
114 | SnowEffect::snowParticles->setColor(1, .0, .0, .0, .0); |
---|
115 | |
---|
116 | this->emitter->setSystem(SnowEffect::snowParticles); |
---|
117 | |
---|
118 | // this->updateNode(0); |
---|
119 | this->emitter->setRelCoor(snowCoord); |
---|
120 | this->emitter->setEmissionRate(rate); |
---|
121 | this->emitter->setEmissionVelocity(velocity, randomVelocity); |
---|
122 | this->emitter->setSpread(angle, randomAngle); |
---|
123 | this->emitter->setSize(snowSize); |
---|
124 | } |
---|
125 | |
---|
126 | |
---|
127 | bool SnowEffect::deactivate() |
---|
128 | { |
---|
129 | PRINTF(0)("Deactivating SnowEffect\n"); |
---|
130 | activated = false; |
---|
131 | |
---|
132 | this->emitter->setSystem(NULL); |
---|
133 | } |
---|
134 | |
---|
135 | void SnowEffect::activateSnow() |
---|
136 | { |
---|
137 | this->activate(); |
---|
138 | } |
---|
139 | |
---|
140 | void SnowEffect::deactivateSnow() |
---|
141 | { |
---|
142 | this->deactivate(); |
---|
143 | } |
---|
144 | |
---|
145 | void SnowEffect::draw() const |
---|
146 | { |
---|
147 | } |
---|
148 | |
---|
149 | void SnowEffect::tick(float dt) |
---|
150 | { |
---|
151 | float distance = (State::getCameraNode()->getAbsCoor() - snowCoord).len(); |
---|
152 | if( activated && ( distance > 0.6*snowSize.x || distance > 0.6*snowSize.y) ) |
---|
153 | this->deactivate(); |
---|
154 | if( !activated && ( distance < 0.6*snowSize.x || distance < 0.6*snowSize.y )) |
---|
155 | this->activate(); |
---|
156 | } |
---|
157 | |
---|