Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/orxonox/particle/ParticleInterface.cc @ 1552

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

several improvements:

  • AI works properly now - add enemies with 'createEnemy x' where x is the number of enemies to add, default is 1. You can remove AI ships with 'killEnemies'.
  • Added new explosion (with smoke)
  • Added new projectile (with trail)
  • Added new thruster emitter
  • AI ships are destroyable - they start with 100 hp, each hit makes 15 hp damage, this value is configurable in the config-file: [Projectile] damage_
  • Added AI ship spawn and explosion effects
  • Property svn:eol-style set to native
File size: 4.6 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 "util/Convert.h"
42
43namespace orxonox
44{
45  unsigned int ParticleInterface::counter_s = 0;
46  ParticleInterface* ParticleInterface::currentParticleInterface_s = 0;
47
48  ParticleInterface::ParticleInterface(const std::string& templateName)
49  {
50    this->sceneNode_ = 0;
51    this->particleSystem_ = GraphicsEngine::getSingleton().getSceneManager()->createParticleSystem("particles" + getConvertedValue<unsigned int, std::string>(ParticleInterface::counter_s++), templateName);
52  }
53
54  ParticleInterface::~ParticleInterface()
55  {
56    this->particleSystem_->removeAllEmitters();
57    GraphicsEngine::getSingleton().getSceneManager()->destroyParticleSystem(particleSystem_);
58  }
59
60  void ParticleInterface::addToSceneNode(Ogre::SceneNode* sceneNode)
61  {
62    this->sceneNode_ = sceneNode;
63    this->sceneNode_->attachObject(this->particleSystem_);
64  }
65
66  void ParticleInterface::detachFromSceneNode()
67  {
68    if (this->sceneNode_)
69    {
70      this->sceneNode_->detachObject(this->particleSystem_);
71      this->sceneNode_ = 0;
72    }
73  }
74
75  Ogre::ParticleEmitter* ParticleInterface::createNewEmitter()
76  {
77    if (this->particleSystem_->getNumEmitters() > 0)
78    {
79      Ogre::ParticleEmitter* newemitter = this->particleSystem_->addEmitter(this->particleSystem_->getEmitter(0)->getType());
80      this->particleSystem_->getEmitter(0)->copyParametersTo(newemitter);
81      return newemitter;
82    }
83    else
84      return 0;
85  }
86  Ogre::ParticleEmitter* ParticleInterface::getEmitter(unsigned int emitterNr) const
87  {
88    if (emitterNr < this->particleSystem_->getNumEmitters())
89      return this->particleSystem_->getEmitter(emitterNr);
90    else
91      return 0;
92  }
93  void ParticleInterface::removeEmitter(unsigned int emitterNr)
94  {
95    if (emitterNr < this->particleSystem_->getNumEmitters())
96      this->particleSystem_->removeEmitter(emitterNr);
97  }
98  void ParticleInterface::removeAllEmitters()
99  {
100    this->particleSystem_->removeAllEmitters();
101  }
102  unsigned int ParticleInterface::getNumEmitters() const
103  {
104    return this->particleSystem_->getNumEmitters();
105  }
106
107  Ogre::ParticleAffector* ParticleInterface::addAffector(const std::string& name)
108  {
109    return this->particleSystem_->addAffector(name);
110  }
111  Ogre::ParticleAffector* ParticleInterface::getAffector(unsigned int affectorNr) const
112  {
113    if (affectorNr < this->particleSystem_->getNumAffectors())
114      return this->particleSystem_->getAffector(affectorNr);
115    else
116      return 0;
117  }
118  void ParticleInterface::removeAffector(unsigned int affectorNr)
119  {
120    if (affectorNr < this->particleSystem_->getNumAffectors())
121      this->particleSystem_->removeAffector(affectorNr);
122  }
123  void ParticleInterface::removeAllAffectors()
124  {
125    this->particleSystem_->removeAllAffectors();
126  }
127  unsigned int ParticleInterface::getNumAffectors() const
128  {
129    return this->particleSystem_->getNumAffectors();
130  }
131
132  void ParticleInterface::setEnabled(bool enable)
133  {
134    for (unsigned int i = 0; i < this->particleSystem_->getNumEmitters(); i++)
135      this->particleSystem_->getEmitter(i)->setEnabled(enable);
136  }
137
138  void ParticleInterface::setSpeedFactor(float factor)
139  {
140    this->particleSystem_->setSpeedFactor(factor);
141  }
142  float ParticleInterface::getSpeedFactor() const
143  {
144    return this->particleSystem_->getSpeedFactor();
145  }
146
147  bool ParticleInterface::getKeepParticlesInLocalSpace() const
148  {
149    return this->particleSystem_->getKeepParticlesInLocalSpace();
150  }
151  void ParticleInterface::setKeepParticlesInLocalSpace(bool keep)
152  {
153    this->particleSystem_->setKeepParticlesInLocalSpace(keep);
154  }
155}
Note: See TracBrowser for help on using the repository browser.