[1505] | 1 | /* |
---|
[2065] | 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 | /** |
---|
[2114] | 30 | * @file |
---|
[1505] | 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> |
---|
[2019] | 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 | { |
---|
[2065] | 48 | unsigned int ParticleInterface::counter_s = 0; |
---|
| 49 | ParticleInterface* ParticleInterface::currentParticleInterface_s = 0; |
---|
[1505] | 50 | |
---|
[2065] | 51 | ParticleInterface::ParticleInterface(Ogre::SceneManager* scenemanager, const std::string& templateName, LODParticle::LOD detaillevel) |
---|
| 52 | { |
---|
| 53 | RegisterRootObject(ParticleInterface); |
---|
[1563] | 54 | |
---|
[2065] | 55 | assert(scenemanager); |
---|
[2019] | 56 | |
---|
[2065] | 57 | this->scenemanager_ = scenemanager; |
---|
| 58 | this->sceneNode_ = 0; |
---|
[1563] | 59 | |
---|
[2065] | 60 | this->bEnabled_ = true; |
---|
| 61 | this->bVisible_ = true; |
---|
| 62 | this->bAllowedByLOD_ = true; |
---|
| 63 | |
---|
| 64 | this->particleSystem_ = this->scenemanager_->createParticleSystem("particles" + getConvertedValue<unsigned int, std::string>(ParticleInterface::counter_s++), templateName); |
---|
| 65 | this->particleSystem_->setSpeedFactor(1.0f); |
---|
| 66 | //this->particleSystem_->setSpeedFactor(Orxonox::getInstance().getTimeFactor()); |
---|
| 67 | |
---|
| 68 | this->setDetailLevel((unsigned int)detaillevel); |
---|
| 69 | } |
---|
| 70 | |
---|
| 71 | ParticleInterface::~ParticleInterface() |
---|
[1563] | 72 | { |
---|
[2065] | 73 | this->particleSystem_->removeAllEmitters(); |
---|
| 74 | this->detachFromSceneNode(); |
---|
| 75 | this->scenemanager_->destroyParticleSystem(particleSystem_); |
---|
[1563] | 76 | } |
---|
[2065] | 77 | |
---|
| 78 | void ParticleInterface::addToSceneNode(Ogre::SceneNode* sceneNode) |
---|
[1563] | 79 | { |
---|
[2065] | 80 | if (this->sceneNode_) |
---|
| 81 | this->detachFromSceneNode(); |
---|
| 82 | |
---|
| 83 | this->sceneNode_ = sceneNode; |
---|
| 84 | this->sceneNode_->attachObject(this->particleSystem_); |
---|
[1563] | 85 | } |
---|
[1505] | 86 | |
---|
[2065] | 87 | void ParticleInterface::detachFromSceneNode() |
---|
| 88 | { |
---|
| 89 | if (this->sceneNode_) |
---|
| 90 | { |
---|
| 91 | this->sceneNode_->detachObject(this->particleSystem_); |
---|
| 92 | this->sceneNode_ = 0; |
---|
| 93 | } |
---|
| 94 | } |
---|
[1505] | 95 | |
---|
[2065] | 96 | Ogre::ParticleEmitter* ParticleInterface::createNewEmitter() |
---|
| 97 | { |
---|
| 98 | if (this->particleSystem_->getNumEmitters() > 0) |
---|
| 99 | { |
---|
| 100 | Ogre::ParticleEmitter* newemitter = this->particleSystem_->addEmitter(this->particleSystem_->getEmitter(0)->getType()); |
---|
| 101 | this->particleSystem_->getEmitter(0)->copyParametersTo(newemitter); |
---|
| 102 | return newemitter; |
---|
| 103 | } |
---|
| 104 | else |
---|
| 105 | return 0; |
---|
| 106 | } |
---|
| 107 | Ogre::ParticleEmitter* ParticleInterface::getEmitter(unsigned int emitterNr) const |
---|
| 108 | { |
---|
| 109 | if (emitterNr < this->particleSystem_->getNumEmitters()) |
---|
| 110 | return this->particleSystem_->getEmitter(emitterNr); |
---|
| 111 | else |
---|
| 112 | return 0; |
---|
| 113 | } |
---|
| 114 | void ParticleInterface::removeEmitter(unsigned int emitterNr) |
---|
| 115 | { |
---|
| 116 | if (emitterNr < this->particleSystem_->getNumEmitters()) |
---|
| 117 | this->particleSystem_->removeEmitter(emitterNr); |
---|
| 118 | } |
---|
| 119 | void ParticleInterface::removeAllEmitters() |
---|
| 120 | { |
---|
| 121 | this->particleSystem_->removeAllEmitters(); |
---|
| 122 | } |
---|
| 123 | unsigned int ParticleInterface::getNumEmitters() const |
---|
| 124 | { |
---|
| 125 | return this->particleSystem_->getNumEmitters(); |
---|
| 126 | } |
---|
[1505] | 127 | |
---|
[2065] | 128 | Ogre::ParticleAffector* ParticleInterface::addAffector(const std::string& name) |
---|
[1552] | 129 | { |
---|
[2065] | 130 | return this->particleSystem_->addAffector(name); |
---|
[1552] | 131 | } |
---|
[2065] | 132 | Ogre::ParticleAffector* ParticleInterface::getAffector(unsigned int affectorNr) const |
---|
| 133 | { |
---|
| 134 | if (affectorNr < this->particleSystem_->getNumAffectors()) |
---|
| 135 | return this->particleSystem_->getAffector(affectorNr); |
---|
| 136 | else |
---|
| 137 | return 0; |
---|
| 138 | } |
---|
| 139 | void ParticleInterface::removeAffector(unsigned int affectorNr) |
---|
| 140 | { |
---|
| 141 | if (affectorNr < this->particleSystem_->getNumAffectors()) |
---|
| 142 | this->particleSystem_->removeAffector(affectorNr); |
---|
| 143 | } |
---|
| 144 | void ParticleInterface::removeAllAffectors() |
---|
| 145 | { |
---|
| 146 | this->particleSystem_->removeAllAffectors(); |
---|
| 147 | } |
---|
| 148 | unsigned int ParticleInterface::getNumAffectors() const |
---|
| 149 | { |
---|
| 150 | return this->particleSystem_->getNumAffectors(); |
---|
| 151 | } |
---|
[1505] | 152 | |
---|
[2065] | 153 | void ParticleInterface::setEnabled(bool enable) |
---|
[1552] | 154 | { |
---|
[2065] | 155 | this->bEnabled_ = enable; |
---|
| 156 | |
---|
| 157 | for (unsigned int i = 0; i < this->particleSystem_->getNumEmitters(); i++) |
---|
| 158 | this->particleSystem_->getEmitter(i)->setEnabled(this->bEnabled_ && this->bAllowedByLOD_); |
---|
[1505] | 159 | } |
---|
| 160 | |
---|
[2065] | 161 | void ParticleInterface::setVisible(bool visible) |
---|
| 162 | { |
---|
| 163 | this->bVisible_ = visible; |
---|
[1505] | 164 | |
---|
[2065] | 165 | this->particleSystem_->setVisible(this->bVisible_ && this->bAllowedByLOD_); |
---|
| 166 | } |
---|
[1563] | 167 | |
---|
[2065] | 168 | void ParticleInterface::setDetailLevel(unsigned int level) |
---|
| 169 | { |
---|
| 170 | this->detaillevel_ = level; |
---|
| 171 | this->detailLevelChanged(GraphicsEngine::getInstance().getDetailLevelParticle()); |
---|
| 172 | } |
---|
[1563] | 173 | |
---|
[2065] | 174 | void ParticleInterface::detailLevelChanged(unsigned int newlevel) |
---|
| 175 | { |
---|
| 176 | if (newlevel >= (unsigned int)this->detaillevel_) |
---|
| 177 | this->bAllowedByLOD_ = true; |
---|
| 178 | else |
---|
| 179 | this->bAllowedByLOD_ = false; |
---|
[1563] | 180 | |
---|
[2065] | 181 | this->updateVisibility(); |
---|
| 182 | } |
---|
[1505] | 183 | |
---|
[2065] | 184 | void ParticleInterface::updateVisibility() |
---|
| 185 | { |
---|
| 186 | this->setEnabled(this->isEnabled()); |
---|
| 187 | this->setVisible(this->isVisible()); |
---|
| 188 | } |
---|
[1505] | 189 | |
---|
[2065] | 190 | void ParticleInterface::setSpeedFactor(float factor) |
---|
| 191 | { |
---|
| 192 | //this->particleSystem_->setSpeedFactor(Orxonox::getInstance().getTimeFactor() * factor); |
---|
| 193 | this->particleSystem_->setSpeedFactor(1.0f * factor); |
---|
| 194 | } |
---|
| 195 | float ParticleInterface::getSpeedFactor() const |
---|
| 196 | { |
---|
| 197 | //return (this->particleSystem_->getSpeedFactor() / Orxonox::getInstance().getTimeFactor()); |
---|
| 198 | return (this->particleSystem_->getSpeedFactor() / 1.0f); |
---|
| 199 | } |
---|
| 200 | |
---|
| 201 | bool ParticleInterface::getKeepParticlesInLocalSpace() const |
---|
| 202 | { |
---|
| 203 | return this->particleSystem_->getKeepParticlesInLocalSpace(); |
---|
| 204 | } |
---|
| 205 | void ParticleInterface::setKeepParticlesInLocalSpace(bool keep) |
---|
| 206 | { |
---|
| 207 | this->particleSystem_->setKeepParticlesInLocalSpace(keep); |
---|
| 208 | } |
---|
[1505] | 209 | } |
---|