Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/core7/src/libraries/tools/ParticleInterface.cc @ 10382

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

found another unregistered class

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