Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 1636 was 1608, checked in by landauf, 16 years ago
  • added a backlight to all SpaceShips, leaving a trail behind (configurable)
  • changed some lines in SpaceShipAI, AI seems to be more fair now…
  • fixed a bug in Math.cc algorithms to calculate radar positions and AI movement (division by zero and acos of 1.000001)
  • added destroy() and destroydelay to ParticleSpawner, so the smoketrail of a destroyed enemy stays visible for some seconds
  • added 2 lines to Orxonox.cc to make the length of the backlight-trail independend of the gamespeed

########################
# !!! MEDIA UPDATE !!! #
########################

  • Property svn:eol-style set to native
File size: 3.7 KB
Line 
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
32#include "core/CoreIncludes.h"
33#include "core/Executor.h"
34#include "tools/ParticleInterface.h"
35#include "GraphicsEngine.h"
36
37namespace orxonox
38{
39    CreateFactory(ParticleSpawner);
40
41    ParticleSpawner::ParticleSpawner()
42    {
43        RegisterObject(ParticleSpawner);
44        this->particle_ = 0;
45    }
46
47    ParticleSpawner::ParticleSpawner(const std::string& templateName, LODParticle::LOD detaillevel, float lifetime, float startdelay, float destroydelay, const Vector3& direction)
48    {
49        RegisterObject(ParticleSpawner);
50        this->setParticle(templateName, detaillevel, lifetime, startdelay, destroydelay, direction);
51    }
52
53    void ParticleSpawner::setParticle(const std::string& templateName, LODParticle::LOD detaillevel, float lifetime, float startdelay, float destroydelay, const Vector3& direction)
54    {
55        ExecutorMember<ParticleSpawner>* executor = createExecutor(createFunctor(&ParticleSpawner::createParticleSpawner));
56        this->destroydelay_ = destroydelay;
57        executor->setDefaultValues(lifetime);
58        this->timer_.setTimer(startdelay, false, this, executor);
59        this->particle_ = new ParticleInterface(templateName, detaillevel);
60        this->particle_->addToSceneNode(this->getNode());
61        this->particle_->setEnabled(false);
62        if (direction != Vector3::ZERO)
63        {
64            this->particle_->getAllEmitters()->setDirection(direction);
65        }
66    }
67
68    ParticleSpawner::~ParticleSpawner()
69    {
70        if (this->isInitialized() && this->particle_)
71        {
72            this->particle_->detachFromSceneNode();
73            delete this->particle_;
74        }
75    };
76
77    void ParticleSpawner::destroy()
78    {
79        this->setPosition(this->getNode()->getParent()->getPosition());
80        this->getNode()->getParent()->removeChild(this->getNode());
81        GraphicsEngine::getSingleton().getSceneManager()->getRootSceneNode()->addChild(this->getNode());
82        if (this->particle_)
83            this->particle_->setEnabled(false);
84        if (!this->timer_.isActive() || this->timer_.getRemainingTime() > this->destroydelay_)
85            this->timer_.setTimer(this->destroydelay_, false, this, createExecutor(createFunctor(&ParticleSpawner::destroyParticleSpawner)));
86    }
87
88    void ParticleSpawner::createParticleSpawner(float lifetime)
89    {
90        this->particle_->setEnabled(true);
91        if (lifetime != 0)
92            this->timer_.setTimer(lifetime, false, this, createExecutor(createFunctor(&ParticleSpawner::destroyParticleSpawner)));
93    }
94
95    void ParticleSpawner::destroyParticleSpawner()
96    {
97        delete this;
98    }
99
100    void ParticleSpawner::setVisible(bool visible)
101    {
102        if (this->particle_)
103            this->particle_->setEnabled(visible);
104    }
105}
Note: See TracBrowser for help on using the repository browser.