Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/weapons/src/orxonox/tools/ParticleInterface.cc @ 3063

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