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 ParticleInterface.cc |
---|
31 | * @brief class to control praticle effects |
---|
32 | */ |
---|
33 | |
---|
34 | #include "OrxonoxStableHeaders.h" |
---|
35 | #include "ParticleInterface.h" |
---|
36 | |
---|
37 | #include <OgreParticleSystem.h> |
---|
38 | #include <OgreParticleEmitter.h> |
---|
39 | #include <OgreSceneManager.h> |
---|
40 | #include <cassert> |
---|
41 | |
---|
42 | #include "GraphicsEngine.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 | RegisterRootObject(ParticleInterface); |
---|
54 | |
---|
55 | assert(scenemanager); |
---|
56 | |
---|
57 | this->scenemanager_ = scenemanager; |
---|
58 | |
---|
59 | this->bEnabled_ = true; |
---|
60 | this->bVisible_ = true; |
---|
61 | this->bAllowedByLOD_ = true; |
---|
62 | |
---|
63 | this->particleSystem_ = this->scenemanager_->createParticleSystem("particles" + getConvertedValue<unsigned int, std::string>(ParticleInterface::counter_s++), templateName); |
---|
64 | this->particleSystem_->setSpeedFactor(1.0f); |
---|
65 | //this->particleSystem_->setSpeedFactor(Orxonox::getInstance().getTimeFactor()); |
---|
66 | |
---|
67 | this->setDetailLevel((unsigned int)detaillevel); |
---|
68 | } |
---|
69 | |
---|
70 | ParticleInterface::~ParticleInterface() |
---|
71 | { |
---|
72 | this->particleSystem_->removeAllEmitters(); |
---|
73 | this->scenemanager_->destroyParticleSystem(particleSystem_); |
---|
74 | } |
---|
75 | |
---|
76 | Ogre::ParticleEmitter* ParticleInterface::createNewEmitter() |
---|
77 | { |
---|
78 | if (this->particleSystem_->getNumEmitters() > 0) |
---|
79 | { |
---|
80 | Ogre::ParticleEmitter* newemitter = this->particleSystem_->addEmitter(this->particleSystem_->getEmitter(0)->getType()); |
---|
81 | this->particleSystem_->getEmitter(0)->copyParametersTo(newemitter); |
---|
82 | return newemitter; |
---|
83 | } |
---|
84 | else |
---|
85 | return 0; |
---|
86 | } |
---|
87 | Ogre::ParticleEmitter* ParticleInterface::getEmitter(unsigned int emitterNr) const |
---|
88 | { |
---|
89 | if (emitterNr < this->particleSystem_->getNumEmitters()) |
---|
90 | return this->particleSystem_->getEmitter(emitterNr); |
---|
91 | else |
---|
92 | return 0; |
---|
93 | } |
---|
94 | void ParticleInterface::removeEmitter(unsigned int emitterNr) |
---|
95 | { |
---|
96 | if (emitterNr < this->particleSystem_->getNumEmitters()) |
---|
97 | this->particleSystem_->removeEmitter(emitterNr); |
---|
98 | } |
---|
99 | void ParticleInterface::removeAllEmitters() |
---|
100 | { |
---|
101 | this->particleSystem_->removeAllEmitters(); |
---|
102 | } |
---|
103 | unsigned int ParticleInterface::getNumEmitters() const |
---|
104 | { |
---|
105 | return this->particleSystem_->getNumEmitters(); |
---|
106 | } |
---|
107 | |
---|
108 | Ogre::ParticleAffector* ParticleInterface::addAffector(const std::string& name) |
---|
109 | { |
---|
110 | return this->particleSystem_->addAffector(name); |
---|
111 | } |
---|
112 | Ogre::ParticleAffector* ParticleInterface::getAffector(unsigned int affectorNr) const |
---|
113 | { |
---|
114 | if (affectorNr < this->particleSystem_->getNumAffectors()) |
---|
115 | return this->particleSystem_->getAffector(affectorNr); |
---|
116 | else |
---|
117 | return 0; |
---|
118 | } |
---|
119 | void ParticleInterface::removeAffector(unsigned int affectorNr) |
---|
120 | { |
---|
121 | if (affectorNr < this->particleSystem_->getNumAffectors()) |
---|
122 | this->particleSystem_->removeAffector(affectorNr); |
---|
123 | } |
---|
124 | void ParticleInterface::removeAllAffectors() |
---|
125 | { |
---|
126 | this->particleSystem_->removeAllAffectors(); |
---|
127 | } |
---|
128 | unsigned int ParticleInterface::getNumAffectors() const |
---|
129 | { |
---|
130 | return this->particleSystem_->getNumAffectors(); |
---|
131 | } |
---|
132 | |
---|
133 | void ParticleInterface::setEnabled(bool enable) |
---|
134 | { |
---|
135 | this->bEnabled_ = enable; |
---|
136 | |
---|
137 | for (unsigned int i = 0; i < this->particleSystem_->getNumEmitters(); i++) |
---|
138 | this->particleSystem_->getEmitter(i)->setEnabled(this->bEnabled_ && this->bAllowedByLOD_); |
---|
139 | } |
---|
140 | |
---|
141 | void ParticleInterface::setVisible(bool visible) |
---|
142 | { |
---|
143 | this->bVisible_ = visible; |
---|
144 | |
---|
145 | this->particleSystem_->setVisible(this->bVisible_ && this->bAllowedByLOD_); |
---|
146 | } |
---|
147 | |
---|
148 | void ParticleInterface::setDetailLevel(unsigned int level) |
---|
149 | { |
---|
150 | this->detaillevel_ = level; |
---|
151 | this->detailLevelChanged(GraphicsEngine::getInstance().getDetailLevelParticle()); |
---|
152 | } |
---|
153 | |
---|
154 | void ParticleInterface::detailLevelChanged(unsigned int newlevel) |
---|
155 | { |
---|
156 | if (newlevel >= (unsigned int)this->detaillevel_) |
---|
157 | this->bAllowedByLOD_ = true; |
---|
158 | else |
---|
159 | this->bAllowedByLOD_ = false; |
---|
160 | |
---|
161 | this->updateVisibility(); |
---|
162 | } |
---|
163 | |
---|
164 | void ParticleInterface::updateVisibility() |
---|
165 | { |
---|
166 | this->setEnabled(this->isEnabled()); |
---|
167 | this->setVisible(this->isVisible()); |
---|
168 | } |
---|
169 | |
---|
170 | void ParticleInterface::setSpeedFactor(float factor) |
---|
171 | { |
---|
172 | //this->particleSystem_->setSpeedFactor(Orxonox::getInstance().getTimeFactor() * factor); |
---|
173 | this->particleSystem_->setSpeedFactor(1.0f * factor); |
---|
174 | } |
---|
175 | float ParticleInterface::getSpeedFactor() const |
---|
176 | { |
---|
177 | //return (this->particleSystem_->getSpeedFactor() / Orxonox::getInstance().getTimeFactor()); |
---|
178 | return (this->particleSystem_->getSpeedFactor() / 1.0f); |
---|
179 | } |
---|
180 | |
---|
181 | bool ParticleInterface::getKeepParticlesInLocalSpace() const |
---|
182 | { |
---|
183 | return this->particleSystem_->getKeepParticlesInLocalSpace(); |
---|
184 | } |
---|
185 | void ParticleInterface::setKeepParticlesInLocalSpace(bool keep) |
---|
186 | { |
---|
187 | this->particleSystem_->setKeepParticlesInLocalSpace(keep); |
---|
188 | } |
---|
189 | } |
---|