[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; |
---|
[1552] | 57 | this->particleSystem_ = GraphicsEngine::getSingleton().getSceneManager()->createParticleSystem("particles" + getConvertedValue<unsigned int, std::string>(ParticleInterface::counter_s++), templateName); |
---|
[1555] | 58 | this->particleSystem_->setSpeedFactor(Orxonox::getSingleton()->getTimeFactor()); |
---|
[1563] | 59 | |
---|
| 60 | if (GraphicsEngine::getSingleton().getDetailLevelParticle() < (unsigned int)this->detaillevel_) |
---|
| 61 | { |
---|
| 62 | this->bVisible_ = false; |
---|
| 63 | this->updateVisibility(); |
---|
| 64 | } |
---|
| 65 | else |
---|
| 66 | { |
---|
| 67 | this->bVisible_ = true; |
---|
| 68 | } |
---|
[1505] | 69 | } |
---|
| 70 | |
---|
[1552] | 71 | ParticleInterface::~ParticleInterface() |
---|
[1505] | 72 | { |
---|
[1552] | 73 | this->particleSystem_->removeAllEmitters(); |
---|
| 74 | GraphicsEngine::getSingleton().getSceneManager()->destroyParticleSystem(particleSystem_); |
---|
[1505] | 75 | } |
---|
| 76 | |
---|
[1552] | 77 | void ParticleInterface::addToSceneNode(Ogre::SceneNode* sceneNode) |
---|
[1505] | 78 | { |
---|
[1552] | 79 | this->sceneNode_ = sceneNode; |
---|
| 80 | this->sceneNode_->attachObject(this->particleSystem_); |
---|
[1505] | 81 | } |
---|
| 82 | |
---|
[1552] | 83 | void ParticleInterface::detachFromSceneNode() |
---|
[1505] | 84 | { |
---|
[1552] | 85 | if (this->sceneNode_) |
---|
| 86 | { |
---|
| 87 | this->sceneNode_->detachObject(this->particleSystem_); |
---|
| 88 | this->sceneNode_ = 0; |
---|
| 89 | } |
---|
[1505] | 90 | } |
---|
| 91 | |
---|
[1552] | 92 | Ogre::ParticleEmitter* ParticleInterface::createNewEmitter() |
---|
[1505] | 93 | { |
---|
[1552] | 94 | if (this->particleSystem_->getNumEmitters() > 0) |
---|
| 95 | { |
---|
| 96 | Ogre::ParticleEmitter* newemitter = this->particleSystem_->addEmitter(this->particleSystem_->getEmitter(0)->getType()); |
---|
| 97 | this->particleSystem_->getEmitter(0)->copyParametersTo(newemitter); |
---|
| 98 | return newemitter; |
---|
[1505] | 99 | } |
---|
[1552] | 100 | else |
---|
| 101 | return 0; |
---|
[1505] | 102 | } |
---|
[1552] | 103 | Ogre::ParticleEmitter* ParticleInterface::getEmitter(unsigned int emitterNr) const |
---|
[1505] | 104 | { |
---|
[1552] | 105 | if (emitterNr < this->particleSystem_->getNumEmitters()) |
---|
| 106 | return this->particleSystem_->getEmitter(emitterNr); |
---|
| 107 | else |
---|
| 108 | return 0; |
---|
[1505] | 109 | } |
---|
[1552] | 110 | void ParticleInterface::removeEmitter(unsigned int emitterNr) |
---|
[1505] | 111 | { |
---|
[1552] | 112 | if (emitterNr < this->particleSystem_->getNumEmitters()) |
---|
| 113 | this->particleSystem_->removeEmitter(emitterNr); |
---|
[1505] | 114 | } |
---|
[1552] | 115 | void ParticleInterface::removeAllEmitters() |
---|
[1505] | 116 | { |
---|
[1552] | 117 | this->particleSystem_->removeAllEmitters(); |
---|
[1505] | 118 | } |
---|
[1552] | 119 | unsigned int ParticleInterface::getNumEmitters() const |
---|
| 120 | { |
---|
| 121 | return this->particleSystem_->getNumEmitters(); |
---|
| 122 | } |
---|
[1505] | 123 | |
---|
[1552] | 124 | Ogre::ParticleAffector* ParticleInterface::addAffector(const std::string& name) |
---|
[1505] | 125 | { |
---|
[1552] | 126 | return this->particleSystem_->addAffector(name); |
---|
[1505] | 127 | } |
---|
[1552] | 128 | Ogre::ParticleAffector* ParticleInterface::getAffector(unsigned int affectorNr) const |
---|
| 129 | { |
---|
| 130 | if (affectorNr < this->particleSystem_->getNumAffectors()) |
---|
| 131 | return this->particleSystem_->getAffector(affectorNr); |
---|
| 132 | else |
---|
| 133 | return 0; |
---|
| 134 | } |
---|
| 135 | void ParticleInterface::removeAffector(unsigned int affectorNr) |
---|
| 136 | { |
---|
| 137 | if (affectorNr < this->particleSystem_->getNumAffectors()) |
---|
| 138 | this->particleSystem_->removeAffector(affectorNr); |
---|
| 139 | } |
---|
| 140 | void ParticleInterface::removeAllAffectors() |
---|
| 141 | { |
---|
| 142 | this->particleSystem_->removeAllAffectors(); |
---|
| 143 | } |
---|
| 144 | unsigned int ParticleInterface::getNumAffectors() const |
---|
| 145 | { |
---|
| 146 | return this->particleSystem_->getNumAffectors(); |
---|
| 147 | } |
---|
[1505] | 148 | |
---|
[1552] | 149 | void ParticleInterface::setEnabled(bool enable) |
---|
[1505] | 150 | { |
---|
[1563] | 151 | this->bEnabled_ = enable; |
---|
| 152 | this->updateVisibility(); |
---|
| 153 | } |
---|
| 154 | |
---|
| 155 | void ParticleInterface::detailLevelChanged(unsigned int newlevel) |
---|
| 156 | { |
---|
| 157 | if (newlevel >= (unsigned int)this->detaillevel_) |
---|
| 158 | this->bVisible_ = true; |
---|
| 159 | else |
---|
| 160 | this->bVisible_ = false; |
---|
| 161 | |
---|
| 162 | this->updateVisibility(); |
---|
| 163 | } |
---|
| 164 | |
---|
| 165 | void ParticleInterface::updateVisibility() |
---|
| 166 | { |
---|
[1552] | 167 | for (unsigned int i = 0; i < this->particleSystem_->getNumEmitters(); i++) |
---|
[1563] | 168 | this->particleSystem_->getEmitter(i)->setEnabled(this->bEnabled_ && this->bVisible_); |
---|
[1505] | 169 | } |
---|
| 170 | |
---|
[1552] | 171 | void ParticleInterface::setSpeedFactor(float factor) |
---|
[1505] | 172 | { |
---|
[1555] | 173 | this->particleSystem_->setSpeedFactor(Orxonox::getSingleton()->getTimeFactor() * factor); |
---|
[1505] | 174 | } |
---|
[1552] | 175 | float ParticleInterface::getSpeedFactor() const |
---|
| 176 | { |
---|
[1563] | 177 | return (this->particleSystem_->getSpeedFactor() / Orxonox::getSingleton()->getTimeFactor()); |
---|
[1552] | 178 | } |
---|
[1505] | 179 | |
---|
[1552] | 180 | bool ParticleInterface::getKeepParticlesInLocalSpace() const |
---|
| 181 | { |
---|
| 182 | return this->particleSystem_->getKeepParticlesInLocalSpace(); |
---|
[1505] | 183 | } |
---|
[1552] | 184 | void ParticleInterface::setKeepParticlesInLocalSpace(bool keep) |
---|
| 185 | { |
---|
| 186 | this->particleSystem_->setKeepParticlesInLocalSpace(keep); |
---|
| 187 | } |
---|
[1505] | 188 | } |
---|