Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/orxonox/tools/ParticleInterface.cc @ 3224

Last change on this file since 3224 was 3196, checked in by rgrieder, 15 years ago

Merged pch branch back to trunk.

  • Property svn:eol-style set to native
File size: 7.0 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"
45#include "core/GameMode.h"
[2896]46#include "GraphicsManager.h"
[1505]47
[1552]48namespace orxonox
49{
[2087]50    unsigned int ParticleInterface::counter_s = 0;
51    ParticleInterface* ParticleInterface::currentParticleInterface_s = 0;
[1505]52
[2087]53    ParticleInterface::ParticleInterface(Ogre::SceneManager* scenemanager, const std::string& templateName, LODParticle::LOD detaillevel)
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
[2896]67        if (GameMode::showsGraphics())
[2171]68        {
69            try
70            {
71                this->particleSystem_ = this->scenemanager_->createParticleSystem("particles" + getConvertedValue<unsigned int, std::string>(ParticleInterface::counter_s++), templateName);
[2662]72                this->setSpeedFactor(1.0f);
[2171]73            }
74            catch (...)
75            {
76                COUT(1) << "Error: Couln't load particle system \"" << templateName << "\"" << std::endl;
77                this->particleSystem_ = 0;
78            }
79        }
[2087]80
81        this->setDetailLevel((unsigned int)detaillevel);
82    }
83
84    ParticleInterface::~ParticleInterface()
[1563]85    {
[2171]86        if (this->particleSystem_)
87        {
88            this->particleSystem_->removeAllEmitters();
89            this->scenemanager_->destroyParticleSystem(this->particleSystem_);
90        }
[1563]91    }
[2087]92
93    Ogre::ParticleEmitter* ParticleInterface::createNewEmitter()
94    {
[2171]95        if (this->particleSystem_ && this->particleSystem_->getNumEmitters() > 0)
[2087]96        {
97            Ogre::ParticleEmitter* newemitter = this->particleSystem_->addEmitter(this->particleSystem_->getEmitter(0)->getType());
98            this->particleSystem_->getEmitter(0)->copyParametersTo(newemitter);
99            return newemitter;
100        }
101        else
102            return 0;
103    }
104    Ogre::ParticleEmitter* ParticleInterface::getEmitter(unsigned int emitterNr) const
105    {
[2171]106        if (this->particleSystem_ && (emitterNr < this->particleSystem_->getNumEmitters()))
[2087]107            return this->particleSystem_->getEmitter(emitterNr);
108        else
109            return 0;
110    }
111    void ParticleInterface::removeEmitter(unsigned int emitterNr)
112    {
[2171]113        if (this->particleSystem_ && (emitterNr < this->particleSystem_->getNumEmitters()))
[2087]114            this->particleSystem_->removeEmitter(emitterNr);
115    }
116    void ParticleInterface::removeAllEmitters()
117    {
[2171]118        if (this->particleSystem_)
119            this->particleSystem_->removeAllEmitters();
[2087]120    }
121    unsigned int ParticleInterface::getNumEmitters() const
122    {
[2171]123        if (this->particleSystem_)
124            return this->particleSystem_->getNumEmitters();
125        else
126            return 0;
[2087]127    }
[1505]128
[2087]129    Ogre::ParticleAffector* ParticleInterface::addAffector(const std::string& name)
[1552]130    {
[2171]131        if (this->particleSystem_)
132            return this->particleSystem_->addAffector(name);
133        else
134            return 0;
[1552]135    }
[3196]136    Ogre::ParticleAffector* ParticleInterface::getAffector(unsigned int affectorNr)
[2087]137    {
[2171]138        if (this->particleSystem_ && (affectorNr < this->particleSystem_->getNumAffectors()))
[2087]139            return this->particleSystem_->getAffector(affectorNr);
140        else
141            return 0;
142    }
143    void ParticleInterface::removeAffector(unsigned int affectorNr)
144    {
[2171]145        if (this->particleSystem_ && (affectorNr < this->particleSystem_->getNumAffectors()))
[2087]146            this->particleSystem_->removeAffector(affectorNr);
147    }
148    void ParticleInterface::removeAllAffectors()
149    {
[2171]150        if (this->particleSystem_)
151            this->particleSystem_->removeAllAffectors();
[2087]152    }
153    unsigned int ParticleInterface::getNumAffectors() const
154    {
[2171]155        if (this->particleSystem_)
156            return this->particleSystem_->getNumAffectors();
157        else
158            return 0;
[2087]159    }
[1505]160
[2087]161    void ParticleInterface::setEnabled(bool enable)
[1552]162    {
[2087]163        this->bEnabled_ = enable;
164
[2171]165        if (this->particleSystem_)
166            for (unsigned int i = 0; i < this->particleSystem_->getNumEmitters(); i++)
167                this->particleSystem_->getEmitter(i)->setEnabled(this->bEnabled_ && this->bAllowedByLOD_);
[1505]168    }
169
[2087]170    void ParticleInterface::setVisible(bool visible)
171    {
172        this->bVisible_ = visible;
[1505]173
[2171]174        if (this->particleSystem_)
175            this->particleSystem_->setVisible(this->bVisible_ && this->bAllowedByLOD_);
[2087]176    }
[1563]177
[2087]178    void ParticleInterface::setDetailLevel(unsigned int level)
179    {
180        this->detaillevel_ = level;
[2896]181        if (GameMode::showsGraphics())
182            this->detailLevelChanged(GraphicsManager::getInstance().getDetailLevelParticle());
[2087]183    }
[1563]184
[2087]185    void ParticleInterface::detailLevelChanged(unsigned int newlevel)
186    {
187        if (newlevel >= (unsigned int)this->detaillevel_)
188            this->bAllowedByLOD_ = true;
189        else
190            this->bAllowedByLOD_ = false;
[1563]191
[2087]192        this->updateVisibility();
193    }
[1505]194
[2087]195    void ParticleInterface::updateVisibility()
196    {
197        this->setEnabled(this->isEnabled());
198        this->setVisible(this->isVisible());
199    }
[1505]200
[2087]201    void ParticleInterface::setSpeedFactor(float factor)
202    {
[2662]203        this->speedFactor_ = factor;
204
[2171]205        if (this->particleSystem_)
[2662]206            this->particleSystem_->setSpeedFactor(factor * this->getTimeFactor());
[2087]207    }
[2662]208    void ParticleInterface::changedTimeFactor(float factor_new, float factor_old)
[2087]209    {
[2662]210        this->setSpeedFactor(this->speedFactor_);
[2087]211    }
212
213    bool ParticleInterface::getKeepParticlesInLocalSpace() const
214    {
[2171]215        if (this->particleSystem_)
216            return this->particleSystem_->getKeepParticlesInLocalSpace();
217        else
218            return false;
[2087]219    }
220    void ParticleInterface::setKeepParticlesInLocalSpace(bool keep)
221    {
[2171]222        if (this->particleSystem_)
223            this->particleSystem_->setKeepParticlesInLocalSpace(keep);
[2087]224    }
[1505]225}
Note: See TracBrowser for help on using the repository browser.