[1505] | 1 | /* |
---|
[2087] | 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 | */ |
---|
[1505] | 28 | |
---|
| 29 | /** |
---|
[2171] | 30 | * @file |
---|
[1505] | 31 | * @brief class to control praticle effects |
---|
| 32 | */ |
---|
| 33 | |
---|
| 34 | #include "ParticleInterface.h" |
---|
| 35 | |
---|
[1552] | 36 | #include <OgreParticleSystem.h> |
---|
| 37 | #include <OgreParticleEmitter.h> |
---|
| 38 | #include <OgreSceneManager.h> |
---|
[2087] | 39 | #include <cassert> |
---|
[1505] | 40 | |
---|
[2896] | 41 | #include "GraphicsManager.h" |
---|
| 42 | #include "core/GameMode.h" |
---|
[1563] | 43 | #include "core/CoreIncludes.h" |
---|
[1552] | 44 | #include "util/Convert.h" |
---|
[1505] | 45 | |
---|
[1552] | 46 | namespace orxonox |
---|
| 47 | { |
---|
[2087] | 48 | unsigned int ParticleInterface::counter_s = 0; |
---|
| 49 | ParticleInterface* ParticleInterface::currentParticleInterface_s = 0; |
---|
[1505] | 50 | |
---|
[2087] | 51 | ParticleInterface::ParticleInterface(Ogre::SceneManager* scenemanager, const std::string& templateName, LODParticle::LOD detaillevel) |
---|
| 52 | { |
---|
[2662] | 53 | RegisterObject(ParticleInterface); |
---|
[1563] | 54 | |
---|
[2087] | 55 | assert(scenemanager); |
---|
[1563] | 56 | |
---|
[2087] | 57 | this->scenemanager_ = scenemanager; |
---|
[2171] | 58 | this->particleSystem_ = 0; |
---|
[2087] | 59 | |
---|
| 60 | this->bEnabled_ = true; |
---|
| 61 | this->bVisible_ = true; |
---|
| 62 | this->bAllowedByLOD_ = true; |
---|
[2662] | 63 | this->speedFactor_ = 1.0f; |
---|
[2087] | 64 | |
---|
[2896] | 65 | if (GameMode::showsGraphics()) |
---|
[2171] | 66 | { |
---|
| 67 | try |
---|
| 68 | { |
---|
| 69 | this->particleSystem_ = this->scenemanager_->createParticleSystem("particles" + getConvertedValue<unsigned int, std::string>(ParticleInterface::counter_s++), templateName); |
---|
[2662] | 70 | this->setSpeedFactor(1.0f); |
---|
[2171] | 71 | } |
---|
| 72 | catch (...) |
---|
| 73 | { |
---|
| 74 | COUT(1) << "Error: Couln't load particle system \"" << templateName << "\"" << std::endl; |
---|
| 75 | this->particleSystem_ = 0; |
---|
| 76 | } |
---|
| 77 | } |
---|
[2087] | 78 | |
---|
| 79 | this->setDetailLevel((unsigned int)detaillevel); |
---|
| 80 | } |
---|
| 81 | |
---|
| 82 | ParticleInterface::~ParticleInterface() |
---|
[1563] | 83 | { |
---|
[2171] | 84 | if (this->particleSystem_) |
---|
| 85 | { |
---|
| 86 | this->particleSystem_->removeAllEmitters(); |
---|
| 87 | this->scenemanager_->destroyParticleSystem(this->particleSystem_); |
---|
| 88 | } |
---|
[1563] | 89 | } |
---|
[2087] | 90 | |
---|
| 91 | Ogre::ParticleEmitter* ParticleInterface::createNewEmitter() |
---|
| 92 | { |
---|
[2171] | 93 | if (this->particleSystem_ && this->particleSystem_->getNumEmitters() > 0) |
---|
[2087] | 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 | { |
---|
[2171] | 104 | if (this->particleSystem_ && (emitterNr < this->particleSystem_->getNumEmitters())) |
---|
[2087] | 105 | return this->particleSystem_->getEmitter(emitterNr); |
---|
| 106 | else |
---|
| 107 | return 0; |
---|
| 108 | } |
---|
| 109 | void ParticleInterface::removeEmitter(unsigned int emitterNr) |
---|
| 110 | { |
---|
[2171] | 111 | if (this->particleSystem_ && (emitterNr < this->particleSystem_->getNumEmitters())) |
---|
[2087] | 112 | this->particleSystem_->removeEmitter(emitterNr); |
---|
| 113 | } |
---|
| 114 | void ParticleInterface::removeAllEmitters() |
---|
| 115 | { |
---|
[2171] | 116 | if (this->particleSystem_) |
---|
| 117 | this->particleSystem_->removeAllEmitters(); |
---|
[2087] | 118 | } |
---|
| 119 | unsigned int ParticleInterface::getNumEmitters() const |
---|
| 120 | { |
---|
[2171] | 121 | if (this->particleSystem_) |
---|
| 122 | return this->particleSystem_->getNumEmitters(); |
---|
| 123 | else |
---|
| 124 | return 0; |
---|
[2087] | 125 | } |
---|
[1505] | 126 | |
---|
[2087] | 127 | Ogre::ParticleAffector* ParticleInterface::addAffector(const std::string& name) |
---|
[1552] | 128 | { |
---|
[2171] | 129 | if (this->particleSystem_) |
---|
| 130 | return this->particleSystem_->addAffector(name); |
---|
| 131 | else |
---|
| 132 | return 0; |
---|
[1552] | 133 | } |
---|
[2087] | 134 | Ogre::ParticleAffector* ParticleInterface::getAffector(unsigned int affectorNr) const |
---|
| 135 | { |
---|
[2171] | 136 | if (this->particleSystem_ && (affectorNr < this->particleSystem_->getNumAffectors())) |
---|
[2087] | 137 | return this->particleSystem_->getAffector(affectorNr); |
---|
| 138 | else |
---|
| 139 | return 0; |
---|
| 140 | } |
---|
| 141 | void ParticleInterface::removeAffector(unsigned int affectorNr) |
---|
| 142 | { |
---|
[2171] | 143 | if (this->particleSystem_ && (affectorNr < this->particleSystem_->getNumAffectors())) |
---|
[2087] | 144 | this->particleSystem_->removeAffector(affectorNr); |
---|
| 145 | } |
---|
| 146 | void ParticleInterface::removeAllAffectors() |
---|
| 147 | { |
---|
[2171] | 148 | if (this->particleSystem_) |
---|
| 149 | this->particleSystem_->removeAllAffectors(); |
---|
[2087] | 150 | } |
---|
| 151 | unsigned int ParticleInterface::getNumAffectors() const |
---|
| 152 | { |
---|
[2171] | 153 | if (this->particleSystem_) |
---|
| 154 | return this->particleSystem_->getNumAffectors(); |
---|
| 155 | else |
---|
| 156 | return 0; |
---|
[2087] | 157 | } |
---|
[1505] | 158 | |
---|
[2087] | 159 | void ParticleInterface::setEnabled(bool enable) |
---|
[1552] | 160 | { |
---|
[2087] | 161 | this->bEnabled_ = enable; |
---|
| 162 | |
---|
[2171] | 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_); |
---|
[1505] | 166 | } |
---|
| 167 | |
---|
[2087] | 168 | void ParticleInterface::setVisible(bool visible) |
---|
| 169 | { |
---|
| 170 | this->bVisible_ = visible; |
---|
[1505] | 171 | |
---|
[2171] | 172 | if (this->particleSystem_) |
---|
| 173 | this->particleSystem_->setVisible(this->bVisible_ && this->bAllowedByLOD_); |
---|
[2087] | 174 | } |
---|
[1563] | 175 | |
---|
[2087] | 176 | void ParticleInterface::setDetailLevel(unsigned int level) |
---|
| 177 | { |
---|
| 178 | this->detaillevel_ = level; |
---|
[2896] | 179 | if (GameMode::showsGraphics()) |
---|
| 180 | this->detailLevelChanged(GraphicsManager::getInstance().getDetailLevelParticle()); |
---|
[2087] | 181 | } |
---|
[1563] | 182 | |
---|
[2087] | 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; |
---|
[1563] | 189 | |
---|
[2087] | 190 | this->updateVisibility(); |
---|
| 191 | } |
---|
[1505] | 192 | |
---|
[2087] | 193 | void ParticleInterface::updateVisibility() |
---|
| 194 | { |
---|
| 195 | this->setEnabled(this->isEnabled()); |
---|
| 196 | this->setVisible(this->isVisible()); |
---|
| 197 | } |
---|
[1505] | 198 | |
---|
[2087] | 199 | void ParticleInterface::setSpeedFactor(float factor) |
---|
| 200 | { |
---|
[2662] | 201 | this->speedFactor_ = factor; |
---|
| 202 | |
---|
[2171] | 203 | if (this->particleSystem_) |
---|
[2662] | 204 | this->particleSystem_->setSpeedFactor(factor * this->getTimeFactor()); |
---|
[2087] | 205 | } |
---|
[2662] | 206 | void ParticleInterface::changedTimeFactor(float factor_new, float factor_old) |
---|
[2087] | 207 | { |
---|
[2662] | 208 | this->setSpeedFactor(this->speedFactor_); |
---|
[2087] | 209 | } |
---|
| 210 | |
---|
| 211 | bool ParticleInterface::getKeepParticlesInLocalSpace() const |
---|
| 212 | { |
---|
[2171] | 213 | if (this->particleSystem_) |
---|
| 214 | return this->particleSystem_->getKeepParticlesInLocalSpace(); |
---|
| 215 | else |
---|
| 216 | return false; |
---|
[2087] | 217 | } |
---|
| 218 | void ParticleInterface::setKeepParticlesInLocalSpace(bool keep) |
---|
| 219 | { |
---|
[2171] | 220 | if (this->particleSystem_) |
---|
| 221 | this->particleSystem_->setKeepParticlesInLocalSpace(keep); |
---|
[2087] | 222 | } |
---|
[1505] | 223 | } |
---|