Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/core7/src/libraries/tools/ParticleInterface.cc @ 10396

Last change on this file since 10396 was 10382, checked in by landauf, 9 years ago

found another unregistered class

  • Property svn:eol-style set to native
File size: 7.4 KB
RevLine 
[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/**
[2171]30* @file
[1505]31* @brief class to control praticle effects
32*/
33
34#include "ParticleInterface.h"
35
[3196]36#include <cassert>
37#include <string>
[1552]38#include <OgreParticleSystem.h>
39#include <OgreParticleEmitter.h>
40#include <OgreSceneManager.h>
[1505]41
[3196]42#include "util/Convert.h"
43#include "util/Math.h"
44#include "core/CoreIncludes.h"
[9667]45#include "core/config/ConfigValueIncludes.h"
[3196]46#include "core/GameMode.h"
[1505]47
[1552]48namespace orxonox
49{
[2087]50    unsigned int ParticleInterface::counter_s = 0;
51    ParticleInterface* ParticleInterface::currentParticleInterface_s = 0;
[1505]52
[10382]53    RegisterAbstractClass(ParticleInterface).inheritsFrom<TimeFactorListener>();
54
[3280]55    ParticleInterface::ParticleInterface(Ogre::SceneManager* scenemanager, const std::string& templateName, LODParticle::Value detaillevel)
[2087]56    {
[2662]57        RegisterObject(ParticleInterface);
[1563]58
[2087]59        assert(scenemanager);
[1563]60
[2087]61        this->scenemanager_ = scenemanager;
[2171]62        this->particleSystem_ = 0;
[2087]63
64        this->bEnabled_ = true;
65        this->bVisible_ = true;
66        this->bAllowedByLOD_ = true;
[2662]67        this->speedFactor_ = 1.0f;
[2087]68
[6417]69        this->setDetailLevel(static_cast<unsigned int>(detaillevel));
70
71        this->setConfigValues();
72
[2896]73        if (GameMode::showsGraphics())
[2171]74        {
75            try
76            {
[3280]77                this->particleSystem_ = this->scenemanager_->createParticleSystem("particles" + multi_cast<std::string>(ParticleInterface::counter_s++), templateName);
[2662]78                this->setSpeedFactor(1.0f);
[2171]79            }
80            catch (...)
81            {
[8858]82                orxout(internal_error) << "Couldn't load particle system \"" << templateName << '"' << endl;
[2171]83                this->particleSystem_ = 0;
84            }
85        }
[2087]86    }
87
88    ParticleInterface::~ParticleInterface()
[1563]89    {
[2171]90        if (this->particleSystem_)
91        {
92            this->particleSystem_->removeAllEmitters();
93            this->scenemanager_->destroyParticleSystem(this->particleSystem_);
94        }
[1563]95    }
[2087]96
[3370]97    void ParticleInterface::setConfigValues()
98    {
[7166]99        SetConfigValueExternal(globalDetailLevel_, "GraphicsSettings", "particlesDetailLevel", 2)
100            .description("O: off, 1: low, 2: normal, 3: high")
101            .callback(this, &ParticleInterface::detailLevelChanged);
[3370]102    }
103
[2087]104    Ogre::ParticleEmitter* ParticleInterface::createNewEmitter()
105    {
[2171]106        if (this->particleSystem_ && this->particleSystem_->getNumEmitters() > 0)
[2087]107        {
108            Ogre::ParticleEmitter* newemitter = this->particleSystem_->addEmitter(this->particleSystem_->getEmitter(0)->getType());
109            this->particleSystem_->getEmitter(0)->copyParametersTo(newemitter);
110            return newemitter;
111        }
112        else
113            return 0;
114    }
115    Ogre::ParticleEmitter* ParticleInterface::getEmitter(unsigned int emitterNr) const
116    {
[2171]117        if (this->particleSystem_ && (emitterNr < this->particleSystem_->getNumEmitters()))
[2087]118            return this->particleSystem_->getEmitter(emitterNr);
119        else
120            return 0;
121    }
122    void ParticleInterface::removeEmitter(unsigned int emitterNr)
123    {
[2171]124        if (this->particleSystem_ && (emitterNr < this->particleSystem_->getNumEmitters()))
[2087]125            this->particleSystem_->removeEmitter(emitterNr);
126    }
127    void ParticleInterface::removeAllEmitters()
128    {
[2171]129        if (this->particleSystem_)
130            this->particleSystem_->removeAllEmitters();
[2087]131    }
132    unsigned int ParticleInterface::getNumEmitters() const
133    {
[2171]134        if (this->particleSystem_)
135            return this->particleSystem_->getNumEmitters();
136        else
137            return 0;
[2087]138    }
[1505]139
[2087]140    Ogre::ParticleAffector* ParticleInterface::addAffector(const std::string& name)
[1552]141    {
[2171]142        if (this->particleSystem_)
143            return this->particleSystem_->addAffector(name);
144        else
145            return 0;
[1552]146    }
[3196]147    Ogre::ParticleAffector* ParticleInterface::getAffector(unsigned int affectorNr)
[2087]148    {
[2171]149        if (this->particleSystem_ && (affectorNr < this->particleSystem_->getNumAffectors()))
[2087]150            return this->particleSystem_->getAffector(affectorNr);
151        else
152            return 0;
153    }
154    void ParticleInterface::removeAffector(unsigned int affectorNr)
155    {
[2171]156        if (this->particleSystem_ && (affectorNr < this->particleSystem_->getNumAffectors()))
[2087]157            this->particleSystem_->removeAffector(affectorNr);
158    }
159    void ParticleInterface::removeAllAffectors()
160    {
[2171]161        if (this->particleSystem_)
162            this->particleSystem_->removeAllAffectors();
[2087]163    }
164    unsigned int ParticleInterface::getNumAffectors() const
165    {
[2171]166        if (this->particleSystem_)
167            return this->particleSystem_->getNumAffectors();
168        else
169            return 0;
[2087]170    }
[1505]171
[2087]172    void ParticleInterface::setEnabled(bool enable)
[1552]173    {
[2087]174        this->bEnabled_ = enable;
175
[2171]176        if (this->particleSystem_)
177            for (unsigned int i = 0; i < this->particleSystem_->getNumEmitters(); i++)
178                this->particleSystem_->getEmitter(i)->setEnabled(this->bEnabled_ && this->bAllowedByLOD_);
[1505]179    }
180
[2087]181    void ParticleInterface::setVisible(bool visible)
182    {
183        this->bVisible_ = visible;
[1505]184
[2171]185        if (this->particleSystem_)
186            this->particleSystem_->setVisible(this->bVisible_ && this->bAllowedByLOD_);
[2087]187    }
[1563]188
[2087]189    void ParticleInterface::setDetailLevel(unsigned int level)
190    {
191        this->detaillevel_ = level;
[2896]192        if (GameMode::showsGraphics())
[3370]193            this->detailLevelChanged();
[2087]194    }
[1563]195
[3370]196    void ParticleInterface::detailLevelChanged()
[2087]197    {
[3370]198        if (this->globalDetailLevel_ >= this->detaillevel_)
[2087]199            this->bAllowedByLOD_ = true;
200        else
201            this->bAllowedByLOD_ = false;
[1563]202
[2087]203        this->updateVisibility();
204    }
[1505]205
[2087]206    void ParticleInterface::updateVisibility()
207    {
208        this->setEnabled(this->isEnabled());
209        this->setVisible(this->isVisible());
210    }
[1505]211
[2087]212    void ParticleInterface::setSpeedFactor(float factor)
213    {
[2662]214        this->speedFactor_ = factor;
215
[2171]216        if (this->particleSystem_)
[2662]217            this->particleSystem_->setSpeedFactor(factor * this->getTimeFactor());
[2087]218    }
[2662]219    void ParticleInterface::changedTimeFactor(float factor_new, float factor_old)
[2087]220    {
[2662]221        this->setSpeedFactor(this->speedFactor_);
[2087]222    }
223
224    bool ParticleInterface::getKeepParticlesInLocalSpace() const
225    {
[2171]226        if (this->particleSystem_)
227            return this->particleSystem_->getKeepParticlesInLocalSpace();
228        else
229            return false;
[2087]230    }
231    void ParticleInterface::setKeepParticlesInLocalSpace(bool keep)
232    {
[2171]233        if (this->particleSystem_)
234            this->particleSystem_->setKeepParticlesInLocalSpace(keep);
[2087]235    }
[1505]236}
Note: See TracBrowser for help on using the repository browser.