Changeset 1552 for code/trunk/src/orxonox/particle
- Timestamp:
- Jun 6, 2008, 5:31:58 PM (17 years ago)
- Location:
- code/trunk/src/orxonox/particle
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk/src/orxonox/particle/ParticleInterface.cc
r1505 r1552 34 34 #include "ParticleInterface.h" 35 35 36 // #include <OgreParticleSystem.h> 37 // #include <Ogre.h> 38 // #include <OIS/OIS.h> 39 // #include <CEGUI/CEGUI.h> 40 // #include <CEGUIRenderer.h> 36 #include <OgreParticleSystem.h> 37 #include <OgreParticleEmitter.h> 38 #include <OgreSceneManager.h> 41 39 40 #include "GraphicsEngine.h" 41 #include "util/Convert.h" 42 42 43 namespace orxonox 44 { 45 unsigned int ParticleInterface::counter_s = 0; 46 ParticleInterface* ParticleInterface::currentParticleInterface_s = 0; 43 47 44 namespace orxonox { 45 using namespace Ogre; 46 47 ParticleInterface::ParticleInterface( SceneManager *sceneManager, std::string name, std::string templateName ) 48 ParticleInterface::ParticleInterface(const std::string& templateName) 48 49 { 49 sceneManager_ = sceneManager; 50 particleSystem_ = sceneManager->createParticleSystem(name, templateName); 51 52 //Variabeln einlesen, Emitter1_ ist Referenz-Emitter 53 velocity_ = particleSystem_->getSpeedFactor(); 54 colour_ = particleSystem_->getEmitter(0)->getColour(); 55 rate_ = particleSystem_->getEmitter(0)->getEmissionRate(); 56 distance_ = particleSystem_->getEmitter(0)->getTimeToLive(); 57 58 //Anzahl der Emitter 59 numberOfEmitters_ = particleSystem_->getNumEmitters(); 60 standardizeEmitters(); 50 this->sceneNode_ = 0; 51 this->particleSystem_ = GraphicsEngine::getSingleton().getSceneManager()->createParticleSystem("particles" + getConvertedValue<unsigned int, std::string>(ParticleInterface::counter_s++), templateName); 61 52 } 62 53 63 ParticleInterface::~ParticleInterface( void)54 ParticleInterface::~ParticleInterface() 64 55 { 65 while(particleSystem_->getNumEmitters()>0) 66 particleSystem_->removeEmitter(particleSystem_->getNumEmitters()-1); 67 sceneManager_->destroyParticleSystem(particleSystem_); 56 this->particleSystem_->removeAllEmitters(); 57 GraphicsEngine::getSingleton().getSceneManager()->destroyParticleSystem(particleSystem_); 68 58 } 69 59 70 void ParticleInterface:: standardizeEmitters(void)60 void ParticleInterface::addToSceneNode(Ogre::SceneNode* sceneNode) 71 61 { 72 //Abgleichen der anderen Emitter an die Variabeln 73 for (int i=0; i < numberOfEmitters_; i++) { 74 particleSystem_->getEmitter(i)->setColour( colour_ ); 75 particleSystem_->getEmitter(i)->setTimeToLive( distance_ ); 76 particleSystem_->getEmitter(i)->setEmissionRate( rate_ ); 77 } 78 62 this->sceneNode_ = sceneNode; 63 this->sceneNode_->attachObject(this->particleSystem_); 79 64 } 80 65 81 void ParticleInterface:: setVelocity(Real v)66 void ParticleInterface::detachFromSceneNode() 82 67 { 83 velocity_ = v; 84 //partikel anpassen 85 particleSystem_->setSpeedFactor(v); 86 } 87 88 void ParticleInterface::setRate(float r) 89 { 90 rate_ = r; 91 //partikel anpassen 92 for (int i=0; i<numberOfEmitters_; i++) { 93 particleSystem_->getEmitter(i)->setEmissionRate(rate_); 68 if (this->sceneNode_) 69 { 70 this->sceneNode_->detachObject(this->particleSystem_); 71 this->sceneNode_ = 0; 94 72 } 95 73 } 96 74 97 void ParticleInterface::setDistance(Real d)75 Ogre::ParticleEmitter* ParticleInterface::createNewEmitter() 98 76 { 99 distance_ = d; 100 //partikel anpassen 101 for (int i=0; i < numberOfEmitters_; i++) { 102 particleSystem_->getEmitter(i)->setTimeToLive(distance_); 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; 103 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(); 104 105 } 105 106 106 void ParticleInterface::setColour(ColourValue colour)107 Ogre::ParticleAffector* ParticleInterface::addAffector(const std::string& name) 107 108 { 108 colour_ = colour; 109 //partikel anpassen 110 for (int i=0; i < numberOfEmitters_; i++) { 111 particleSystem_->getEmitter(i)->setColour(colour_); 112 } 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(); 113 130 } 114 131 115 ParticleEmitter* ParticleInterface::getEmitter( int emitterNr)132 void ParticleInterface::setEnabled(bool enable) 116 133 { 117 if ( (emitterNr >= numberOfEmitters_) || (emitterNr < 0) ) return NULL;118 return particleSystem_->getEmitter(emitterNr);134 for (unsigned int i = 0; i < this->particleSystem_->getNumEmitters(); i++) 135 this->particleSystem_->getEmitter(i)->setEnabled(enable); 119 136 } 120 137 121 void ParticleInterface:: newEmitter ()138 void ParticleInterface::setSpeedFactor(float factor) 122 139 { 123 particleSystem_->addEmitter(particleSystem_->getEmitter(0)->getType()); 124 particleSystem_->getEmitter(0)->copyParametersTo( particleSystem_->getEmitter(numberOfEmitters_) ); 125 numberOfEmitters_++; 140 this->particleSystem_->setSpeedFactor(factor); 141 } 142 float ParticleInterface::getSpeedFactor() const 143 { 144 return this->particleSystem_->getSpeedFactor(); 126 145 } 127 146 128 // TODO check if this really works 129 Vector3 ParticleInterface::getPositionOfEmitter ( int emitterNr ) 147 bool ParticleInterface::getKeepParticlesInLocalSpace() const 130 148 { 131 return particleSystem_->getEmitter(emitterNr)->getPosition();149 return this->particleSystem_->getKeepParticlesInLocalSpace(); 132 150 } 133 134 void ParticleInterface::setDirection ( Vector3 direction ) 151 void ParticleInterface::setKeepParticlesInLocalSpace(bool keep) 135 152 { 136 for(int i=0; i < numberOfEmitters_; i++) { 137 particleSystem_->getEmitter(i)->setDirection(direction); 138 } 153 this->particleSystem_->setKeepParticlesInLocalSpace(keep); 139 154 } 140 141 void ParticleInterface::switchEnable(){142 bool enable=(!(particleSystem_->getEmitter(0)->getEnabled()));143 for(int i=0; i < numberOfEmitters_; i++) {144 particleSystem_->getEmitter(i)->setEnabled(enable);145 }146 }147 148 155 } -
code/trunk/src/orxonox/particle/ParticleInterface.h
r1505 r1552 21 21 * 22 22 * Author: 23 * Fabian 'x3n' Landau23 * ... 24 24 * Co-authors: 25 25 * ... … … 33 33 34 34 #include <string> 35 36 // #include "ParticleInterface.h"37 // #include <Ogre.h>38 // #include <OIS/OIS.h>39 // #include <CEGUI/CEGUI.h>40 // #include <CEGUIRenderer.h>41 #include <OgreParticleSystem.h>42 35 #include <OgreParticleEmitter.h> 43 #include <OgreSceneManager.h>44 36 45 37 #include "util/Math.h" 46 38 39 #define getAllEmitters() \ 40 storeThisAsCurrentParticleInterface(); \ 41 for (unsigned int i = 0; i < ParticleInterface::getCurrentParticleInterface()->getNumEmitters(); ++i) \ 42 ParticleInterface::getCurrentParticleInterface()->getEmitter(i) 47 43 48 44 namespace orxonox 49 45 { 50 51 46 class _OrxonoxExport ParticleInterface 52 47 { 53 public: 48 public: 49 ParticleInterface(const std::string& templateName); 50 ~ParticleInterface(); 54 51 55 ParticleInterface( Ogre::SceneManager *sceneManager, std::string name, std::string templateName );56 ~ParticleInterface( void );52 inline Ogre::ParticleSystem* getParticleSystem() const 53 { return this->particleSystem_; } 57 54 58 inline void addToSceneNode( Ogre::SceneNode* sceneNode ) 59 { sceneNode_ = sceneNode; sceneNode_->attachObject(particleSystem_);}; 60 inline void detachFromSceneNode( void ) 61 { sceneNode_->detachObject(particleSystem_); sceneNode_ = NULL;}; 55 void addToSceneNode(Ogre::SceneNode* sceneNode); 56 void detachFromSceneNode(); 62 57 63 Ogre::ParticleEmitter* getEmitter ( int emitterNr ); 64 void newEmitter ( void ); 58 Ogre::ParticleEmitter* createNewEmitter(); 59 Ogre::ParticleEmitter* getEmitter(unsigned int emitterNr) const; 60 void removeEmitter(unsigned int emitterNr); 61 void removeAllEmitters(); 62 unsigned int getNumEmitters() const; 65 63 66 Vector3 getPositionOfEmitter ( int emitterNr ); 67 inline void setPositionOfEmitter ( int emitterNr, Vector3 position ) 68 { particleSystem_->getEmitter(emitterNr)->setPosition(position); }; 64 Ogre::ParticleAffector* addAffector(const std::string& name); 65 Ogre::ParticleAffector* getAffector(unsigned int affectorNr) const; 66 void removeAffector(unsigned int affectorNr); 67 void removeAllAffectors(); 68 unsigned int getNumAffectors() const; 69 69 70 inline Vector3 getDirection ( void ) 71 { return particleSystem_->getEmitter(0)->getDirection(); }; 72 void setDirection ( Vector3 direction ); 70 float getSpeedFactor() const; 71 void setSpeedFactor(float factor); 72 bool getKeepParticlesInLocalSpace() const; 73 void setKeepParticlesInLocalSpace(bool keep); 73 74 74 inline Real getVelocity() 75 {return velocity_; }; 76 void setVelocity( Real v ); 75 void setEnabled(bool enable); 77 76 78 inline float getRate() 79 { return rate_; }; 80 void setRate( float r ); 77 inline void storeThisAsCurrentParticleInterface() 78 { ParticleInterface::currentParticleInterface_s = this; } 79 inline static ParticleInterface* getCurrentParticleInterface() 80 { return ParticleInterface::currentParticleInterface_s; } 81 81 82 inline Real getDistance() 83 { return distance_; }; 84 void setDistance( Real d ); 85 86 inline ColourValue getColour( void ) 87 {return colour_;}; 88 void setColour( ColourValue colour ); 89 90 void switchEnable(); 91 92 inline Ogre::ParticleSystem* getParticleSystem() 93 { return this->particleSystem_; }; 94 95 private: 96 Ogre::SceneNode *sceneNode_; 97 Ogre::SceneManager *sceneManager_; 98 Ogre::ParticleSystem *particleSystem_; 99 Real distance_; 100 Real velocity_; 101 float rate_; 102 ColourValue colour_; 103 int numberOfEmitters_; 104 105 void standardizeEmitters(); 82 private: 83 static ParticleInterface* currentParticleInterface_s; 84 static unsigned int counter_s; 85 Ogre::SceneNode* sceneNode_; 86 Ogre::ParticleSystem* particleSystem_; 106 87 }; 107 108 88 } 109 89
Note: See TracChangeset
for help on using the changeset viewer.