Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/presentation3/src/libraries/tools/ParticleInterface.cc @ 6916

Last change on this file since 6916 was 6417, checked in by rgrieder, 15 years ago

Merged presentation2 branch back to trunk.
Major new features:

  • Actual GUI with settings, etc.
  • Improved space ship steering (human interaction)
  • Rocket fire and more particle effects
  • Advanced sound framework
  • Property svn:eol-style set to native
File size: 7.2 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/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    ParticleInterface::ParticleInterface(Ogre::SceneManager* scenemanager, const std::string& templateName, LODParticle::Value detaillevel)
54    {
55        RegisterObject(ParticleInterface);
56
57        assert(scenemanager);
58
59        this->scenemanager_ = scenemanager;
60        this->particleSystem_ = 0;
61
62        this->bEnabled_ = true;
63        this->bVisible_ = true;
64        this->bAllowedByLOD_ = true;
65        this->speedFactor_ = 1.0f;
66
67        this->setDetailLevel(static_cast<unsigned int>(detaillevel));
68
69        this->setConfigValues();
70
71        if (GameMode::showsGraphics())
72        {
73            try
74            {
75                this->particleSystem_ = this->scenemanager_->createParticleSystem("particles" + multi_cast<std::string>(ParticleInterface::counter_s++), templateName);
76                this->setSpeedFactor(1.0f);
77            }
78            catch (...)
79            {
80                COUT(1) << "Error: Couln't load particle system \"" << templateName << '"' << std::endl;
81                this->particleSystem_ = 0;
82            }
83        }
84    }
85
86    ParticleInterface::~ParticleInterface()
87    {
88        if (this->particleSystem_)
89        {
90            this->particleSystem_->removeAllEmitters();
91            this->scenemanager_->destroyParticleSystem(this->particleSystem_);
92        }
93    }
94
95    void ParticleInterface::setConfigValues()
96    {
97        SetConfigValue(globalDetailLevel_, 2)
98            .description("O: off, 1: low, 2: normal, 3: high").callback(this, &ParticleInterface::detailLevelChanged);
99    }
100
101    Ogre::ParticleEmitter* ParticleInterface::createNewEmitter()
102    {
103        if (this->particleSystem_ && this->particleSystem_->getNumEmitters() > 0)
104        {
105            Ogre::ParticleEmitter* newemitter = this->particleSystem_->addEmitter(this->particleSystem_->getEmitter(0)->getType());
106            this->particleSystem_->getEmitter(0)->copyParametersTo(newemitter);
107            return newemitter;
108        }
109        else
110            return 0;
111    }
112    Ogre::ParticleEmitter* ParticleInterface::getEmitter(unsigned int emitterNr) const
113    {
114        if (this->particleSystem_ && (emitterNr < this->particleSystem_->getNumEmitters()))
115            return this->particleSystem_->getEmitter(emitterNr);
116        else
117            return 0;
118    }
119    void ParticleInterface::removeEmitter(unsigned int emitterNr)
120    {
121        if (this->particleSystem_ && (emitterNr < this->particleSystem_->getNumEmitters()))
122            this->particleSystem_->removeEmitter(emitterNr);
123    }
124    void ParticleInterface::removeAllEmitters()
125    {
126        if (this->particleSystem_)
127            this->particleSystem_->removeAllEmitters();
128    }
129    unsigned int ParticleInterface::getNumEmitters() const
130    {
131        if (this->particleSystem_)
132            return this->particleSystem_->getNumEmitters();
133        else
134            return 0;
135    }
136
137    Ogre::ParticleAffector* ParticleInterface::addAffector(const std::string& name)
138    {
139        if (this->particleSystem_)
140            return this->particleSystem_->addAffector(name);
141        else
142            return 0;
143    }
144    Ogre::ParticleAffector* ParticleInterface::getAffector(unsigned int affectorNr)
145    {
146        if (this->particleSystem_ && (affectorNr < this->particleSystem_->getNumAffectors()))
147            return this->particleSystem_->getAffector(affectorNr);
148        else
149            return 0;
150    }
151    void ParticleInterface::removeAffector(unsigned int affectorNr)
152    {
153        if (this->particleSystem_ && (affectorNr < this->particleSystem_->getNumAffectors()))
154            this->particleSystem_->removeAffector(affectorNr);
155    }
156    void ParticleInterface::removeAllAffectors()
157    {
158        if (this->particleSystem_)
159            this->particleSystem_->removeAllAffectors();
160    }
161    unsigned int ParticleInterface::getNumAffectors() const
162    {
163        if (this->particleSystem_)
164            return this->particleSystem_->getNumAffectors();
165        else
166            return 0;
167    }
168
169    void ParticleInterface::setEnabled(bool enable)
170    {
171        this->bEnabled_ = enable;
172
173        if (this->particleSystem_)
174            for (unsigned int i = 0; i < this->particleSystem_->getNumEmitters(); i++)
175                this->particleSystem_->getEmitter(i)->setEnabled(this->bEnabled_ && this->bAllowedByLOD_);
176    }
177
178    void ParticleInterface::setVisible(bool visible)
179    {
180        this->bVisible_ = visible;
181
182        if (this->particleSystem_)
183            this->particleSystem_->setVisible(this->bVisible_ && this->bAllowedByLOD_);
184    }
185
186    void ParticleInterface::setDetailLevel(unsigned int level)
187    {
188        this->detaillevel_ = level;
189        if (GameMode::showsGraphics())
190            this->detailLevelChanged();
191    }
192
193    void ParticleInterface::detailLevelChanged()
194    {
195        if (this->globalDetailLevel_ >= this->detaillevel_)
196            this->bAllowedByLOD_ = true;
197        else
198            this->bAllowedByLOD_ = false;
199
200        this->updateVisibility();
201    }
202
203    void ParticleInterface::updateVisibility()
204    {
205        this->setEnabled(this->isEnabled());
206        this->setVisible(this->isVisible());
207    }
208
209    void ParticleInterface::setSpeedFactor(float factor)
210    {
211        this->speedFactor_ = factor;
212
213        if (this->particleSystem_)
214            this->particleSystem_->setSpeedFactor(factor * this->getTimeFactor());
215    }
216    void ParticleInterface::changedTimeFactor(float factor_new, float factor_old)
217    {
218        this->setSpeedFactor(this->speedFactor_);
219    }
220
221    bool ParticleInterface::getKeepParticlesInLocalSpace() const
222    {
223        if (this->particleSystem_)
224            return this->particleSystem_->getKeepParticlesInLocalSpace();
225        else
226            return false;
227    }
228    void ParticleInterface::setKeepParticlesInLocalSpace(bool keep)
229    {
230        if (this->particleSystem_)
231            this->particleSystem_->setKeepParticlesInLocalSpace(keep);
232    }
233}
Note: See TracBrowser for help on using the repository browser.