Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Oct 30, 2008, 2:44:48 AM (16 years ago)
Author:
landauf
Message:

added two more graphical classes, ParticleEmitter and ParticleSpawner

Location:
code/branches/objecthierarchy/src/orxonox
Files:
2 added
17 edited

Legend:

Unmodified
Added
Removed
  • code/branches/objecthierarchy/src/orxonox/CMakeLists.txt

    r2044 r2065  
    6262  objects/worldentities/CameraPosition.cc
    6363  objects/worldentities/SpawnPoint.cc
     64  objects/worldentities/ParticleEmitter.cc
     65  objects/worldentities/ParticleSpawner.cc
    6466#  objects/worldentities/Backlight.cc
    65 #  objects/worldentities/ParticleSpawner.cc
    6667
    6768  objects/worldentities/triggers/Trigger.cc
  • code/branches/objecthierarchy/src/orxonox/OrxonoxPrereqs.h

    r2044 r2065  
    9696    class BlinkingBillboard;
    9797    class Light;
     98    class Backlight;
     99    class ParticleEmitter;
     100    class ParticleSpawner;
    98101
    99102    class Camera;
     
    107110    class Controller;
    108111    class HumanController;
    109 
    110     class Backlight;
    111     class ParticleSpawner;
    112112
    113113    class Info;
  • code/branches/objecthierarchy/src/orxonox/objects/worldentities/Billboard.cc

    r2044 r2065  
    7676                this->billboard_.setBillboardSet(this->getScene()->getSceneManager(), this->material_, this->colour_, 1);
    7777                this->getNode()->attachObject(this->billboard_.getBillboardSet());
     78                this->billboard_.setVisible(this->isVisible());
    7879            }
    7980        }
     
    9091                this->billboard_.setBillboardSet(this->getScene()->getSceneManager(), this->material_, this->colour_, 1);
    9192                this->getNode()->attachObject(this->billboard_.getBillboardSet());
     93                this->billboard_.setVisible(this->isVisible());
    9294            }
    9395        }
  • code/branches/objecthierarchy/src/orxonox/objects/worldentities/BlinkingBillboard.cc

    r2063 r2065  
    3030#include "BlinkingBillboard.h"
    3131
     32#include "core/Core.h"
    3233#include "core/CoreIncludes.h"
    3334#include "core/XMLPort.h"
     35#include "util/Math.h"
    3436
    3537namespace orxonox
     
    4446        this->frequency_ = 1.0f;
    4547        this->phase_ = 0;
     48        this->bQuadratic_ = false;
    4649        this->time_ = 0;
    4750
     
    6063        XMLPortParam(BlinkingBillboard, "frequency", setFrequency, getFrequency, xmlelement, mode).defaultValues(1.0f);
    6164        XMLPortParam(BlinkingBillboard, "phase",     setPhase,     getPhase,     xmlelement, mode).defaultValues(Degree(0));
     65        XMLPortParam(BlinkingBillboard, "quadratic", setQuadratic, isQuadratic,  xmlelement, mode).defaultValues(false);
    6266    }
    6367
    6468    void BlinkingBillboard::registerVariables()
    6569    {
    66         REGISTERDATA(this->amplitude_, network::direction::toclient);
    67         REGISTERDATA(this->frequency_, network::direction::toclient);
    68         REGISTERDATA(this->phase_,     network::direction::toclient);
     70//        REGISTERDATA(this->amplitude_, network::direction::toclient);
     71//        REGISTERDATA(this->frequency_, network::direction::toclient);
     72//        REGISTERDATA(this->phase_,     network::direction::toclient);
    6973    }
    7074
    7175    void BlinkingBillboard::tick(float dt)
    7276    {
    73         this->time_ += dt;
    74         this->setScale(this->amplitude_ * sin((6.2831853 * this->time_ + this->phase_.valueRadians()) * this->frequency_));
     77        if (Core::isMaster())
     78        {
     79            this->time_ += dt;
     80            if (this->bQuadratic_)
     81                this->setScale(this->amplitude_ * square(sin((6.2831853 * this->time_ + this->phase_.valueRadians()) * this->frequency_)));
     82            else
     83                this->setScale(this->amplitude_ * sin((6.2831853 * this->time_ + this->phase_.valueRadians()) * this->frequency_));
     84        }
    7585    }
    7686}
  • code/branches/objecthierarchy/src/orxonox/objects/worldentities/BlinkingBillboard.h

    r2063 r2065  
    6262                { return this->phase_; }
    6363
     64            inline void setQuadratic(bool bQuadratic)
     65                { this->bQuadratic_ = bQuadratic; }
     66            inline bool isQuadratic() const
     67                { return this->bQuadratic_; }
     68
    6469        private:
    6570            float amplitude_;
    6671            float frequency_;
    6772            Degree phase_;
     73            bool bQuadratic_;
    6874            long double time_;
    6975    };
  • code/branches/objecthierarchy/src/orxonox/objects/worldentities/ControllableEntity.cc

    r2062 r2065  
    9595        XMLPortParam(ControllableEntity, "camerapositiontemplate", setCameraPositionTemplate, getCameraPositionTemkplate, xmlelement, mode);
    9696
    97         XMLPortObject(ControllableEntity, WorldEntity, "camerapositions", addCameraPosition, getCameraPosition, xmlelement, mode);
     97        XMLPortObject(ControllableEntity, CameraPosition, "camerapositions", addCameraPosition, getCameraPosition, xmlelement, mode);
    9898    }
    9999
     
    239239            else if (this->bControlled_)
    240240            {
    241                 COUT(2) << "setting client position" << endl;
     241//                COUT(2) << "setting client position" << endl;
    242242                this->client_velocity_ = this->velocity_;
    243243                this->client_position_ = this->node_->getPosition();
     
    249249    {
    250250        REGISTERSTRING(this->cameraPositionTemplate_, network::direction::toclient);
    251        
    252        
    253         REGISTERDATA(this->client_overwrite_,   network::direction::toserver);
    254         REGISTERDATA(this->server_overwrite_,   network::direction::toclient, new network::NetworkCallback<ControllableEntity>(this, &ControllableEntity::processOverwrite));
    255251
    256252        REGISTERDATA(this->server_position_,    network::direction::toclient, new network::NetworkCallback<ControllableEntity>(this, &ControllableEntity::processServerPosition));
     
    258254        REGISTERDATA(this->server_orientation_, network::direction::toclient, new network::NetworkCallback<ControllableEntity>(this, &ControllableEntity::processServerOrientation));
    259255
     256        REGISTERDATA(this->server_overwrite_,   network::direction::toclient, new network::NetworkCallback<ControllableEntity>(this, &ControllableEntity::processOverwrite));
     257        REGISTERDATA(this->client_overwrite_,   network::direction::toserver);
    260258
    261259        REGISTERDATA(this->client_position_,    network::direction::toserver, new network::NetworkCallback<ControllableEntity>(this, &ControllableEntity::processClientPosition));
     
    301299        if (this->server_overwrite_ == this->client_overwrite_)
    302300        {
    303             COUT(2) << "callback: setting client position" << endl;
     301//            COUT(2) << "callback: setting client position" << endl;
    304302            this->node_->setPosition(this->client_position_);
    305303            this->server_position_ = this->client_position_;
    306304        }
    307         else
    308           COUT(2) << "callback: not setting client position" << endl;
     305//        else
     306//          COUT(2) << "callback: not setting client position" << endl;
    309307    }
    310308
     
    458456        else if (this->bControlled_)
    459457        {
    460 //             this->node_->lookAt(target, relativeTo, localDirectionVector);
     458            this->node_->lookAt(target, relativeTo, localDirectionVector);
    461459            this->client_orientation_ = this->node_->getOrientation();
    462460        }
  • code/branches/objecthierarchy/src/orxonox/objects/worldentities/Light.cc

    r2044 r2065  
    165165        this->light_->setType(this->type_);
    166166    }
     167
     168    void Light::changedVisibility()
     169    {
     170        SUPER(Light, changedVisibility);
     171
     172        this->light_->setVisible(this->isVisible());
     173    }
    167174}
  • code/branches/objecthierarchy/src/orxonox/objects/worldentities/Light.h

    r2044 r2065  
    4949            void registerVariables();
    5050
     51            virtual void changedVisibility();
     52
    5153            inline Ogre::Light* getLight()
    5254                { return this->light_; }
  • code/branches/objecthierarchy/src/orxonox/objects/worldentities/Model.cc

    r2040 r2065  
    7676            this->getNode()->attachObject(this->mesh_.getEntity());
    7777            this->mesh_.getEntity()->setCastShadows(this->bCastShadows_);
     78            this->mesh_.setVisible(this->isVisible());
    7879        }
    7980    }
  • code/branches/objecthierarchy/src/orxonox/objects/worldentities/ParticleSpawner.cc

    r2027 r2065  
    3030#include "ParticleSpawner.h"
    3131
    32 #include <OgreSceneManager.h>
    3332#include "core/CoreIncludes.h"
     33#include "core/EventIncludes.h"
    3434#include "core/Executor.h"
     35#include "core/XMLPort.h"
    3536#include "tools/ParticleInterface.h"
    36 #include "GraphicsEngine.h"
    3737
    3838namespace orxonox
     
    4040    CreateFactory(ParticleSpawner);
    4141
    42     ParticleSpawner::ParticleSpawner()
     42    ParticleSpawner::ParticleSpawner(BaseObject* creator) : ParticleEmitter(creator)
    4343    {
    4444        RegisterObject(ParticleSpawner);
    45         this->particle_ = 0;
    46     }
    4745
    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;
    5354
    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();
    6756    }
    6857
    6958    ParticleSpawner::~ParticleSpawner()
    7059    {
    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)));
    8760    }
    8861
    89     void ParticleSpawner::createParticleSpawner(float lifetime)
     62    void ParticleSpawner::XMLPort(Element& xmlelement, XMLPort::Mode mode)
    9063    {
    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        }
    94125    }
    95126
     
    98129        delete this;
    99130    }
    100 
    101     void ParticleSpawner::setVisible(bool visible)
    102     {
    103         if (this->particle_)
    104             this->particle_->setEnabled(visible);
    105     }
    106131}
  • code/branches/objecthierarchy/src/orxonox/objects/worldentities/ParticleSpawner.h

    r2044 r2065  
    3232#include "OrxonoxPrereqs.h"
    3333
    34 #include "PositionableEntity.h"
     34#include "ParticleEmitter.h"
    3535#include "tools/Timer.h"
    3636
    3737namespace orxonox
    3838{
    39     class _OrxonoxExport ParticleSpawner : public PositionableEntity
     39    class _OrxonoxExport ParticleSpawner : public ParticleEmitter
    4040    {
    4141        public:
    42             ParticleSpawner();
    43             ParticleSpawner(const std::string& templateName, LODParticle::LOD detaillevel, float lifetime = 0, float startdelay = 0, float destroydelay = 0, const Vector3& direction = Vector3::ZERO);
     42            ParticleSpawner(BaseObject* creator);
    4443            virtual ~ParticleSpawner();
    45             void destroy();
    4644
    47             void setParticle(const std::string& templateName, LODParticle::LOD detaillevel, float lifetime = 0, float startdelay = 0, float destroydelay = 0, const Vector3& direction = Vector3::ZERO);
    48             inline ParticleInterface* getParticleInterface() const
    49                 { return this->particle_; }
     45            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
     46            virtual void processEvent(Event& event);
    5047
    51             void setVisible(bool visible);
     48            inline void destroy()
     49                { this->bForceDestroy_ = true; this->stopParticleSpawner(); }
     50            inline void spawn()
     51                { this->bSuppressStart_ = false; this->startParticleSpawner(); }
     52
     53            void configure(float lifetime = 0, float startdelay = 0, float destroydelay = 0, bool autodestroy = true);
     54
     55            inline void setAutoStart(bool autostart)
     56                { this->bAutostart_ = autostart; this->bSuppressStart_ = !autostart; }
     57            inline bool getAutoStart() const
     58                { return this->bAutostart_; }
     59
     60            inline void setDestroyAfterLife(bool destroy)
     61                { this->bAutoDestroy_ = destroy; }
     62            inline bool getDestroyAfterLife() const
     63                { return this->bAutoDestroy_; }
     64
     65            inline void setLoop(bool loop)
     66                { this->bLoop_ = loop; }
     67            inline bool getLoop() const
     68                { return this->bLoop_; }
     69
     70            inline void setLifetime(float lifetime)
     71                { this->lifetime_ = lifetime; this->startParticleSpawner(); }
     72            inline float getLifetime() const
     73                { return this->lifetime_; }
     74
     75            inline void setStartdelay(float startdelay)
     76                { this->startdelay_ = startdelay; this->startParticleSpawner(); }
     77            inline float getStartdelay() const
     78                { return this->startdelay_; }
     79
     80            inline void setDestroydelay(float destroydelay)
     81                { this->destroydelay_ = destroydelay; this->startParticleSpawner(); }
     82            inline float getDestroydelay() const
     83                { return this->destroydelay_; }
    5284
    5385        private:
    54             void createParticleSpawner(float lifetime);
     86            void startParticleSpawner();
     87            void fireParticleSpawner();
     88            void stopParticleSpawner();
    5589            void destroyParticleSpawner();
    5690
    5791            Timer<ParticleSpawner> timer_;
    58             ParticleInterface* particle_;
     92
     93            bool  bSuppressStart_;
     94            bool  bAutostart_;
     95            bool  bForceDestroy_;
     96            bool  bAutoDestroy_;
     97            bool  bLoop_;
     98            float startdelay_;
     99            float lifetime_;
    59100            float destroydelay_;
    60101    };
  • code/branches/objecthierarchy/src/orxonox/objects/worldentities/SpawnPoint.cc

    r2040 r2065  
    7878        {
    7979            this->getGametype()->pawnPreSpawn(entity);
     80
    8081            this->spawn(entity);
     82
    8183            if (this->template_)
    8284                entity->addTemplate(this->template_);
     85
    8386            entity->postSpawn();
     87
    8488            this->getGametype()->pawnPostSpawn(entity);
     89
     90            this->fireEvent();
    8591        }
    8692        return entity;
  • code/branches/objecthierarchy/src/orxonox/objects/worldentities/WorldEntity.h

    r2040 r2065  
    134134                { parent->attach(this); }
    135135            inline void detachFromParent()
    136                 { this->parent_->detach(this); }
     136                { if (this->parent_) { this->parent_->detach(this); } }
    137137            inline WorldEntity* getParent() const
    138138                { return this->parent_; }
  • code/branches/objecthierarchy/src/orxonox/objects/worldentities/triggers/Trigger.cc

    r2031 r2065  
    128128      this->bTriggered_ = (newState & 0x1);
    129129      this->bActive_ = newState & 2;
     130      this->fireEvent(this->bActive_);
    130131      this->stateChanges_.pop();
    131132      if (this->stateChanges_.size() != 0)
  • code/branches/objecthierarchy/src/orxonox/tools/Mesh.h

    r2019 r2065  
    2121 *
    2222 *   Author:
    23  *      ...
     23 *      Fabian 'x3n' Landau
    2424 *   Co-authors:
    2525 *      ...
  • code/branches/objecthierarchy/src/orxonox/tools/ParticleInterface.cc

    r2019 r2065  
    11/*
    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 */
     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 */
    2728
    2829/**
     
    4546namespace orxonox
    4647{
    47   unsigned int ParticleInterface::counter_s = 0;
    48   ParticleInterface* ParticleInterface::currentParticleInterface_s = 0;
    49 
    50   ParticleInterface::ParticleInterface(Ogre::SceneManager* scenemanager, const std::string& templateName, LODParticle::LOD detaillevel)
    51   {
    52     RegisterRootObject(ParticleInterface);
    53 
    54     assert(scenemanager);
    55 
    56     this->scenemanager_ = scenemanager;
    57     this->sceneNode_ = 0;
    58     this->bEnabled_ = true;
    59     this->detaillevel_ = (unsigned int)detaillevel;
    60     this->particleSystem_ = this->scenemanager_->createParticleSystem("particles" + getConvertedValue<unsigned int, std::string>(ParticleInterface::counter_s++), templateName);
    61     //this->particleSystem_->setSpeedFactor(Orxonox::getInstance().getTimeFactor());
    62     this->particleSystem_->setSpeedFactor(1.0f);
    63 
    64     if (GraphicsEngine::getInstance().getDetailLevelParticle() < (unsigned int)this->detaillevel_)
    65     {
    66       this->bVisible_ = false;
    67       this->updateVisibility();
    68     }
    69     else
    70     {
    71       this->bVisible_ = true;
    72     }
    73   }
    74 
    75   ParticleInterface::~ParticleInterface()
    76   {
    77     this->particleSystem_->removeAllEmitters();
    78     this->scenemanager_->destroyParticleSystem(particleSystem_);
    79   }
    80 
    81   void ParticleInterface::addToSceneNode(Ogre::SceneNode* sceneNode)
    82   {
    83     this->sceneNode_ = sceneNode;
    84     this->sceneNode_->attachObject(this->particleSystem_);
    85   }
    86 
    87   void ParticleInterface::detachFromSceneNode()
    88   {
    89     if (this->sceneNode_)
    90     {
    91       this->sceneNode_->detachObject(this->particleSystem_);
    92       this->sceneNode_ = 0;
    93     }
    94   }
    95 
    96   Ogre::ParticleEmitter* ParticleInterface::createNewEmitter()
    97   {
    98     if (this->particleSystem_->getNumEmitters() > 0)
    99     {
    100       Ogre::ParticleEmitter* newemitter = this->particleSystem_->addEmitter(this->particleSystem_->getEmitter(0)->getType());
    101       this->particleSystem_->getEmitter(0)->copyParametersTo(newemitter);
    102       return newemitter;
    103     }
    104     else
    105       return 0;
    106   }
    107   Ogre::ParticleEmitter* ParticleInterface::getEmitter(unsigned int emitterNr) const
    108   {
    109     if (emitterNr < this->particleSystem_->getNumEmitters())
    110       return this->particleSystem_->getEmitter(emitterNr);
    111     else
    112       return 0;
    113   }
    114   void ParticleInterface::removeEmitter(unsigned int emitterNr)
    115   {
    116     if (emitterNr < this->particleSystem_->getNumEmitters())
    117       this->particleSystem_->removeEmitter(emitterNr);
    118   }
    119   void ParticleInterface::removeAllEmitters()
    120   {
    121     this->particleSystem_->removeAllEmitters();
    122   }
    123   unsigned int ParticleInterface::getNumEmitters() const
    124   {
    125     return this->particleSystem_->getNumEmitters();
    126   }
    127 
    128   Ogre::ParticleAffector* ParticleInterface::addAffector(const std::string& name)
    129   {
    130     return this->particleSystem_->addAffector(name);
    131   }
    132   Ogre::ParticleAffector* ParticleInterface::getAffector(unsigned int affectorNr) const
    133   {
    134     if (affectorNr < this->particleSystem_->getNumAffectors())
    135       return this->particleSystem_->getAffector(affectorNr);
    136     else
    137       return 0;
    138   }
    139   void ParticleInterface::removeAffector(unsigned int affectorNr)
    140   {
    141     if (affectorNr < this->particleSystem_->getNumAffectors())
    142       this->particleSystem_->removeAffector(affectorNr);
    143   }
    144   void ParticleInterface::removeAllAffectors()
    145   {
    146     this->particleSystem_->removeAllAffectors();
    147   }
    148   unsigned int ParticleInterface::getNumAffectors() const
    149   {
    150     return this->particleSystem_->getNumAffectors();
    151   }
    152 
    153   void ParticleInterface::setEnabled(bool enable)
    154   {
    155     this->bEnabled_ = enable;
    156     this->updateVisibility();
    157   }
    158 
    159   void ParticleInterface::detailLevelChanged(unsigned int newlevel)
    160   {
    161     if (newlevel >= (unsigned int)this->detaillevel_)
    162       this->bVisible_ = true;
    163     else
    164       this->bVisible_ = false;
    165 
    166     this->updateVisibility();
    167   }
    168 
    169   void ParticleInterface::updateVisibility()
    170   {
    171     for (unsigned int i = 0; i < this->particleSystem_->getNumEmitters(); i++)
    172       this->particleSystem_->getEmitter(i)->setEnabled(this->bEnabled_ && this->bVisible_);
    173   }
    174 
    175   void ParticleInterface::setSpeedFactor(float factor)
    176   {
    177     //this->particleSystem_->setSpeedFactor(Orxonox::getInstance().getTimeFactor() * factor);
    178     this->particleSystem_->setSpeedFactor(1.0f * factor);
    179   }
    180   float ParticleInterface::getSpeedFactor() const
    181   {
    182     //return (this->particleSystem_->getSpeedFactor() / Orxonox::getInstance().getTimeFactor());
    183     return (this->particleSystem_->getSpeedFactor() / 1.0f);
    184   }
    185 
    186   bool ParticleInterface::getKeepParticlesInLocalSpace() const
    187   {
    188     return this->particleSystem_->getKeepParticlesInLocalSpace();
    189   }
    190   void ParticleInterface::setKeepParticlesInLocalSpace(bool keep)
    191   {
    192     this->particleSystem_->setKeepParticlesInLocalSpace(keep);
    193   }
     48    unsigned int ParticleInterface::counter_s = 0;
     49    ParticleInterface* ParticleInterface::currentParticleInterface_s = 0;
     50
     51    ParticleInterface::ParticleInterface(Ogre::SceneManager* scenemanager, const std::string& templateName, LODParticle::LOD detaillevel)
     52    {
     53        RegisterRootObject(ParticleInterface);
     54
     55        assert(scenemanager);
     56
     57        this->scenemanager_ = scenemanager;
     58        this->sceneNode_ = 0;
     59
     60        this->bEnabled_ = true;
     61        this->bVisible_ = true;
     62        this->bAllowedByLOD_ = true;
     63
     64        this->particleSystem_ = this->scenemanager_->createParticleSystem("particles" + getConvertedValue<unsigned int, std::string>(ParticleInterface::counter_s++), templateName);
     65        this->particleSystem_->setSpeedFactor(1.0f);
     66        //this->particleSystem_->setSpeedFactor(Orxonox::getInstance().getTimeFactor());
     67
     68        this->setDetailLevel((unsigned int)detaillevel);
     69    }
     70
     71    ParticleInterface::~ParticleInterface()
     72    {
     73        this->particleSystem_->removeAllEmitters();
     74        this->detachFromSceneNode();
     75        this->scenemanager_->destroyParticleSystem(particleSystem_);
     76    }
     77
     78    void ParticleInterface::addToSceneNode(Ogre::SceneNode* sceneNode)
     79    {
     80        if (this->sceneNode_)
     81            this->detachFromSceneNode();
     82
     83        this->sceneNode_ = sceneNode;
     84        this->sceneNode_->attachObject(this->particleSystem_);
     85    }
     86
     87    void ParticleInterface::detachFromSceneNode()
     88    {
     89        if (this->sceneNode_)
     90        {
     91            this->sceneNode_->detachObject(this->particleSystem_);
     92            this->sceneNode_ = 0;
     93        }
     94    }
     95
     96    Ogre::ParticleEmitter* ParticleInterface::createNewEmitter()
     97    {
     98        if (this->particleSystem_->getNumEmitters() > 0)
     99        {
     100            Ogre::ParticleEmitter* newemitter = this->particleSystem_->addEmitter(this->particleSystem_->getEmitter(0)->getType());
     101            this->particleSystem_->getEmitter(0)->copyParametersTo(newemitter);
     102            return newemitter;
     103        }
     104        else
     105            return 0;
     106    }
     107    Ogre::ParticleEmitter* ParticleInterface::getEmitter(unsigned int emitterNr) const
     108    {
     109        if (emitterNr < this->particleSystem_->getNumEmitters())
     110            return this->particleSystem_->getEmitter(emitterNr);
     111        else
     112            return 0;
     113    }
     114    void ParticleInterface::removeEmitter(unsigned int emitterNr)
     115    {
     116        if (emitterNr < this->particleSystem_->getNumEmitters())
     117            this->particleSystem_->removeEmitter(emitterNr);
     118    }
     119    void ParticleInterface::removeAllEmitters()
     120    {
     121        this->particleSystem_->removeAllEmitters();
     122    }
     123    unsigned int ParticleInterface::getNumEmitters() const
     124    {
     125        return this->particleSystem_->getNumEmitters();
     126    }
     127
     128    Ogre::ParticleAffector* ParticleInterface::addAffector(const std::string& name)
     129    {
     130        return this->particleSystem_->addAffector(name);
     131    }
     132    Ogre::ParticleAffector* ParticleInterface::getAffector(unsigned int affectorNr) const
     133    {
     134        if (affectorNr < this->particleSystem_->getNumAffectors())
     135            return this->particleSystem_->getAffector(affectorNr);
     136        else
     137            return 0;
     138    }
     139    void ParticleInterface::removeAffector(unsigned int affectorNr)
     140    {
     141        if (affectorNr < this->particleSystem_->getNumAffectors())
     142            this->particleSystem_->removeAffector(affectorNr);
     143    }
     144    void ParticleInterface::removeAllAffectors()
     145    {
     146        this->particleSystem_->removeAllAffectors();
     147    }
     148    unsigned int ParticleInterface::getNumAffectors() const
     149    {
     150        return this->particleSystem_->getNumAffectors();
     151    }
     152
     153    void ParticleInterface::setEnabled(bool enable)
     154    {
     155        this->bEnabled_ = enable;
     156
     157        for (unsigned int i = 0; i < this->particleSystem_->getNumEmitters(); i++)
     158            this->particleSystem_->getEmitter(i)->setEnabled(this->bEnabled_ && this->bAllowedByLOD_);
     159    }
     160
     161    void ParticleInterface::setVisible(bool visible)
     162    {
     163        this->bVisible_ = visible;
     164
     165        this->particleSystem_->setVisible(this->bVisible_ && this->bAllowedByLOD_);
     166    }
     167
     168    void ParticleInterface::setDetailLevel(unsigned int level)
     169    {
     170        this->detaillevel_ = level;
     171        this->detailLevelChanged(GraphicsEngine::getInstance().getDetailLevelParticle());
     172    }
     173
     174    void ParticleInterface::detailLevelChanged(unsigned int newlevel)
     175    {
     176        if (newlevel >= (unsigned int)this->detaillevel_)
     177            this->bAllowedByLOD_ = true;
     178        else
     179            this->bAllowedByLOD_ = false;
     180
     181        this->updateVisibility();
     182    }
     183
     184    void ParticleInterface::updateVisibility()
     185    {
     186        this->setEnabled(this->isEnabled());
     187        this->setVisible(this->isVisible());
     188    }
     189
     190    void ParticleInterface::setSpeedFactor(float factor)
     191    {
     192        //this->particleSystem_->setSpeedFactor(Orxonox::getInstance().getTimeFactor() * factor);
     193        this->particleSystem_->setSpeedFactor(1.0f * factor);
     194    }
     195    float ParticleInterface::getSpeedFactor() const
     196    {
     197        //return (this->particleSystem_->getSpeedFactor() / Orxonox::getInstance().getTimeFactor());
     198        return (this->particleSystem_->getSpeedFactor() / 1.0f);
     199    }
     200
     201    bool ParticleInterface::getKeepParticlesInLocalSpace() const
     202    {
     203        return this->particleSystem_->getKeepParticlesInLocalSpace();
     204    }
     205    void ParticleInterface::setKeepParticlesInLocalSpace(bool keep)
     206    {
     207        this->particleSystem_->setKeepParticlesInLocalSpace(keep);
     208    }
    194209}
  • code/branches/objecthierarchy/src/orxonox/tools/ParticleInterface.h

    r2019 r2065  
    2121 *
    2222 *   Author:
    23  *      ...
     23 *      Fabian 'x3n' Landau
    2424 *   Co-authors:
    2525 *      ...
     
    4545namespace orxonox
    4646{
    47   class _OrxonoxExport ParticleInterface : public OrxonoxClass
    48   {
    49     public:
    50       ParticleInterface(Ogre::SceneManager* scenemanager, const std::string& templateName, LODParticle::LOD detaillevel);
    51       ~ParticleInterface();
     47    class _OrxonoxExport ParticleInterface : public OrxonoxClass
     48    {
     49        public:
     50            ParticleInterface(Ogre::SceneManager* scenemanager, const std::string& templateName, LODParticle::LOD detaillevel);
     51            virtual ~ParticleInterface();
    5252
    53       inline Ogre::ParticleSystem* getParticleSystem() const
    54         { return this->particleSystem_; }
     53            inline Ogre::ParticleSystem* getParticleSystem() const
     54                { return this->particleSystem_; }
    5555
    56       void addToSceneNode(Ogre::SceneNode* sceneNode);
    57       void detachFromSceneNode();
     56            void addToSceneNode(Ogre::SceneNode* sceneNode);
     57            void detachFromSceneNode();
    5858
    59       Ogre::ParticleEmitter* createNewEmitter();
    60       Ogre::ParticleEmitter* getEmitter(unsigned int emitterNr) const;
    61       void removeEmitter(unsigned int emitterNr);
    62       void removeAllEmitters();
    63       unsigned int getNumEmitters() const;
     59            Ogre::ParticleEmitter* createNewEmitter();
     60            Ogre::ParticleEmitter* getEmitter(unsigned int emitterNr) const;
     61            void removeEmitter(unsigned int emitterNr);
     62            void removeAllEmitters();
     63            unsigned int getNumEmitters() const;
    6464
    65       Ogre::ParticleAffector* addAffector(const std::string& name);
    66       Ogre::ParticleAffector* getAffector(unsigned int affectorNr) const;
    67       void removeAffector(unsigned int affectorNr);
    68       void removeAllAffectors();
    69       unsigned int getNumAffectors() const;
     65            Ogre::ParticleAffector* addAffector(const std::string& name);
     66            Ogre::ParticleAffector* getAffector(unsigned int affectorNr) const;
     67            void removeAffector(unsigned int affectorNr);
     68            void removeAllAffectors();
     69            unsigned int getNumAffectors() const;
    7070
    71       float getSpeedFactor() const;
    72       void setSpeedFactor(float factor);
    73       bool getKeepParticlesInLocalSpace() const;
    74       void setKeepParticlesInLocalSpace(bool keep);
     71            float getSpeedFactor() const;
     72            void setSpeedFactor(float factor);
     73            bool getKeepParticlesInLocalSpace() const;
     74            void setKeepParticlesInLocalSpace(bool keep);
    7575
    76       void setEnabled(bool enable);
    77       void detailLevelChanged(unsigned int newlevel);
     76            void setEnabled(bool enable);
     77            inline bool isEnabled() const
     78                { return this->bEnabled_; }
    7879
    79       inline void storeThisAsCurrentParticleInterface()
    80         { ParticleInterface::currentParticleInterface_s = this; }
    81       inline static ParticleInterface* getCurrentParticleInterface()
    82         { return ParticleInterface::currentParticleInterface_s; }
     80            void setVisible(bool visible);
     81            inline bool isVisible() const
     82                { return this->bVisible_; }
    8383
    84     private:
    85       void updateVisibility();
     84            void detailLevelChanged(unsigned int newlevel);
     85            void setDetailLevel(unsigned int level);
    8686
    87       static ParticleInterface* currentParticleInterface_s;
    88       static unsigned int counter_s;
    89       Ogre::SceneNode* sceneNode_;
    90       Ogre::ParticleSystem* particleSystem_;
    91       bool bVisible_;
    92       bool bEnabled_;
    93       unsigned int detaillevel_;                            //!< Detail level of this particle effect (0: off, 1: low, 2: normal, 3: high)
    94       Ogre::SceneManager* scenemanager_;
    95   };
     87            inline void storeThisAsCurrentParticleInterface()
     88                { ParticleInterface::currentParticleInterface_s = this; }
     89            inline static ParticleInterface* getCurrentParticleInterface()
     90                { return ParticleInterface::currentParticleInterface_s; }
     91
     92        private:
     93            void updateVisibility();
     94
     95            static ParticleInterface* currentParticleInterface_s;
     96            static unsigned int       counter_s;
     97
     98            Ogre::SceneNode*          sceneNode_;
     99            Ogre::ParticleSystem*     particleSystem_;
     100            bool                      bVisible_;
     101            bool                      bEnabled_;
     102            bool                      bAllowedByLOD_;
     103            unsigned int              detaillevel_;     //!< Detail level of this particle effect (0: off, 1: low, 2: normal, 3: high)
     104            Ogre::SceneManager*       scenemanager_;
     105    };
    96106}
    97107
Note: See TracChangeset for help on using the changeset viewer.