Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Nov 1, 2008, 7:04:09 PM (16 years ago)
Author:
landauf
Message:

merged objecthierarchy branch back to trunk

Location:
code/trunk
Files:
2 deleted
9 edited

Legend:

Unmodified
Added
Removed
  • code/trunk

  • code/trunk/src/orxonox/tools/BillboardSet.cc

    r1755 r2087  
    3131
    3232#include <sstream>
     33#include <cassert>
    3334
    3435#include <OgreSceneManager.h>
     36#include <OgreBillboard.h>
    3537
    36 #include "GraphicsEngine.h"
    37 #include "util/Math.h"
     38#include "util/Convert.h"
     39#include "util/String.h"
    3840
    3941namespace orxonox
     
    4648    }
    4749
    48     void BillboardSet::setBillboardSet(const std::string& file, int count)
     50    BillboardSet::~BillboardSet()
    4951    {
    50         std::ostringstream name;
    51         name << (BillboardSet::billboardSetCounter_s++);
    52         this->billboardSet_ = GraphicsEngine::getInstance().getLevelSceneManager()->createBillboardSet("Billboard" + name.str(), count);
    53         this->billboardSet_->createBillboard(Vector3::ZERO);
    54         this->billboardSet_->setMaterialName(file);
     52        this->destroyBillboardSet();
    5553    }
    5654
    57     void BillboardSet::setBillboardSet(const std::string& file, const ColourValue& colour, int count)
     55    void BillboardSet::setBillboardSet(Ogre::SceneManager* scenemanager, const std::string& file, int count)
    5856    {
    59         std::ostringstream name;
    60         name << (BillboardSet::billboardSetCounter_s++);
    61         this->billboardSet_ = GraphicsEngine::getInstance().getLevelSceneManager()->createBillboardSet("Billboard" + name.str(), count);
    62         this->billboardSet_->createBillboard(Vector3::ZERO, colour);
    63         this->billboardSet_->setMaterialName(file);
     57        this->setBillboardSet(scenemanager, file, Vector3::ZERO, count);
    6458    }
    6559
    66     void BillboardSet::setBillboardSet(const std::string& file, const Vector3& position, int count)
     60    void BillboardSet::setBillboardSet(Ogre::SceneManager* scenemanager, const std::string& file, const ColourValue& colour, int count)
    6761    {
    68         std::ostringstream name;
    69         name << (BillboardSet::billboardSetCounter_s++);
    70         this->billboardSet_ = GraphicsEngine::getInstance().getLevelSceneManager()->createBillboardSet("Billboard" + name.str(), count);
    71         this->billboardSet_->createBillboard(position);
    72         this->billboardSet_->setMaterialName(file);
     62        this->setBillboardSet(scenemanager, file, colour, Vector3::ZERO, count);
    7363    }
    7464
    75     void BillboardSet::setBillboardSet(const std::string& file, const ColourValue& colour, const Vector3& position, int count)
     65    void BillboardSet::setBillboardSet(Ogre::SceneManager* scenemanager, const std::string& file, const Vector3& position, int count)
    7666    {
    77         std::ostringstream name;
    78         name << (BillboardSet::billboardSetCounter_s++);
    79         this->billboardSet_ = GraphicsEngine::getInstance().getLevelSceneManager()->createBillboardSet("Billboard" + name.str(), count);
    80         this->billboardSet_->createBillboard(position, colour);
    81         this->billboardSet_->setMaterialName(file);
     67        assert(scenemanager);
     68        this->destroyBillboardSet();
     69
     70        try
     71        {
     72            this->billboardSet_ = scenemanager->createBillboardSet("Billboard" + convertToString(BillboardSet::billboardSetCounter_s++), count);
     73            this->billboardSet_->createBillboard(position);
     74            this->billboardSet_->setMaterialName(file);
     75        }
     76        catch (...)
     77        {
     78            COUT(1) << "Error: Couln't load billboard \"" << file << "\"" << std::endl;
     79        }
     80
     81        this->scenemanager_ = scenemanager;
    8282    }
    8383
    84     BillboardSet::~BillboardSet()
     84    void BillboardSet::setBillboardSet(Ogre::SceneManager* scenemanager, const std::string& file, const ColourValue& colour, const Vector3& position, int count)
     85    {
     86        assert(scenemanager);
     87        this->destroyBillboardSet();
     88
     89        try
     90        {
     91            this->billboardSet_ = scenemanager->createBillboardSet("Billboard" + convertToString(BillboardSet::billboardSetCounter_s++), count);
     92            this->billboardSet_->createBillboard(position, colour);
     93            this->billboardSet_->setMaterialName(file);
     94        }
     95        catch (...)
     96        {
     97            COUT(1) << "Error: Couln't load billboard \"" << file << "\"" << std::endl;
     98        }
     99
     100        this->scenemanager_ = scenemanager;
     101    }
     102
     103    void BillboardSet::destroyBillboardSet()
     104    {
     105        if (this->billboardSet_ && this->scenemanager_)
     106            this->scenemanager_->destroyBillboardSet(this->billboardSet_);
     107    }
     108
     109    const std::string& BillboardSet::getName() const
    85110    {
    86111        if (this->billboardSet_)
    87             GraphicsEngine::getInstance().getLevelSceneManager()->destroyBillboardSet(this->billboardSet_);
     112            return this->billboardSet_->getName();
     113        else
     114            return BLANKSTRING;
     115    }
     116
     117    void BillboardSet::setVisible(bool visible)
     118    {
     119        if (this->billboardSet_)
     120            this->billboardSet_->setVisible(visible);
     121    }
     122
     123    bool BillboardSet::getVisible() const
     124    {
     125        if (this->billboardSet_)
     126            return this->billboardSet_->getVisible();
     127        else
     128            return false;
     129    }
     130
     131    void BillboardSet::setColour(const ColourValue& colour)
     132    {
     133        if (this->billboardSet_)
     134        {
     135            for (int i = 0; i < this->billboardSet_->getNumBillboards(); ++i)
     136                this->billboardSet_->getBillboard(i)->setColour(colour);
     137        }
     138    }
     139
     140    const ColourValue& BillboardSet::getColour() const
     141    {
     142        if (this->billboardSet_ && this->billboardSet_->getNumBillboards() > 0)
     143        {
     144            return this->billboardSet_->getBillboard(0)->getColour();
     145        }
     146        else
     147            return ColourValue::White;
     148    }
     149
     150    void BillboardSet::setMaterial(const std::string& material)
     151    {
     152        if (this->billboardSet_)
     153            this->billboardSet_->setMaterialName(material);
     154    }
     155
     156    const std::string& BillboardSet::getMaterial() const
     157    {
     158        if (this->billboardSet_)
     159            return this->billboardSet_->getMaterialName();
     160        else
     161            return BLANKSTRING;
    88162    }
    89163}
  • code/trunk/src/orxonox/tools/BillboardSet.h

    r1602 r2087  
    4444            BillboardSet();
    4545            ~BillboardSet();
    46             void setBillboardSet(const std::string& file, int count = 1);
    47             void setBillboardSet(const std::string& file, const ColourValue& colour, int count = 1);
    48             void setBillboardSet(const std::string& file, const Vector3& position, int count = 1);
    49             void setBillboardSet(const std::string& file, const ColourValue& colour, const Vector3& position, int count = 1);
     46
     47            void setBillboardSet(Ogre::SceneManager* scenemanager, const std::string& file, int count = 1);
     48            void setBillboardSet(Ogre::SceneManager* scenemanager, const std::string& file, const ColourValue& colour, int count = 1);
     49            void setBillboardSet(Ogre::SceneManager* scenemanager, const std::string& file, const Vector3& position, int count = 1);
     50            void setBillboardSet(Ogre::SceneManager* scenemanager, const std::string& file, const ColourValue& colour, const Vector3& position, int count = 1);
    5051
    5152            inline Ogre::BillboardSet* getBillboardSet()
    5253                { return this->billboardSet_; }
    5354
    54             inline const std::string& getName() const
    55                 { return this->billboardSet_->getName(); }
     55            const std::string& getName() const;
    5656
    57             inline void setVisible(bool visible)
    58                 { this->billboardSet_->setVisible(visible); }
    59             inline bool getVisible() const
    60                 { return this->billboardSet_->getVisible(); }
     57            void setVisible(bool visible);
     58            bool getVisible() const;
     59
     60            void setColour(const ColourValue& colour);
     61            const ColourValue& getColour() const;
     62
     63            void setMaterial(const std::string& material);
     64            const std::string& getMaterial() const;
    6165
    6266        private:
     67            void destroyBillboardSet();
     68
    6369            static unsigned int billboardSetCounter_s;
    6470            Ogre::BillboardSet* billboardSet_;
     71            Ogre::SceneManager* scenemanager_;
    6572    };
    6673}
  • code/trunk/src/orxonox/tools/Mesh.cc

    r1755 r2087  
    3232#include <sstream>
    3333#include <OgreSceneManager.h>
    34 #include "GraphicsEngine.h"
    35 #include "Settings.h"
     34#include <cassert>
     35
     36#include "core/Core.h"
     37#include "util/Convert.h"
     38#include "util/String.h"
    3639
    3740namespace orxonox
     
    3942    unsigned int Mesh::meshCounter_s = 0;
    4043
    41     Mesh::Mesh() :
    42       entity_(0)
     44    Mesh::Mesh()
    4345    {
    44     }
    45 
    46     void Mesh::setMesh(const std::string& file)
    47     {
    48         std::ostringstream name;
    49         name << (Mesh::meshCounter_s++);
    50         if (Settings::showsGraphics())
    51             this->entity_ = GraphicsEngine::getInstance().getLevelSceneManager()->createEntity("Mesh" + name.str(), file);
     46        this->entity_ = 0;
     47        this->bCastShadows_ = true;
    5248    }
    5349
    5450    Mesh::~Mesh()
    5551    {
    56         if (this->entity_ && Settings::showsGraphics())
    57             GraphicsEngine::getInstance().getLevelSceneManager()->destroyEntity(this->entity_);
     52        if (this->entity_ && this->scenemanager_)
     53            this->scenemanager_->destroyEntity(this->entity_);
     54    }
     55
     56    void Mesh::setMeshSource(Ogre::SceneManager* scenemanager, const std::string& meshsource)
     57    {
     58        assert(scenemanager);
     59
     60        this->scenemanager_ = scenemanager;
     61
     62        if (this->entity_)
     63            this->scenemanager_->destroyEntity(this->entity_);
     64
     65        if (Core::showsGraphics())
     66        {
     67            try
     68            {
     69                this->entity_ = this->scenemanager_->createEntity("Mesh" + convertToString(Mesh::meshCounter_s++), meshsource);
     70                this->entity_->setCastShadows(this->bCastShadows_);
     71            }
     72            catch (...)
     73            {
     74                COUT(1) << "Error: Couln't load mesh \"" << meshsource << "\"" << std::endl;
     75            }
     76        }
     77    }
     78
     79    void Mesh::setCastShadows(bool bCastShadows)
     80    {
     81        this->bCastShadows_ = bCastShadows;
     82        if (this->entity_)
     83            this->entity_->setCastShadows(this->bCastShadows_);
     84    }
     85
     86    const std::string& Mesh::getName() const
     87    {
     88        if (this->entity_)
     89            return this->entity_->getName();
     90        else
     91            return BLANKSTRING;
     92    }
     93
     94    void Mesh::setVisible(bool bVisible)
     95    {
     96        if (this->entity_)
     97            this->entity_->setVisible(bVisible);
     98    }
     99
     100    bool Mesh::isVisible() const
     101    {
     102        if (this->entity_)
     103            return this->entity_->getVisible();
     104        else
     105            return false;
    58106    }
    59107}
  • code/trunk/src/orxonox/tools/Mesh.h

    r1627 r2087  
    2121 *
    2222 *   Author:
    23  *      ...
     23 *      Fabian 'x3n' Landau
    2424 *   Co-authors:
    2525 *      ...
     
    3333
    3434#include <string>
    35 
    3635#include <OgreEntity.h>
    3736
     
    4342            Mesh();
    4443            ~Mesh();
    45             void setMesh(const std::string& file);
     44
     45            void setMeshSource(Ogre::SceneManager* scenemanager, const std::string& file);
    4646
    4747            inline Ogre::Entity* getEntity()
    4848                { return this->entity_; }
    4949
    50             inline const std::string& getName() const
    51                 { return this->entity_->getName(); }
     50            const std::string& getName() const;
    5251
    53             inline void setVisible(bool visible)
    54                 { if (this->entity_) this->entity_->setVisible(visible); }
    55             inline bool getVisible() const
    56                 { if (this->entity_) return this->entity_->getVisible(); else return false; }
     52            void setVisible(bool bVisible);
     53            bool isVisible() const;
     54
     55            void setCastShadows(bool bCastShadows);
     56            inline bool getCastShadows() const
     57                { return this->bCastShadows_; }
    5758
    5859        private:
    5960            static unsigned int meshCounter_s;
    6061            Ogre::Entity* entity_;
     62            bool bCastShadows_;
     63            Ogre::SceneManager* scenemanager_;
    6164    };
    6265}
  • code/trunk/src/orxonox/tools/ParticleInterface.cc

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

    r1563 r2087  
    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(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   };
     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    };
    95106}
    96107
  • code/trunk/src/orxonox/tools/Timer.cc

    r1755 r2087  
    9292        this->bLoop_ = false;
    9393        this->bActive_ = false;
     94        this->bKillAfterCall_ = false;
    9495
    9596        this->time_ = 0;
     
    111112    void TimerBase::run() const
    112113    {
     114        bool temp = this->bKillAfterCall_; // to avoid errors with bKillAfterCall_=false and an exutors which destroy the timer
     115
    113116        (*this->executor_)();
     117
     118        if (temp)
     119            delete this;
    114120    }
    115121
     
    136142            {
    137143                // It's time to call the function
    138                 if (this->bLoop_)
     144                if (this->bLoop_ && !this->bKillAfterCall_)
    139145                {
    140146                    this->time_ += this->interval_; // Q: Why '+=' and not '='? A: Think about it. It's more accurate like that. Seriously.
  • code/trunk/src/orxonox/tools/Timer.h

    r1755 r2087  
    116116            TimerBase();
    117117
    118             Executor* executor_; //!< The executor of the function that should be called when the time expires
    119 
    120             long long interval_; //!< The time-interval in micro seconds
    121             bool bLoop_;         //!< If true, the function gets called every 'interval' seconds
    122             bool bActive_;       //!< If true, the Timer ticks and calls the function if the time's up
    123 
    124             long long time_;     //!< Internal variable, counting the time till the next function-call
     118            Executor* executor_;  //!< The executor of the function that should be called when the time expires
     119
     120            long long interval_;  //!< The time-interval in micro seconds
     121            bool bLoop_;          //!< If true, the function gets called every 'interval' seconds
     122            bool bActive_;        //!< If true, the Timer ticks and calls the function if the time's up
     123            bool bKillAfterCall_; //!< If true the timer gets deleted after it called the function
     124
     125            long long time_;      //!< Internal variable, counting the time till the next function-call
    125126    };
    126127
     
    139140                @param exeuctor A executor of the function to call
    140141            */
    141             Timer(float interval, bool bLoop, T* object, ExecutorMember<T>* exeuctor)
    142             {
    143                 this->setTimer(interval, bLoop, object, exeuctor);
     142            Timer(float interval, bool bLoop, T* object, ExecutorMember<T>* exeuctor, bool bKillAfterCall = false)
     143            {
     144                this->setTimer(interval, bLoop, object, exeuctor, bKillAfterCall);
    144145            }
    145146
     
    151152                @param exeuctor A executor of the function to call
    152153            */
    153             void setTimer(float interval, bool bLoop, T* object, ExecutorMember<T>* executor)
     154            void setTimer(float interval, bool bLoop, T* object, ExecutorMember<T>* executor, bool bKillAfterCall = false)
    154155            {
    155156                this->deleteExecutor();
     
    162163
    163164                this->time_ = this->interval_;
     165                this->bKillAfterCall_ = bKillAfterCall;
    164166            }
    165167    };
     
    177179                @param exeuctor A executor of the function to call
    178180            */
    179             StaticTimer(float interval, bool bLoop, ExecutorStatic* executor)
    180             {
    181                 this->setTimer(interval, bLoop, executor);
     181            StaticTimer(float interval, bool bLoop, ExecutorStatic* executor, bool bKillAfterCall = false)
     182            {
     183                this->setTimer(interval, bLoop, executor, bKillAfterCall);
    182184            }
    183185
     
    189191                @param executor A executor of the function to call
    190192            */
    191             void setTimer(float interval, bool bLoop, ExecutorStatic* executor)
     193            void setTimer(float interval, bool bLoop, ExecutorStatic* executor, bool bKillAfterCall = false)
    192194            {
    193195                this->deleteExecutor();
     
    199201
    200202                this->time_ = this->interval_;
     203                this->bKillAfterCall_ = bKillAfterCall;
    201204            }
    202205    };
Note: See TracChangeset for help on using the changeset viewer.