Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/objecthierarchy/src/orxonox/tools/ParticleInterface.cc @ 2019

Last change on this file since 2019 was 2019, checked in by landauf, 16 years ago

many changes, most important: BaseObject takes now a pointer to it's creator which is needed to build a level hierarchy (with different scenes)

  • Property svn:eol-style set to native
File size: 5.8 KB
RevLine 
[1505]1/*
2*   ORXONOX - the hottest 3D action shooter ever to exist
3*
4*
5*   License notice:
6*
7*   This program is free software; you can redistribute it and/or
8*   modify it under the terms of the GNU General Public License
9*   as published by the Free Software Foundation; either version 2
10*   of the License, or (at your option) any later version.
11*
12*   This program is distributed in the hope that it will be useful,
13*   but WITHOUT ANY WARRANTY; without even the implied warranty of
14*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15*   GNU General Public License for more details.
16*
17*   You should have received a copy of the GNU General Public License
18*   along with this program; if not, write to the Free Software
19*   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20*
21*   Author:
22*      ...
23*   Co-authors:
24*      ...
25*
26*/
27
28/**
29* @file ParticleInterface.cc
30* @brief class to control praticle effects
31*/
32
33#include "OrxonoxStableHeaders.h"
34#include "ParticleInterface.h"
35
[1552]36#include <OgreParticleSystem.h>
37#include <OgreParticleEmitter.h>
38#include <OgreSceneManager.h>
[2019]39#include <cassert>
[1505]40
[1552]41#include "GraphicsEngine.h"
[1563]42#include "core/CoreIncludes.h"
[1552]43#include "util/Convert.h"
[1505]44
[1552]45namespace orxonox
46{
47  unsigned int ParticleInterface::counter_s = 0;
48  ParticleInterface* ParticleInterface::currentParticleInterface_s = 0;
[1505]49
[2019]50  ParticleInterface::ParticleInterface(Ogre::SceneManager* scenemanager, const std::string& templateName, LODParticle::LOD detaillevel)
[1505]51  {
[1563]52    RegisterRootObject(ParticleInterface);
53
[2019]54    assert(scenemanager);
55
56    this->scenemanager_ = scenemanager;
[1552]57    this->sceneNode_ = 0;
[1563]58    this->bEnabled_ = true;
59    this->detaillevel_ = (unsigned int)detaillevel;
[2019]60    this->particleSystem_ = this->scenemanager_->createParticleSystem("particles" + getConvertedValue<unsigned int, std::string>(ParticleInterface::counter_s++), templateName);
[1755]61    //this->particleSystem_->setSpeedFactor(Orxonox::getInstance().getTimeFactor());
62    this->particleSystem_->setSpeedFactor(1.0f);
[1563]63
[1755]64    if (GraphicsEngine::getInstance().getDetailLevelParticle() < (unsigned int)this->detaillevel_)
[1563]65    {
66      this->bVisible_ = false;
67      this->updateVisibility();
68    }
69    else
70    {
71      this->bVisible_ = true;
72    }
[1505]73  }
74
[1552]75  ParticleInterface::~ParticleInterface()
[1505]76  {
[1552]77    this->particleSystem_->removeAllEmitters();
[2019]78    this->scenemanager_->destroyParticleSystem(particleSystem_);
[1505]79  }
80
[1552]81  void ParticleInterface::addToSceneNode(Ogre::SceneNode* sceneNode)
[1505]82  {
[1552]83    this->sceneNode_ = sceneNode;
84    this->sceneNode_->attachObject(this->particleSystem_);
[1505]85  }
86
[1552]87  void ParticleInterface::detachFromSceneNode()
[1505]88  {
[1552]89    if (this->sceneNode_)
90    {
91      this->sceneNode_->detachObject(this->particleSystem_);
92      this->sceneNode_ = 0;
93    }
[1505]94  }
95
[1552]96  Ogre::ParticleEmitter* ParticleInterface::createNewEmitter()
[1505]97  {
[1552]98    if (this->particleSystem_->getNumEmitters() > 0)
99    {
100      Ogre::ParticleEmitter* newemitter = this->particleSystem_->addEmitter(this->particleSystem_->getEmitter(0)->getType());
101      this->particleSystem_->getEmitter(0)->copyParametersTo(newemitter);
102      return newemitter;
[1505]103    }
[1552]104    else
105      return 0;
[1505]106  }
[1552]107  Ogre::ParticleEmitter* ParticleInterface::getEmitter(unsigned int emitterNr) const
[1505]108  {
[1552]109    if (emitterNr < this->particleSystem_->getNumEmitters())
110      return this->particleSystem_->getEmitter(emitterNr);
111    else
112      return 0;
[1505]113  }
[1552]114  void ParticleInterface::removeEmitter(unsigned int emitterNr)
[1505]115  {
[1552]116    if (emitterNr < this->particleSystem_->getNumEmitters())
117      this->particleSystem_->removeEmitter(emitterNr);
[1505]118  }
[1552]119  void ParticleInterface::removeAllEmitters()
[1505]120  {
[1552]121    this->particleSystem_->removeAllEmitters();
[1505]122  }
[1552]123  unsigned int ParticleInterface::getNumEmitters() const
124  {
125    return this->particleSystem_->getNumEmitters();
126  }
[1505]127
[1552]128  Ogre::ParticleAffector* ParticleInterface::addAffector(const std::string& name)
[1505]129  {
[1552]130    return this->particleSystem_->addAffector(name);
[1505]131  }
[1552]132  Ogre::ParticleAffector* ParticleInterface::getAffector(unsigned int affectorNr) const
133  {
134    if (affectorNr < this->particleSystem_->getNumAffectors())
135      return this->particleSystem_->getAffector(affectorNr);
136    else
137      return 0;
138  }
139  void ParticleInterface::removeAffector(unsigned int affectorNr)
140  {
141    if (affectorNr < this->particleSystem_->getNumAffectors())
142      this->particleSystem_->removeAffector(affectorNr);
143  }
144  void ParticleInterface::removeAllAffectors()
145  {
146    this->particleSystem_->removeAllAffectors();
147  }
148  unsigned int ParticleInterface::getNumAffectors() const
149  {
150    return this->particleSystem_->getNumAffectors();
151  }
[1505]152
[1552]153  void ParticleInterface::setEnabled(bool enable)
[1505]154  {
[1563]155    this->bEnabled_ = enable;
156    this->updateVisibility();
157  }
158
159  void ParticleInterface::detailLevelChanged(unsigned int newlevel)
160  {
161    if (newlevel >= (unsigned int)this->detaillevel_)
162      this->bVisible_ = true;
163    else
164      this->bVisible_ = false;
165
166    this->updateVisibility();
167  }
168
169  void ParticleInterface::updateVisibility()
170  {
[1552]171    for (unsigned int i = 0; i < this->particleSystem_->getNumEmitters(); i++)
[1563]172      this->particleSystem_->getEmitter(i)->setEnabled(this->bEnabled_ && this->bVisible_);
[1505]173  }
174
[1552]175  void ParticleInterface::setSpeedFactor(float factor)
[1505]176  {
[1755]177    //this->particleSystem_->setSpeedFactor(Orxonox::getInstance().getTimeFactor() * factor);
178    this->particleSystem_->setSpeedFactor(1.0f * factor);
[1505]179  }
[1552]180  float ParticleInterface::getSpeedFactor() const
181  {
[1755]182    //return (this->particleSystem_->getSpeedFactor() / Orxonox::getInstance().getTimeFactor());
183    return (this->particleSystem_->getSpeedFactor() / 1.0f);
[1552]184  }
[1505]185
[1552]186  bool ParticleInterface::getKeepParticlesInLocalSpace() const
187  {
188    return this->particleSystem_->getKeepParticlesInLocalSpace();
[1505]189  }
[1552]190  void ParticleInterface::setKeepParticlesInLocalSpace(bool keep)
191  {
192    this->particleSystem_->setKeepParticlesInLocalSpace(keep);
193  }
[1505]194}
Note: See TracBrowser for help on using the repository browser.