[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" |
---|
| 41 | #include "util/Convert.h" |
---|
[1505] | 42 | |
---|
[1552] | 43 | namespace orxonox |
---|
| 44 | { |
---|
| 45 | unsigned int ParticleInterface::counter_s = 0; |
---|
| 46 | ParticleInterface* ParticleInterface::currentParticleInterface_s = 0; |
---|
[1505] | 47 | |
---|
[1552] | 48 | ParticleInterface::ParticleInterface(const std::string& templateName) |
---|
[1505] | 49 | { |
---|
[1552] | 50 | this->sceneNode_ = 0; |
---|
| 51 | this->particleSystem_ = GraphicsEngine::getSingleton().getSceneManager()->createParticleSystem("particles" + getConvertedValue<unsigned int, std::string>(ParticleInterface::counter_s++), templateName); |
---|
[1505] | 52 | } |
---|
| 53 | |
---|
[1552] | 54 | ParticleInterface::~ParticleInterface() |
---|
[1505] | 55 | { |
---|
[1552] | 56 | this->particleSystem_->removeAllEmitters(); |
---|
| 57 | GraphicsEngine::getSingleton().getSceneManager()->destroyParticleSystem(particleSystem_); |
---|
[1505] | 58 | } |
---|
| 59 | |
---|
[1552] | 60 | void ParticleInterface::addToSceneNode(Ogre::SceneNode* sceneNode) |
---|
[1505] | 61 | { |
---|
[1552] | 62 | this->sceneNode_ = sceneNode; |
---|
| 63 | this->sceneNode_->attachObject(this->particleSystem_); |
---|
[1505] | 64 | } |
---|
| 65 | |
---|
[1552] | 66 | void ParticleInterface::detachFromSceneNode() |
---|
[1505] | 67 | { |
---|
[1552] | 68 | if (this->sceneNode_) |
---|
| 69 | { |
---|
| 70 | this->sceneNode_->detachObject(this->particleSystem_); |
---|
| 71 | this->sceneNode_ = 0; |
---|
| 72 | } |
---|
[1505] | 73 | } |
---|
| 74 | |
---|
[1552] | 75 | Ogre::ParticleEmitter* ParticleInterface::createNewEmitter() |
---|
[1505] | 76 | { |
---|
[1552] | 77 | if (this->particleSystem_->getNumEmitters() > 0) |
---|
| 78 | { |
---|
| 79 | Ogre::ParticleEmitter* newemitter = this->particleSystem_->addEmitter(this->particleSystem_->getEmitter(0)->getType()); |
---|
| 80 | this->particleSystem_->getEmitter(0)->copyParametersTo(newemitter); |
---|
| 81 | return newemitter; |
---|
[1505] | 82 | } |
---|
[1552] | 83 | else |
---|
| 84 | return 0; |
---|
[1505] | 85 | } |
---|
[1552] | 86 | Ogre::ParticleEmitter* ParticleInterface::getEmitter(unsigned int emitterNr) const |
---|
[1505] | 87 | { |
---|
[1552] | 88 | if (emitterNr < this->particleSystem_->getNumEmitters()) |
---|
| 89 | return this->particleSystem_->getEmitter(emitterNr); |
---|
| 90 | else |
---|
| 91 | return 0; |
---|
[1505] | 92 | } |
---|
[1552] | 93 | void ParticleInterface::removeEmitter(unsigned int emitterNr) |
---|
[1505] | 94 | { |
---|
[1552] | 95 | if (emitterNr < this->particleSystem_->getNumEmitters()) |
---|
| 96 | this->particleSystem_->removeEmitter(emitterNr); |
---|
[1505] | 97 | } |
---|
[1552] | 98 | void ParticleInterface::removeAllEmitters() |
---|
[1505] | 99 | { |
---|
[1552] | 100 | this->particleSystem_->removeAllEmitters(); |
---|
[1505] | 101 | } |
---|
[1552] | 102 | unsigned int ParticleInterface::getNumEmitters() const |
---|
| 103 | { |
---|
| 104 | return this->particleSystem_->getNumEmitters(); |
---|
| 105 | } |
---|
[1505] | 106 | |
---|
[1552] | 107 | Ogre::ParticleAffector* ParticleInterface::addAffector(const std::string& name) |
---|
[1505] | 108 | { |
---|
[1552] | 109 | return this->particleSystem_->addAffector(name); |
---|
[1505] | 110 | } |
---|
[1552] | 111 | Ogre::ParticleAffector* ParticleInterface::getAffector(unsigned int affectorNr) const |
---|
| 112 | { |
---|
| 113 | if (affectorNr < this->particleSystem_->getNumAffectors()) |
---|
| 114 | return this->particleSystem_->getAffector(affectorNr); |
---|
| 115 | else |
---|
| 116 | return 0; |
---|
| 117 | } |
---|
| 118 | void ParticleInterface::removeAffector(unsigned int affectorNr) |
---|
| 119 | { |
---|
| 120 | if (affectorNr < this->particleSystem_->getNumAffectors()) |
---|
| 121 | this->particleSystem_->removeAffector(affectorNr); |
---|
| 122 | } |
---|
| 123 | void ParticleInterface::removeAllAffectors() |
---|
| 124 | { |
---|
| 125 | this->particleSystem_->removeAllAffectors(); |
---|
| 126 | } |
---|
| 127 | unsigned int ParticleInterface::getNumAffectors() const |
---|
| 128 | { |
---|
| 129 | return this->particleSystem_->getNumAffectors(); |
---|
| 130 | } |
---|
[1505] | 131 | |
---|
[1552] | 132 | void ParticleInterface::setEnabled(bool enable) |
---|
[1505] | 133 | { |
---|
[1552] | 134 | for (unsigned int i = 0; i < this->particleSystem_->getNumEmitters(); i++) |
---|
| 135 | this->particleSystem_->getEmitter(i)->setEnabled(enable); |
---|
[1505] | 136 | } |
---|
| 137 | |
---|
[1552] | 138 | void ParticleInterface::setSpeedFactor(float factor) |
---|
[1505] | 139 | { |
---|
[1552] | 140 | this->particleSystem_->setSpeedFactor(factor); |
---|
[1505] | 141 | } |
---|
[1552] | 142 | float ParticleInterface::getSpeedFactor() const |
---|
| 143 | { |
---|
| 144 | return this->particleSystem_->getSpeedFactor(); |
---|
| 145 | } |
---|
[1505] | 146 | |
---|
[1552] | 147 | bool ParticleInterface::getKeepParticlesInLocalSpace() const |
---|
| 148 | { |
---|
| 149 | return this->particleSystem_->getKeepParticlesInLocalSpace(); |
---|
[1505] | 150 | } |
---|
[1552] | 151 | void ParticleInterface::setKeepParticlesInLocalSpace(bool keep) |
---|
| 152 | { |
---|
| 153 | this->particleSystem_->setKeepParticlesInLocalSpace(keep); |
---|
| 154 | } |
---|
[1505] | 155 | } |
---|