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