Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/resource/src/orxonox/tools/ParticleInterface.cc @ 3338

Last change on this file since 3338 was 3336, checked in by rgrieder, 15 years ago

Moved Config value detailLevelParticle from GraphicsManager to ParticleInterface.
The resulting section name problem is to be resolved later. We've got a mess of config values anyway.

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