Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/presentation2/src/libraries/tools/ParticleInterface.cc @ 6518

Last change on this file since 6518 was 6394, checked in by rgrieder, 15 years ago

std::string tweaks:

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