Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/FICN/src/orxonox/particle/ParticleInterface.cc @ 646

Last change on this file since 646 was 646, checked in by landauf, 16 years ago
  • added very bad collision detection (presentation hack :D)
  • added explosions
  • fixed bug in ParticleInterface (it tried to delete SceneManager)

AND:

  • fixed one of the most amazing bugs ever! (the game crashed when I deleted an object through a timer-function. because the timer-functions is called by an iterator, the iterator indirectly delted its object. by overloading the (it++) operator, i was able to solve this problem)
File size: 5.0 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#include "ParticleInterface.h"
29// #include <OgreParticleSystem.h>
30// #include <Ogre.h>
31//#include <OIS/OIS.h>
32// #include <CEGUI/CEGUI.h>
33// #include <CEGUIRenderer.h>
34
35
36using namespace Ogre;
37
38namespace particle {
39
40  ParticleInterface::~ParticleInterface(void)
41  {
42std::cout << "blubiblub_1\n";
43    sceneManager_->destroyParticleSystem(particleSystem_);
44std::cout << "blubiblub_2\n";
45
46//    delete sceneNode_;
47//    delete particleSystem_;
48//    delete sceneManager_;
49  }
50
51  ParticleInterface::ParticleInterface( SceneManager *sceneManager, String name, String templateName )
52  {
53    sceneManager_ = sceneManager;
54    particleSystem_ = sceneManager->createParticleSystem(name, templateName);
55
56    //Variabeln einlesen, Emitter1_ ist Referenz-Emitter
57    velocity_ = particleSystem_->getSpeedFactor();
58    colour_ = particleSystem_->getEmitter(0)->getColour();
59    rate_ = particleSystem_->getEmitter(0)->getEmissionRate();
60    distance_ = particleSystem_->getEmitter(0)->getTimeToLive();
61
62    //Anzahl der Emitter
63    numberOfEmitters_ = particleSystem_->getNumEmitters();
64    standardizeEmitters();
65  }
66
67  void ParticleInterface::standardizeEmitters(void)
68  {
69    //Abgleichen der anderen Emitter an die Variabeln
70    for (int i=1; i<numberOfEmitters_; i++) {
71      particleSystem_->getEmitter(i)->setColour( colour_ );
72      particleSystem_->getEmitter(i)->setTimeToLive( distance_ );
73      particleSystem_->getEmitter(i)->setEmissionRate( rate_ );
74    }
75
76  }
77
78  void ParticleInterface::addToSceneNode( SceneNode* sceneNode )
79  {
80    sceneNode_ = sceneNode;
81    sceneNode_->attachObject(particleSystem_);
82  }
83
84  void ParticleInterface::detachFromSceneNode ( void )
85  {
86    sceneNode_->detachObject(particleSystem_);
87    sceneNode_ = NULL;
88  }
89
90  Real ParticleInterface::getVelocity()
91  {
92    return velocity_;
93  }
94
95  void ParticleInterface::setVelocity(Real v)
96  {
97    velocity_ = v;
98    //partikel anpassen
99    particleSystem_->setSpeedFactor(v);
100  }
101
102  int ParticleInterface::getRate()
103  {
104    return rate_;
105  }
106  void ParticleInterface::setRate(int r)
107  {
108    rate_ = r;
109    //partikel anpassen
110    for (int i=0; i<numberOfEmitters_; i++) {
111      particleSystem_->getEmitter(i)->setEmissionRate(rate_);
112    }
113  }
114
115  Real ParticleInterface::getDistance()
116  {
117    return distance_;
118  }
119
120  void ParticleInterface::setDistance(Real d)
121  {
122    distance_ = d;
123    //partikel anpassen
124    for (int i=0; i<numberOfEmitters_; i++) {
125      particleSystem_->getEmitter(i)->setTimeToLive(distance_);
126    }
127  }
128  ColourValue ParticleInterface::getColour()
129  {
130    return colour_;
131  }
132
133  void ParticleInterface::setColour(ColourValue colour)
134  {
135    colour_ = colour;
136    //partikel anpassen
137    for (int i=0; i<numberOfEmitters_; i++) {
138      particleSystem_->getEmitter(i)->setColour(colour_);
139    }
140  }
141
142  ParticleEmitter* ParticleInterface::getEmitter( int emitterNr )
143  {
144    if (!(emitterNr<numberOfEmitters_)) return NULL;
145    return particleSystem_->getEmitter(emitterNr);
146  }
147
148  void ParticleInterface::newEmitter ( void )
149  {
150    particleSystem_->addEmitter(particleSystem_->getEmitter(0)->getType());
151    numberOfEmitters_=numberOfEmitters_+1;
152    particleSystem_->getEmitter(0)->copyParametersTo( particleSystem_->getEmitter(numberOfEmitters_-1) );
153  }
154
155  void ParticleInterface::setPositionOfEmitter ( int emitterNr, Vector3 position )
156  {
157    particleSystem_->getEmitter(emitterNr)->setPosition(position);
158  }
159
160  Vector3 ParticleInterface::getPositionOfEmitter ( int emitterNr )
161  {
162    return particleSystem_->getEmitter(0)->getPosition();
163  }
164
165  void ParticleInterface::setDirection ( Vector3 direction )
166  {
167    for(int i=0; i<numberOfEmitters_; i++) {
168      particleSystem_->getEmitter(i)->setDirection(direction);
169    }
170  }
171
172
173  Vector3 ParticleInterface::getDirection ( void )
174  {
175    return particleSystem_->getEmitter(0)->getDirection();
176  }
177
178  void ParticleInterface::switchEnable(){
179    bool enable=(!(particleSystem_->getEmitter(0)->getEnabled()));
180    for(int i=0; i<numberOfEmitters_; i++) {
181      particleSystem_->getEmitter(i)->setEnabled(enable);
182    }
183  }
184
185}
Note: See TracBrowser for help on using the repository browser.