1 | /* |
---|
2 | * ORXONOX - the hottest 3D action shooter ever to exist |
---|
3 | * > www.orxonox.net < |
---|
4 | * |
---|
5 | * |
---|
6 | * License notice: |
---|
7 | * |
---|
8 | * This program is free software; you can redistribute it and/or |
---|
9 | * modify it under the terms of the GNU General Public License |
---|
10 | * as published by the Free Software Foundation; either version 2 |
---|
11 | * of the License, or (at your option) any later version. |
---|
12 | * |
---|
13 | * This program is distributed in the hope that it will be useful, |
---|
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
16 | * GNU General Public License for more details. |
---|
17 | * |
---|
18 | * You should have received a copy of the GNU General Public License |
---|
19 | * along with this program; if not, write to the Free Software |
---|
20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
---|
21 | * |
---|
22 | * Author: |
---|
23 | * Fabian 'x3n' Landau |
---|
24 | * Co-authors: |
---|
25 | * ... |
---|
26 | * |
---|
27 | */ |
---|
28 | |
---|
29 | /** |
---|
30 | * @file |
---|
31 | * @brief class to control praticle effects |
---|
32 | */ |
---|
33 | |
---|
34 | #include "ParticleInterface.h" |
---|
35 | |
---|
36 | #include <OgreParticleSystem.h> |
---|
37 | #include <OgreParticleEmitter.h> |
---|
38 | #include <OgreSceneManager.h> |
---|
39 | #include <cassert> |
---|
40 | |
---|
41 | #include "GraphicsManager.h" |
---|
42 | #include "core/GameMode.h" |
---|
43 | #include "core/CoreIncludes.h" |
---|
44 | #include "util/Convert.h" |
---|
45 | |
---|
46 | namespace orxonox |
---|
47 | { |
---|
48 | unsigned int ParticleInterface::counter_s = 0; |
---|
49 | ParticleInterface* ParticleInterface::currentParticleInterface_s = 0; |
---|
50 | |
---|
51 | ParticleInterface::ParticleInterface(Ogre::SceneManager* scenemanager, const std::string& templateName, LODParticle::LOD detaillevel) |
---|
52 | { |
---|
53 | RegisterObject(ParticleInterface); |
---|
54 | |
---|
55 | assert(scenemanager); |
---|
56 | |
---|
57 | this->scenemanager_ = scenemanager; |
---|
58 | this->particleSystem_ = 0; |
---|
59 | |
---|
60 | this->bEnabled_ = true; |
---|
61 | this->bVisible_ = true; |
---|
62 | this->bAllowedByLOD_ = true; |
---|
63 | this->speedFactor_ = 1.0f; |
---|
64 | |
---|
65 | if (GameMode::showsGraphics()) |
---|
66 | { |
---|
67 | try |
---|
68 | { |
---|
69 | this->particleSystem_ = this->scenemanager_->createParticleSystem("particles" + getConvertedValue<unsigned int, std::string>(ParticleInterface::counter_s++), templateName); |
---|
70 | this->setSpeedFactor(1.0f); |
---|
71 | } |
---|
72 | catch (...) |
---|
73 | { |
---|
74 | COUT(1) << "Error: Couln't load particle system \"" << templateName << "\"" << std::endl; |
---|
75 | this->particleSystem_ = 0; |
---|
76 | } |
---|
77 | } |
---|
78 | |
---|
79 | this->setDetailLevel((unsigned int)detaillevel); |
---|
80 | } |
---|
81 | |
---|
82 | ParticleInterface::~ParticleInterface() |
---|
83 | { |
---|
84 | if (this->particleSystem_) |
---|
85 | { |
---|
86 | this->particleSystem_->removeAllEmitters(); |
---|
87 | this->scenemanager_->destroyParticleSystem(this->particleSystem_); |
---|
88 | } |
---|
89 | } |
---|
90 | |
---|
91 | Ogre::ParticleEmitter* ParticleInterface::createNewEmitter() |
---|
92 | { |
---|
93 | if (this->particleSystem_ && this->particleSystem_->getNumEmitters() > 0) |
---|
94 | { |
---|
95 | Ogre::ParticleEmitter* newemitter = this->particleSystem_->addEmitter(this->particleSystem_->getEmitter(0)->getType()); |
---|
96 | this->particleSystem_->getEmitter(0)->copyParametersTo(newemitter); |
---|
97 | return newemitter; |
---|
98 | } |
---|
99 | else |
---|
100 | return 0; |
---|
101 | } |
---|
102 | Ogre::ParticleEmitter* ParticleInterface::getEmitter(unsigned int emitterNr) const |
---|
103 | { |
---|
104 | if (this->particleSystem_ && (emitterNr < this->particleSystem_->getNumEmitters())) |
---|
105 | return this->particleSystem_->getEmitter(emitterNr); |
---|
106 | else |
---|
107 | return 0; |
---|
108 | } |
---|
109 | void ParticleInterface::removeEmitter(unsigned int emitterNr) |
---|
110 | { |
---|
111 | if (this->particleSystem_ && (emitterNr < this->particleSystem_->getNumEmitters())) |
---|
112 | this->particleSystem_->removeEmitter(emitterNr); |
---|
113 | } |
---|
114 | void ParticleInterface::removeAllEmitters() |
---|
115 | { |
---|
116 | if (this->particleSystem_) |
---|
117 | this->particleSystem_->removeAllEmitters(); |
---|
118 | } |
---|
119 | unsigned int ParticleInterface::getNumEmitters() const |
---|
120 | { |
---|
121 | if (this->particleSystem_) |
---|
122 | return this->particleSystem_->getNumEmitters(); |
---|
123 | else |
---|
124 | return 0; |
---|
125 | } |
---|
126 | |
---|
127 | Ogre::ParticleAffector* ParticleInterface::addAffector(const std::string& name) |
---|
128 | { |
---|
129 | if (this->particleSystem_) |
---|
130 | return this->particleSystem_->addAffector(name); |
---|
131 | else |
---|
132 | return 0; |
---|
133 | } |
---|
134 | Ogre::ParticleAffector* ParticleInterface::getAffector(unsigned int affectorNr) const |
---|
135 | { |
---|
136 | if (this->particleSystem_ && (affectorNr < this->particleSystem_->getNumAffectors())) |
---|
137 | return this->particleSystem_->getAffector(affectorNr); |
---|
138 | else |
---|
139 | return 0; |
---|
140 | } |
---|
141 | void ParticleInterface::removeAffector(unsigned int affectorNr) |
---|
142 | { |
---|
143 | if (this->particleSystem_ && (affectorNr < this->particleSystem_->getNumAffectors())) |
---|
144 | this->particleSystem_->removeAffector(affectorNr); |
---|
145 | } |
---|
146 | void ParticleInterface::removeAllAffectors() |
---|
147 | { |
---|
148 | if (this->particleSystem_) |
---|
149 | this->particleSystem_->removeAllAffectors(); |
---|
150 | } |
---|
151 | unsigned int ParticleInterface::getNumAffectors() const |
---|
152 | { |
---|
153 | if (this->particleSystem_) |
---|
154 | return this->particleSystem_->getNumAffectors(); |
---|
155 | else |
---|
156 | return 0; |
---|
157 | } |
---|
158 | |
---|
159 | void ParticleInterface::setEnabled(bool enable) |
---|
160 | { |
---|
161 | this->bEnabled_ = enable; |
---|
162 | |
---|
163 | if (this->particleSystem_) |
---|
164 | for (unsigned int i = 0; i < this->particleSystem_->getNumEmitters(); i++) |
---|
165 | this->particleSystem_->getEmitter(i)->setEnabled(this->bEnabled_ && this->bAllowedByLOD_); |
---|
166 | } |
---|
167 | |
---|
168 | void ParticleInterface::setVisible(bool visible) |
---|
169 | { |
---|
170 | this->bVisible_ = visible; |
---|
171 | |
---|
172 | if (this->particleSystem_) |
---|
173 | this->particleSystem_->setVisible(this->bVisible_ && this->bAllowedByLOD_); |
---|
174 | } |
---|
175 | |
---|
176 | void ParticleInterface::setDetailLevel(unsigned int level) |
---|
177 | { |
---|
178 | this->detaillevel_ = level; |
---|
179 | if (GameMode::showsGraphics()) |
---|
180 | this->detailLevelChanged(GraphicsManager::getInstance().getDetailLevelParticle()); |
---|
181 | } |
---|
182 | |
---|
183 | void ParticleInterface::detailLevelChanged(unsigned int newlevel) |
---|
184 | { |
---|
185 | if (newlevel >= (unsigned int)this->detaillevel_) |
---|
186 | this->bAllowedByLOD_ = true; |
---|
187 | else |
---|
188 | this->bAllowedByLOD_ = false; |
---|
189 | |
---|
190 | this->updateVisibility(); |
---|
191 | } |
---|
192 | |
---|
193 | void ParticleInterface::updateVisibility() |
---|
194 | { |
---|
195 | this->setEnabled(this->isEnabled()); |
---|
196 | this->setVisible(this->isVisible()); |
---|
197 | } |
---|
198 | |
---|
199 | void ParticleInterface::setSpeedFactor(float factor) |
---|
200 | { |
---|
201 | this->speedFactor_ = factor; |
---|
202 | |
---|
203 | if (this->particleSystem_) |
---|
204 | this->particleSystem_->setSpeedFactor(factor * this->getTimeFactor()); |
---|
205 | } |
---|
206 | void ParticleInterface::changedTimeFactor(float factor_new, float factor_old) |
---|
207 | { |
---|
208 | this->setSpeedFactor(this->speedFactor_); |
---|
209 | } |
---|
210 | |
---|
211 | bool ParticleInterface::getKeepParticlesInLocalSpace() const |
---|
212 | { |
---|
213 | if (this->particleSystem_) |
---|
214 | return this->particleSystem_->getKeepParticlesInLocalSpace(); |
---|
215 | else |
---|
216 | return false; |
---|
217 | } |
---|
218 | void ParticleInterface::setKeepParticlesInLocalSpace(bool keep) |
---|
219 | { |
---|
220 | if (this->particleSystem_) |
---|
221 | this->particleSystem_->setKeepParticlesInLocalSpace(keep); |
---|
222 | } |
---|
223 | } |
---|