Changeset 2065 for code/branches/objecthierarchy/src/orxonox/objects/worldentities/ParticleSpawner.cc
- Timestamp:
- Oct 30, 2008, 2:44:48 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/objecthierarchy/src/orxonox/objects/worldentities/ParticleSpawner.cc
r2027 r2065 30 30 #include "ParticleSpawner.h" 31 31 32 #include <OgreSceneManager.h>33 32 #include "core/CoreIncludes.h" 33 #include "core/EventIncludes.h" 34 34 #include "core/Executor.h" 35 #include "core/XMLPort.h" 35 36 #include "tools/ParticleInterface.h" 36 #include "GraphicsEngine.h"37 37 38 38 namespace orxonox … … 40 40 CreateFactory(ParticleSpawner); 41 41 42 ParticleSpawner::ParticleSpawner( )42 ParticleSpawner::ParticleSpawner(BaseObject* creator) : ParticleEmitter(creator) 43 43 { 44 44 RegisterObject(ParticleSpawner); 45 this->particle_ = 0;46 }47 45 48 ParticleSpawner::ParticleSpawner(const std::string& templateName, LODParticle::LOD detaillevel, float lifetime, float startdelay, float destroydelay, const Vector3& direction) 49 { 50 RegisterObject(ParticleSpawner); 51 this->setParticle(templateName, detaillevel, lifetime, startdelay, destroydelay, direction); 52 } 46 this->bAutostart_ = true; 47 this->bSuppressStart_ = false; 48 this->bAutoDestroy_ = true; 49 this->bForceDestroy_ = false; 50 this->bLoop_ = false; 51 this->startdelay_ = 0; 52 this->lifetime_ = 0; 53 this->destroydelay_ = 0; 53 54 54 void ParticleSpawner::setParticle(const std::string& templateName, LODParticle::LOD detaillevel, float lifetime, float startdelay, float destroydelay, const Vector3& direction) 55 { 56 ExecutorMember<ParticleSpawner>* executor = createExecutor(createFunctor(&ParticleSpawner::createParticleSpawner)); 57 this->destroydelay_ = destroydelay; 58 executor->setDefaultValues(lifetime); 59 this->timer_.setTimer(startdelay, false, this, executor); 60 this->particle_ = new ParticleInterface(templateName, detaillevel); 61 this->particle_->addToSceneNode(this->getNode()); 62 this->particle_->setEnabled(false); 63 if (direction != Vector3::ZERO) 64 { 65 this->particle_->getAllEmitters()->setDirection(direction); 66 } 55 this->startParticleSpawner(); 67 56 } 68 57 69 58 ParticleSpawner::~ParticleSpawner() 70 59 { 71 if (this->isInitialized() && this->particle_)72 {73 this->particle_->detachFromSceneNode();74 delete this->particle_;75 }76 };77 78 void ParticleSpawner::destroy()79 {80 this->setPosition(this->getNode()->getParent()->getPosition());81 this->getNode()->getParent()->removeChild(this->getNode());82 this->detachFromParent();83 if (this->particle_)84 this->particle_->setEnabled(false);85 if (!this->timer_.isActive() || this->timer_.getRemainingTime() > this->destroydelay_)86 this->timer_.setTimer(this->destroydelay_, false, this, createExecutor(createFunctor(&ParticleSpawner::destroyParticleSpawner)));87 60 } 88 61 89 void ParticleSpawner:: createParticleSpawner(float lifetime)62 void ParticleSpawner::XMLPort(Element& xmlelement, XMLPort::Mode mode) 90 63 { 91 this->particle_->setEnabled(true); 92 if (lifetime != 0) 93 this->timer_.setTimer(lifetime, false, this, createExecutor(createFunctor(&ParticleSpawner::destroyParticleSpawner))); 64 SUPER(ParticleSpawner, XMLPort, xmlelement, mode); 65 66 XMLPortParam(ParticleSpawner, "autostart", setAutoStart, getAutoStart, xmlelement, mode).defaultValues(true); 67 XMLPortParam(ParticleSpawner, "autodestroy", setDestroyAfterLife, getDestroyAfterLife, xmlelement, mode).defaultValues(false); 68 XMLPortParam(ParticleSpawner, "loop", setLoop, getLoop, xmlelement, mode).defaultValues(false); 69 XMLPortParam(ParticleSpawner, "lifetime", setLifetime, getLifetime, xmlelement, mode).defaultValues(0.0f); 70 XMLPortParam(ParticleSpawner, "startdelay", setStartdelay, getStartdelay, xmlelement, mode).defaultValues(0.0f); 71 XMLPortParam(ParticleSpawner, "destroydelay", setDestroydelay, getDestroydelay, xmlelement, mode).defaultValues(0.0f); 72 } 73 74 void ParticleSpawner::processEvent(Event& event) 75 { 76 SUPER(ParticleSpawner, processEvent, event); 77 78 SetEvent(ParticleSpawner, "spawn", spawn, event); 79 } 80 81 void ParticleSpawner::configure(float lifetime, float startdelay, float destroydelay, bool autodestroy) 82 { 83 this->bAutoDestroy_ = autodestroy; 84 this->startdelay_ = startdelay; 85 this->lifetime_ = lifetime; 86 this->destroydelay_ = destroydelay; 87 } 88 89 void ParticleSpawner::startParticleSpawner() 90 { 91 if (!this->particles_) 92 return; 93 94 this->particles_->setEnabled(false); 95 96 if (this->bForceDestroy_ || this->bSuppressStart_) 97 return; 98 99 this->timer_.setTimer(this->startdelay_, false, this, createExecutor(createFunctor(&ParticleSpawner::fireParticleSpawner))); 100 } 101 102 void ParticleSpawner::fireParticleSpawner() 103 { 104 this->particles_->setEnabled(true); 105 if (this->lifetime_ != 0) 106 this->timer_.setTimer(this->lifetime_, false, this, createExecutor(createFunctor(&ParticleSpawner::stopParticleSpawner))); 107 } 108 109 void ParticleSpawner::stopParticleSpawner() 110 { 111 this->particles_->setEnabled(false); 112 113 if (this->bAutoDestroy_ || this->bForceDestroy_) 114 { 115 this->setPosition(this->getWorldPosition()); 116 this->detachFromParent(); 117 118 if (!this->timer_.isActive() || this->timer_.getRemainingTime() > this->destroydelay_) 119 this->timer_.setTimer(this->destroydelay_, false, this, createExecutor(createFunctor(&ParticleSpawner::destroyParticleSpawner))); 120 } 121 else if (this->bLoop_) 122 { 123 this->timer_.setTimer(this->destroydelay_, false, this, createExecutor(createFunctor(&ParticleSpawner::startParticleSpawner))); 124 } 94 125 } 95 126 … … 98 129 delete this; 99 130 } 100 101 void ParticleSpawner::setVisible(bool visible)102 {103 if (this->particle_)104 this->particle_->setEnabled(visible);105 }106 131 }
Note: See TracChangeset
for help on using the changeset viewer.