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
Line 
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
36#include <OgreParticleSystem.h>
37#include <OgreParticleEmitter.h>
38#include <OgreSceneManager.h>
39
40#include "GraphicsEngine.h"
41#include "Orxonox.h"
42#include "util/Convert.h"
43
44namespace orxonox
45{
46  unsigned int ParticleInterface::counter_s = 0;
47  ParticleInterface* ParticleInterface::currentParticleInterface_s = 0;
48
49  ParticleInterface::ParticleInterface(const std::string& templateName)
50  {
51    this->sceneNode_ = 0;
52    this->particleSystem_ = GraphicsEngine::getSingleton().getSceneManager()->createParticleSystem("particles" + getConvertedValue<unsigned int, std::string>(ParticleInterface::counter_s++), templateName);
53    this->particleSystem_->setSpeedFactor(Orxonox::getSingleton()->getTimeFactor());
54  }
55
56  ParticleInterface::~ParticleInterface()
57  {
58    this->particleSystem_->removeAllEmitters();
59    GraphicsEngine::getSingleton().getSceneManager()->destroyParticleSystem(particleSystem_);
60  }
61
62  void ParticleInterface::addToSceneNode(Ogre::SceneNode* sceneNode)
63  {
64    this->sceneNode_ = sceneNode;
65    this->sceneNode_->attachObject(this->particleSystem_);
66  }
67
68  void ParticleInterface::detachFromSceneNode()
69  {
70    if (this->sceneNode_)
71    {
72      this->sceneNode_->detachObject(this->particleSystem_);
73      this->sceneNode_ = 0;
74    }
75  }
76
77  Ogre::ParticleEmitter* ParticleInterface::createNewEmitter()
78  {
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;
84    }
85    else
86      return 0;
87  }
88  Ogre::ParticleEmitter* ParticleInterface::getEmitter(unsigned int emitterNr) const
89  {
90    if (emitterNr < this->particleSystem_->getNumEmitters())
91      return this->particleSystem_->getEmitter(emitterNr);
92    else
93      return 0;
94  }
95  void ParticleInterface::removeEmitter(unsigned int emitterNr)
96  {
97    if (emitterNr < this->particleSystem_->getNumEmitters())
98      this->particleSystem_->removeEmitter(emitterNr);
99  }
100  void ParticleInterface::removeAllEmitters()
101  {
102    this->particleSystem_->removeAllEmitters();
103  }
104  unsigned int ParticleInterface::getNumEmitters() const
105  {
106    return this->particleSystem_->getNumEmitters();
107  }
108
109  Ogre::ParticleAffector* ParticleInterface::addAffector(const std::string& name)
110  {
111    return this->particleSystem_->addAffector(name);
112  }
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  }
133
134  void ParticleInterface::setEnabled(bool enable)
135  {
136    for (unsigned int i = 0; i < this->particleSystem_->getNumEmitters(); i++)
137      this->particleSystem_->getEmitter(i)->setEnabled(enable);
138  }
139
140  void ParticleInterface::setSpeedFactor(float factor)
141  {
142    this->particleSystem_->setSpeedFactor(Orxonox::getSingleton()->getTimeFactor() * factor);
143  }
144  float ParticleInterface::getSpeedFactor() const
145  {
146    return this->particleSystem_->getSpeedFactor();
147  }
148
149  bool ParticleInterface::getKeepParticlesInLocalSpace() const
150  {
151    return this->particleSystem_->getKeepParticlesInLocalSpace();
152  }
153  void ParticleInterface::setKeepParticlesInLocalSpace(bool keep)
154  {
155    this->particleSystem_->setKeepParticlesInLocalSpace(keep);
156  }
157}
Note: See TracBrowser for help on using the repository browser.