Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/orxonox/tools/ParticleInterface.cc @ 1555

Last change on this file since 1555 was 1555, checked in by landauf, 16 years ago
  • ParticleInterface uses Orxonox::getTimeFactor to make particle effects independend of gamespeed (but there's still a drawback with thrusters)
  • reduced OIS includes in input-related classes, changed OIS search and include to avoid conflicts with other versions of OIS (for example in Ogre). not yet tested on tardis.
  • Property svn:eol-style set to native
File size: 4.7 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>
[1505]39
[1552]40#include "GraphicsEngine.h"
[1555]41#include "Orxonox.h"
[1552]42#include "util/Convert.h"
[1505]43
[1552]44namespace orxonox
45{
46  unsigned int ParticleInterface::counter_s = 0;
47  ParticleInterface* ParticleInterface::currentParticleInterface_s = 0;
[1505]48
[1552]49  ParticleInterface::ParticleInterface(const std::string& templateName)
[1505]50  {
[1552]51    this->sceneNode_ = 0;
52    this->particleSystem_ = GraphicsEngine::getSingleton().getSceneManager()->createParticleSystem("particles" + getConvertedValue<unsigned int, std::string>(ParticleInterface::counter_s++), templateName);
[1555]53    this->particleSystem_->setSpeedFactor(Orxonox::getSingleton()->getTimeFactor());
[1505]54  }
55
[1552]56  ParticleInterface::~ParticleInterface()
[1505]57  {
[1552]58    this->particleSystem_->removeAllEmitters();
59    GraphicsEngine::getSingleton().getSceneManager()->destroyParticleSystem(particleSystem_);
[1505]60  }
61
[1552]62  void ParticleInterface::addToSceneNode(Ogre::SceneNode* sceneNode)
[1505]63  {
[1552]64    this->sceneNode_ = sceneNode;
65    this->sceneNode_->attachObject(this->particleSystem_);
[1505]66  }
67
[1552]68  void ParticleInterface::detachFromSceneNode()
[1505]69  {
[1552]70    if (this->sceneNode_)
71    {
72      this->sceneNode_->detachObject(this->particleSystem_);
73      this->sceneNode_ = 0;
74    }
[1505]75  }
76
[1552]77  Ogre::ParticleEmitter* ParticleInterface::createNewEmitter()
[1505]78  {
[1552]79    if (this->particleSystem_->getNumEmitters() > 0)
80    {
81      Ogre::ParticleEmitter* newemitter = this->particleSystem_->addEmitter(this->particleSystem_->getEmitter(0)->getType());
82      this->particleSystem_->getEmitter(0)->copyParametersTo(newemitter);
83      return newemitter;
[1505]84    }
[1552]85    else
86      return 0;
[1505]87  }
[1552]88  Ogre::ParticleEmitter* ParticleInterface::getEmitter(unsigned int emitterNr) const
[1505]89  {
[1552]90    if (emitterNr < this->particleSystem_->getNumEmitters())
91      return this->particleSystem_->getEmitter(emitterNr);
92    else
93      return 0;
[1505]94  }
[1552]95  void ParticleInterface::removeEmitter(unsigned int emitterNr)
[1505]96  {
[1552]97    if (emitterNr < this->particleSystem_->getNumEmitters())
98      this->particleSystem_->removeEmitter(emitterNr);
[1505]99  }
[1552]100  void ParticleInterface::removeAllEmitters()
[1505]101  {
[1552]102    this->particleSystem_->removeAllEmitters();
[1505]103  }
[1552]104  unsigned int ParticleInterface::getNumEmitters() const
105  {
106    return this->particleSystem_->getNumEmitters();
107  }
[1505]108
[1552]109  Ogre::ParticleAffector* ParticleInterface::addAffector(const std::string& name)
[1505]110  {
[1552]111    return this->particleSystem_->addAffector(name);
[1505]112  }
[1552]113  Ogre::ParticleAffector* ParticleInterface::getAffector(unsigned int affectorNr) const
114  {
115    if (affectorNr < this->particleSystem_->getNumAffectors())
116      return this->particleSystem_->getAffector(affectorNr);
117    else
118      return 0;
119  }
120  void ParticleInterface::removeAffector(unsigned int affectorNr)
121  {
122    if (affectorNr < this->particleSystem_->getNumAffectors())
123      this->particleSystem_->removeAffector(affectorNr);
124  }
125  void ParticleInterface::removeAllAffectors()
126  {
127    this->particleSystem_->removeAllAffectors();
128  }
129  unsigned int ParticleInterface::getNumAffectors() const
130  {
131    return this->particleSystem_->getNumAffectors();
132  }
[1505]133
[1552]134  void ParticleInterface::setEnabled(bool enable)
[1505]135  {
[1552]136    for (unsigned int i = 0; i < this->particleSystem_->getNumEmitters(); i++)
137      this->particleSystem_->getEmitter(i)->setEnabled(enable);
[1505]138  }
139
[1552]140  void ParticleInterface::setSpeedFactor(float factor)
[1505]141  {
[1555]142    this->particleSystem_->setSpeedFactor(Orxonox::getSingleton()->getTimeFactor() * factor);
[1505]143  }
[1552]144  float ParticleInterface::getSpeedFactor() const
145  {
146    return this->particleSystem_->getSpeedFactor();
147  }
[1505]148
[1552]149  bool ParticleInterface::getKeepParticlesInLocalSpace() const
150  {
151    return this->particleSystem_->getKeepParticlesInLocalSpace();
[1505]152  }
[1552]153  void ParticleInterface::setKeepParticlesInLocalSpace(bool keep)
154  {
155    this->particleSystem_->setKeepParticlesInLocalSpace(keep);
156  }
[1505]157}
Note: See TracBrowser for help on using the repository browser.