Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/orxonox/objects/ParticleSpawner.cc @ 2059

Last change on this file since 2059 was 1755, checked in by rgrieder, 16 years ago

merged gui back to trunk.
update the media repository!

  • Property svn:eol-style set to native
File size: 3.7 KB
RevLine 
[1552]1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *                    > www.orxonox.net <
4 *
5 *
6 *   License notice:
7 *
8 *   This program is free software; you can redistribute it and/or
9 *   modify it under the terms of the GNU General Public License
10 *   as published by the Free Software Foundation; either version 2
11 *   of the License, or (at your option) any later version.
12 *
13 *   This program is distributed in the hope that it will be useful,
14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 *   GNU General Public License for more details.
17 *
18 *   You should have received a copy of the GNU General Public License
19 *   along with this program; if not, write to the Free Software
20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 *
22 *   Author:
23 *      Fabian 'x3n' Landau
24 *   Co-authors:
25 *      ...
26 *
27 */
28
29#include "OrxonoxStableHeaders.h"
30#include "ParticleSpawner.h"
31
[1755]32#include <OgreSceneManager.h>
[1552]33#include "core/CoreIncludes.h"
34#include "core/Executor.h"
[1553]35#include "tools/ParticleInterface.h"
[1608]36#include "GraphicsEngine.h"
[1552]37
38namespace orxonox
39{
40    CreateFactory(ParticleSpawner);
41
[1559]42    ParticleSpawner::ParticleSpawner()
[1552]43    {
44        RegisterObject(ParticleSpawner);
[1602]45        this->particle_ = 0;
[1552]46    }
47
[1608]48    ParticleSpawner::ParticleSpawner(const std::string& templateName, LODParticle::LOD detaillevel, float lifetime, float startdelay, float destroydelay, const Vector3& direction)
[1552]49    {
50        RegisterObject(ParticleSpawner);
[1608]51        this->setParticle(templateName, detaillevel, lifetime, startdelay, destroydelay, direction);
[1602]52    }
[1552]53
[1608]54    void ParticleSpawner::setParticle(const std::string& templateName, LODParticle::LOD detaillevel, float lifetime, float startdelay, float destroydelay, const Vector3& direction)
[1602]55    {
[1552]56        ExecutorMember<ParticleSpawner>* executor = createExecutor(createFunctor(&ParticleSpawner::createParticleSpawner));
[1608]57        this->destroydelay_ = destroydelay;
[1552]58        executor->setDefaultValues(lifetime);
[1608]59        this->timer_.setTimer(startdelay, false, this, executor);
[1563]60        this->particle_ = new ParticleInterface(templateName, detaillevel);
[1552]61        this->particle_->addToSceneNode(this->getNode());
62        this->particle_->setEnabled(false);
63        if (direction != Vector3::ZERO)
64        {
65            this->particle_->getAllEmitters()->setDirection(direction);
66        }
67    }
68
69    ParticleSpawner::~ParticleSpawner()
70    {
[1602]71        if (this->isInitialized() && this->particle_)
[1552]72        {
73            this->particle_->detachFromSceneNode();
74            delete this->particle_;
75        }
76    };
77
[1608]78    void ParticleSpawner::destroy()
79    {
80        this->setPosition(this->getNode()->getParent()->getPosition());
81        this->getNode()->getParent()->removeChild(this->getNode());
[1755]82        GraphicsEngine::getInstance().getLevelSceneManager()->getRootSceneNode()->addChild(this->getNode());
[1608]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    }
88
[1552]89    void ParticleSpawner::createParticleSpawner(float lifetime)
90    {
91        this->particle_->setEnabled(true);
[1602]92        if (lifetime != 0)
93            this->timer_.setTimer(lifetime, false, this, createExecutor(createFunctor(&ParticleSpawner::destroyParticleSpawner)));
[1552]94    }
95
96    void ParticleSpawner::destroyParticleSpawner()
97    {
98        delete this;
99    }
[1602]100
101    void ParticleSpawner::setVisible(bool visible)
102    {
103        if (this->particle_)
104            this->particle_->setEnabled(visible);
105    }
[1552]106}
Note: See TracBrowser for help on using the repository browser.