Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 3003 was 2896, checked in by landauf, 16 years ago

Merged gui branch back to trunk.

I did 2 small changes in IngameManager.cc on line 777 and 888 (yes, really), because const_reverse_iterator strangely doesn't work on MinGW.

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