Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/libraries/tools/ParticleInterface.cc @ 11875

Last change on this file since 11875 was 11071, checked in by landauf, 9 years ago

merged branch cpp11_v3 back to trunk

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