Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 4008 was 3370, checked in by rgrieder, 15 years ago

Merged resource branch back to the trunk. Changes:

  • Automated graphics loading by evaluating whether a GameState requires it
  • Using native Tcl library (x3n)

Windows users: Update your dependency package!

  • 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
[2896]67        if (GameMode::showsGraphics())
[2171]68        {
69            try
70            {
[3280]71                this->particleSystem_ = this->scenemanager_->createParticleSystem("particles" + multi_cast<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
[3301]81        this->setDetailLevel(static_cast<unsigned int>(detaillevel));
[2087]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
[3370]93    void ParticleInterface::setConfigValues()
94    {
95        SetConfigValue(globalDetailLevel_, 2)
96            .description("O: off, 1: low, 2: normal, 3: high").callback(this, &ParticleInterface::detailLevelChanged);
97    }
98
[2087]99    Ogre::ParticleEmitter* ParticleInterface::createNewEmitter()
100    {
[2171]101        if (this->particleSystem_ && this->particleSystem_->getNumEmitters() > 0)
[2087]102        {
103            Ogre::ParticleEmitter* newemitter = this->particleSystem_->addEmitter(this->particleSystem_->getEmitter(0)->getType());
104            this->particleSystem_->getEmitter(0)->copyParametersTo(newemitter);
105            return newemitter;
106        }
107        else
108            return 0;
109    }
110    Ogre::ParticleEmitter* ParticleInterface::getEmitter(unsigned int emitterNr) const
111    {
[2171]112        if (this->particleSystem_ && (emitterNr < this->particleSystem_->getNumEmitters()))
[2087]113            return this->particleSystem_->getEmitter(emitterNr);
114        else
115            return 0;
116    }
117    void ParticleInterface::removeEmitter(unsigned int emitterNr)
118    {
[2171]119        if (this->particleSystem_ && (emitterNr < this->particleSystem_->getNumEmitters()))
[2087]120            this->particleSystem_->removeEmitter(emitterNr);
121    }
122    void ParticleInterface::removeAllEmitters()
123    {
[2171]124        if (this->particleSystem_)
125            this->particleSystem_->removeAllEmitters();
[2087]126    }
127    unsigned int ParticleInterface::getNumEmitters() const
128    {
[2171]129        if (this->particleSystem_)
130            return this->particleSystem_->getNumEmitters();
131        else
132            return 0;
[2087]133    }
[1505]134
[2087]135    Ogre::ParticleAffector* ParticleInterface::addAffector(const std::string& name)
[1552]136    {
[2171]137        if (this->particleSystem_)
138            return this->particleSystem_->addAffector(name);
139        else
140            return 0;
[1552]141    }
[3196]142    Ogre::ParticleAffector* ParticleInterface::getAffector(unsigned int affectorNr)
[2087]143    {
[2171]144        if (this->particleSystem_ && (affectorNr < this->particleSystem_->getNumAffectors()))
[2087]145            return this->particleSystem_->getAffector(affectorNr);
146        else
147            return 0;
148    }
149    void ParticleInterface::removeAffector(unsigned int affectorNr)
150    {
[2171]151        if (this->particleSystem_ && (affectorNr < this->particleSystem_->getNumAffectors()))
[2087]152            this->particleSystem_->removeAffector(affectorNr);
153    }
154    void ParticleInterface::removeAllAffectors()
155    {
[2171]156        if (this->particleSystem_)
157            this->particleSystem_->removeAllAffectors();
[2087]158    }
159    unsigned int ParticleInterface::getNumAffectors() const
160    {
[2171]161        if (this->particleSystem_)
162            return this->particleSystem_->getNumAffectors();
163        else
164            return 0;
[2087]165    }
[1505]166
[2087]167    void ParticleInterface::setEnabled(bool enable)
[1552]168    {
[2087]169        this->bEnabled_ = enable;
170
[2171]171        if (this->particleSystem_)
172            for (unsigned int i = 0; i < this->particleSystem_->getNumEmitters(); i++)
173                this->particleSystem_->getEmitter(i)->setEnabled(this->bEnabled_ && this->bAllowedByLOD_);
[1505]174    }
175
[2087]176    void ParticleInterface::setVisible(bool visible)
177    {
178        this->bVisible_ = visible;
[1505]179
[2171]180        if (this->particleSystem_)
181            this->particleSystem_->setVisible(this->bVisible_ && this->bAllowedByLOD_);
[2087]182    }
[1563]183
[2087]184    void ParticleInterface::setDetailLevel(unsigned int level)
185    {
186        this->detaillevel_ = level;
[2896]187        if (GameMode::showsGraphics())
[3370]188            this->detailLevelChanged();
[2087]189    }
[1563]190
[3370]191    void ParticleInterface::detailLevelChanged()
[2087]192    {
[3370]193        if (this->globalDetailLevel_ >= this->detaillevel_)
[2087]194            this->bAllowedByLOD_ = true;
195        else
196            this->bAllowedByLOD_ = false;
[1563]197
[2087]198        this->updateVisibility();
199    }
[1505]200
[2087]201    void ParticleInterface::updateVisibility()
202    {
203        this->setEnabled(this->isEnabled());
204        this->setVisible(this->isVisible());
205    }
[1505]206
[2087]207    void ParticleInterface::setSpeedFactor(float factor)
208    {
[2662]209        this->speedFactor_ = factor;
210
[2171]211        if (this->particleSystem_)
[2662]212            this->particleSystem_->setSpeedFactor(factor * this->getTimeFactor());
[2087]213    }
[2662]214    void ParticleInterface::changedTimeFactor(float factor_new, float factor_old)
[2087]215    {
[2662]216        this->setSpeedFactor(this->speedFactor_);
[2087]217    }
218
219    bool ParticleInterface::getKeepParticlesInLocalSpace() const
220    {
[2171]221        if (this->particleSystem_)
222            return this->particleSystem_->getKeepParticlesInLocalSpace();
223        else
224            return false;
[2087]225    }
226    void ParticleInterface::setKeepParticlesInLocalSpace(bool keep)
227    {
[2171]228        if (this->particleSystem_)
229            this->particleSystem_->setKeepParticlesInLocalSpace(keep);
[2087]230    }
[1505]231}
Note: See TracBrowser for help on using the repository browser.