| [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 | /** |
|---|
| 30 | * @file ParticleInterface.cc |
|---|
| 31 | * @brief class to control praticle effects |
|---|
| 32 | */ |
|---|
| 33 | |
|---|
| 34 | #include "OrxonoxStableHeaders.h" |
|---|
| 35 | #include "ParticleInterface.h" |
|---|
| 36 | |
|---|
| [1552] | 37 | #include <OgreParticleSystem.h> |
|---|
| 38 | #include <OgreParticleEmitter.h> |
|---|
| 39 | #include <OgreSceneManager.h> |
|---|
| [2087] | 40 | #include <cassert> |
|---|
| [1505] | 41 | |
|---|
| [1552] | 42 | #include "GraphicsEngine.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 | { |
|---|
| 53 | RegisterRootObject(ParticleInterface); |
|---|
| [1563] | 54 | |
|---|
| [2087] | 55 | assert(scenemanager); |
|---|
| [1563] | 56 | |
|---|
| [2087] | 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() |
|---|
| [1563] | 71 | { |
|---|
| [2087] | 72 | this->particleSystem_->removeAllEmitters(); |
|---|
| 73 | this->scenemanager_->destroyParticleSystem(particleSystem_); |
|---|
| [1563] | 74 | } |
|---|
| [2087] | 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 | } |
|---|
| [1505] | 107 | |
|---|
| [2087] | 108 | Ogre::ParticleAffector* ParticleInterface::addAffector(const std::string& name) |
|---|
| [1552] | 109 | { |
|---|
| [2087] | 110 | return this->particleSystem_->addAffector(name); |
|---|
| [1552] | 111 | } |
|---|
| [2087] | 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 | } |
|---|
| [1505] | 132 | |
|---|
| [2087] | 133 | void ParticleInterface::setEnabled(bool enable) |
|---|
| [1552] | 134 | { |
|---|
| [2087] | 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_); |
|---|
| [1505] | 139 | } |
|---|
| 140 | |
|---|
| [2087] | 141 | void ParticleInterface::setVisible(bool visible) |
|---|
| 142 | { |
|---|
| 143 | this->bVisible_ = visible; |
|---|
| [1505] | 144 | |
|---|
| [2087] | 145 | this->particleSystem_->setVisible(this->bVisible_ && this->bAllowedByLOD_); |
|---|
| 146 | } |
|---|
| [1563] | 147 | |
|---|
| [2087] | 148 | void ParticleInterface::setDetailLevel(unsigned int level) |
|---|
| 149 | { |
|---|
| 150 | this->detaillevel_ = level; |
|---|
| 151 | this->detailLevelChanged(GraphicsEngine::getInstance().getDetailLevelParticle()); |
|---|
| 152 | } |
|---|
| [1563] | 153 | |
|---|
| [2087] | 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; |
|---|
| [1563] | 160 | |
|---|
| [2087] | 161 | this->updateVisibility(); |
|---|
| 162 | } |
|---|
| [1505] | 163 | |
|---|
| [2087] | 164 | void ParticleInterface::updateVisibility() |
|---|
| 165 | { |
|---|
| 166 | this->setEnabled(this->isEnabled()); |
|---|
| 167 | this->setVisible(this->isVisible()); |
|---|
| 168 | } |
|---|
| [1505] | 169 | |
|---|
| [2087] | 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 | } |
|---|
| [1505] | 189 | } |
|---|