Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 2182


Ignore:
Timestamp:
Nov 12, 2008, 2:24:10 AM (15 years ago)
Author:
landauf
Message:

changed a lot in Backlight, but not yet finished

Location:
code/branches/objecthierarchy2/src/orxonox/objects/worldentities
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • code/branches/objecthierarchy2/src/orxonox/objects/worldentities/Backlight.cc

    r2171 r2182  
    3030#include "Backlight.h"
    3131
    32 #include <OgreBillboard.h>
    3332#include <OgreRibbonTrail.h>
    3433#include <OgreSceneManager.h>
    3534
     35#include "core/Core.h"
    3636#include "core/CoreIncludes.h"
    37 #include "core/ConfigValueIncludes.h"
    38 #include "core/Executor.h"
    39 #include "util/Math.h"
    40 #include "GraphicsEngine.h"
     37#include "core/XMLPort.h"
     38#include "objects/Scene.h"
    4139
    4240namespace orxonox
     
    4442    CreateFactory(Backlight);
    4543
     44    Backlight::Backlight(BaseObject* creator) : Billboard(creator)
     45    {
     46        RegisterObject(Backlight);
     47
     48        this->ribbonTrail_ = 0;
     49        this->ribbonTrailNode_ = 0;
     50
     51        this->width_ = 0;
     52        this->length_ = 1.0f;
     53        this->lifetime_ = 1.0f;
     54        this->maxelements_ = 1;
     55
     56        if (Core::showsGraphics())
     57        {
     58            assert(this->getScene());
     59            assert(this->getScene()->getSceneManager());
     60            assert(this->getScene()->getRootSceneNode());
     61
     62            this->ribbonTrail_ = this->getScene()->getSceneManager()->createRibbonTrail(this->getNode()->getName());
     63            this->ribbonTrailNode_ = this->getScene()->getRootSceneNode()->createChildSceneNode();
     64            this->ribbonTrailNode_->attachObject(this->ribbonTrail_);
     65            this->ribbonTrail_->addNode(this->getNode());
     66
     67            this->ribbonTrail_->setMaxChainElements(this->maxelements_);
     68            this->ribbonTrail_->setTrailLength(this->length_);
     69            this->ribbonTrail_->setInitialWidth(0, this->width_);
     70        }
     71
     72        this->registerVariables();
     73    }
     74
     75    Backlight::~Backlight()
     76    {
     77        if (this->isInitialized())
     78        {
     79            if (this->ribbonTrail_)
     80            {
     81                if (this->ribbonTrailNode_)
     82                {
     83                    this->ribbonTrailNode_->detachObject(this->ribbonTrail_);
     84                    this->getScene()->getSceneManager()->destroySceneNode(this->ribbonTrailNode_->getName());
     85                }
     86                this->getScene()->getSceneManager()->destroyRibbonTrail(this->ribbonTrail_);
     87            }
     88        }
     89    }
     90
     91    void Backlight::XMLPort(Element& xmlelement, XMLPort::Mode mode)
     92    {
     93        SUPER(Backlight, XMLPort, xmlelement, mode);
     94
     95        XMLPortParam(Backlight, "length",        setLength,        getLength,        xmlelement, mode).defaultValues(100.0f);
     96        XMLPortParam(Backlight, "width",         setWidth,         getWidth,         xmlelement, mode).defaultValues(1.0f);
     97        XMLPortParam(Backlight, "elements",      setMaxElements,   getMaxElements,   xmlelement, mode).defaultValues(10);
     98        XMLPortParam(Backlight, "lifetime",      setLifetime,      getLifetime,      xmlelement, mode).defaultValues(1.0f);
     99        XMLPortParam(Backlight, "trailmaterial", setTrailMaterial, getTrailMaterial, xmlelement, mode);
     100    }
     101
     102    void Backlight::registerVariables()
     103    {
     104        REGISTERDATA  (this->width_,         direction::toclient, new NetworkCallback<Backlight>(this, &Backlight::update_width));
     105        REGISTERDATA  (this->lifetime_,      direction::toclient, new NetworkCallback<Backlight>(this, &Backlight::update_lifetime));
     106        REGISTERDATA  (this->length_,        direction::toclient, new NetworkCallback<Backlight>(this, &Backlight::update_length));
     107        REGISTERDATA  (this->maxelements_,   direction::toclient, new NetworkCallback<Backlight>(this, &Backlight::update_maxelements));
     108        REGISTERSTRING(this->trailmaterial_, direction::toclient, new NetworkCallback<Backlight>(this, &Backlight::update_trailmaterial));
     109    }
     110
     111    void Backlight::changedColour()
     112    {
     113        Billboard::changedColour();
     114
     115        if (this->ribbonTrail_ && this->isActive())
     116            this->ribbonTrail_->setInitialColour(0, this->getColour());
     117    }
     118
     119    void Backlight::update_width()
     120    {
     121        if (this->ribbonTrail_)
     122            this->ribbonTrail_->setInitialWidth(0, this->width_);
     123        this->update_lifetime();
     124    }
     125
     126    void Backlight::update_lifetime()
     127    {
     128        if (this->ribbonTrail_)
     129        {
     130            this->ribbonTrail_->setWidthChange(0, this->width_ / this->lifetime_/* * Backlight::timeFactor_s*/);
     131            this->ribbonTrail_->setColourChange(0, 0, 0, 0, 1.0f / this->lifetime_/* * Backlight::timeFactor_s*/);
     132        }
     133    }
     134
     135    void Backlight::update_length()
     136    {
     137//        if (this->ribbonTrail_)
     138//            this->ribbonTrail_->setTrailLength(this->length_);
     139    }
     140
     141    void Backlight::update_maxelements()
     142    {
     143        if (this->ribbonTrail_)
     144            this->ribbonTrail_->setMaxChainElements(this->maxelements_);
     145    }
     146
     147    void Backlight::update_trailmaterial()
     148    {
     149        if (this->ribbonTrail_)
     150            this->ribbonTrail_->setMaterialName(this->trailmaterial_);
     151    }
     152
     153    void Backlight::changedVisibility()
     154    {
     155        SUPER(Backlight, changedVisibility);
     156
     157        if (this->ribbonTrail_)
     158            this->ribbonTrail_->setVisible(this->isVisible());
     159    }
     160
     161    void Backlight::changedActivity()
     162    {
     163        SUPER(Backlight, changedActivity);
     164
     165        if (this->ribbonTrail_)
     166        {
     167            if (this->isActive())
     168                this->ribbonTrail_->setInitialColour(0, this->getColour());
     169            else
     170                this->ribbonTrail_->setInitialColour(0, 0, 0, 0, 0);
     171        }
     172    }
     173
     174    void Backlight::notifyAttached()
     175    {
     176        Billboard::notifyAttached();
     177
     178//        if (this->ribbonTrail_)
     179//            this->ribbonTrail_->clearChain(0);
     180
     181//        if (this->ribbonTrail_)
     182//            this->ribbonTrail_->setTrailLength(this->length_);
     183    }
     184
     185    void Backlight::tick(float dt)
     186    {
     187        if (this->ribbonTrail_)
     188            this->ribbonTrail_->setTrailLength(this->length_);
     189    }
     190
     191//------------------------------------------------------------------------------------
     192/*
    46193    float Backlight::timeFactor_s = 1.0;
    47194
     
    52199        this->setConfigValues();
    53200        this->traillength_ = 1;
     201        this->colour_ = ColourValue::White;
    54202
    55203        this->configure(maxspeed, brakingtime, scale);
    56204    }
    57    
     205
    58206    bool Backlight::create(){
    59207      if(!WorldEntity::create())
    60208        return false;
    61      
     209
    62210      this->getNode()->setInheritScale(false);
    63211
     
    76224        //this->setTimeFactor(Orxonox::getInstance().getTimeFactor());
    77225      this->setTimeFactor(1.0f);
    78      
     226
    79227      this->ribbonTrail_->setMaxChainElements(this->maxTrailsegments_);
    80228      this->ribbonTrail_->setTrailLength(this->traillength_ = 2 * this->maxTrailsegments_);
     
    113261        this->ribbonTrail_->setColourChange(0, ColourValue(0, 0, 0, this->maxTraillength_ / this->traillength_ / this->maxLifeTime_ * Backlight::timeFactor_s));
    114262    }
    115    
    116    
    117     void Backlight::XMLPort(Element& xmlelement, XMLPort::Mode mode){
    118       SUPER(Backlight, XMLPort, xmlelement, mode);
    119      
    120       Backlight::create();
    121     }
    122263
    123264    void Backlight::tick(float dt)
     
    145286    }
    146287
    147     void Backlight::setColour(const ColourValue& colour)
    148     {
    149         this->billboard_.getBillboardSet()->getBillboard(0)->setColour(colour);
    150         this->ribbonTrail_->setInitialColour(0, ColourValue(colour.r / 4 + 0.75, colour.g / 4 + 0.75, colour.b / 4 + 0.75));
    151     }
    152 
    153288    void Backlight::configure(float maxspeed, float brakingtime, float scale)
    154289    {
     
    168303        this->ribbonTrail_->setVisible(this->isVisible());
    169304    }
     305*/
    170306}
  • code/branches/objecthierarchy2/src/orxonox/objects/worldentities/Backlight.h

    r2171 r2182  
    3131
    3232#include "OrxonoxPrereqs.h"
    33 
    34 #include "PositionableEntity.h"
    35 #include "tools/BillboardSet.h"
     33#include "Billboard.h"
     34#include "objects/Tickable.h"
    3635
    3736namespace orxonox
    3837{
    39     class _OrxonoxExport Backlight : public PositionableEntity
     38    class _OrxonoxExport Backlight : public Billboard, public Tickable
    4039    {
     40        public:
     41            Backlight(BaseObject* creator);
     42            virtual ~Backlight();
     43
     44            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
     45            void registerVariables();
     46
     47            virtual void tick(float dt);
     48            virtual void changedActivity();
     49            virtual void changedVisibility();
     50
     51            inline void setWidth(float width)
     52                { this->width_ = width; this->update_width(); }
     53            inline float getWidth() const
     54                { return this->width_; }
     55
     56            inline void setLifetime(float lifetime)
     57                { this->lifetime_ = lifetime; this->update_lifetime(); }
     58            inline float getLifetime() const
     59                { return this->lifetime_; }
     60
     61            inline void setLength(float length)
     62                { this->length_ = length; this->update_length(); }
     63            inline float getLength() const
     64                { return this->length_; }
     65
     66            inline void setMaxElements(size_t maxelements)
     67                { this->maxelements_ = maxelements; this->update_maxelements(); }
     68            inline size_t getMaxElements() const
     69                { return this->maxelements_; }
     70
     71            inline void setTrailMaterial(const std::string& material)
     72                { this->trailmaterial_ = material; this->update_trailmaterial(); }
     73            inline const std::string& getTrailMaterial() const
     74                { return this->trailmaterial_; }
     75
     76        protected:
     77            virtual void notifyAttached();
     78
     79        private:
     80            virtual void changedColour();
     81            void update_width();
     82            void update_lifetime();
     83            void update_length();
     84            void update_maxelements();
     85            void update_trailmaterial();
     86
     87            Ogre::RibbonTrail* ribbonTrail_;
     88            Ogre::SceneNode* ribbonTrailNode_;
     89            float width_;
     90            float length_;
     91            float lifetime_;
     92            size_t maxelements_;
     93            std::string trailmaterial_;
     94    };
     95
     96
     97/*
    4198        public:
    4299            Backlight(float maxspeed = 1.0, float brakingtime = 1.0, float scale = 1.0);
     
    49106            virtual bool create();
    50107
    51             void setColour(const ColourValue& colour);
     108
    52109            void setTimeFactor(float factor);
    53110
     
    60117            Ogre::SceneNode* ribbonTrailNode_;
    61118            Ogre::RibbonTrail* ribbonTrail_;
     119
    62120
    63121            float maxLifeTime_;
     
    72130            size_t maxTrailsegments_;
    73131    };
     132*/
    74133}
    75134
  • code/branches/objecthierarchy2/src/orxonox/objects/worldentities/Billboard.cc

    r2171 r2182  
    4141    {
    4242        RegisterObject(Billboard);
     43
     44        this->material_ = "";
     45        this->colour_ = ColourValue::White;
    4346
    4447        this->registerVariables();
     
    8891        if (!this->billboard_.getBillboardSet())
    8992        {
    90             if (this->getScene() && this->getScene()->getSceneManager())
     93            if (this->getScene() && this->getScene()->getSceneManager() && (this->material_ != ""))
    9194            {
    9295                this->billboard_.setBillboardSet(this->getScene()->getSceneManager(), this->material_, this->colour_, 1);
  • code/branches/objecthierarchy2/src/orxonox/objects/worldentities/Billboard.h

    r2087 r2182  
    6161                { return this->colour_; }
    6262
     63        protected:
     64            virtual void changedColour();
     65
    6366        private:
    6467            void changedMaterial();
    65             void changedColour();
    6668
    6769            BillboardSet billboard_;
  • code/branches/objecthierarchy2/src/orxonox/objects/worldentities/CMakeLists.txt

    r2131 r2182  
    44  MovableEntity.cc
    55  ControllableEntity.cc
    6   Model.cc
     6
     7  Backlight.cc
    78  Billboard.cc
    89  BlinkingBillboard.cc
     
    1011  Camera.cc
    1112  CameraPosition.cc
    12   SpawnPoint.cc
     13  Model.cc
    1314  ParticleEmitter.cc
    1415  ParticleSpawner.cc
    15 #  Backlight.cc
     16  SpawnPoint.cc
    1617)
    1718
  • code/branches/objecthierarchy2/src/orxonox/objects/worldentities/WorldEntity.cc

    r2171 r2182  
    131131        object->parent_ = this;
    132132        object->parentID_ = this->getObjectID();
     133
     134        object->notifyAttached();
    133135    }
    134136
  • code/branches/objecthierarchy2/src/orxonox/objects/worldentities/WorldEntity.h

    r2171 r2182  
    139139
    140140        protected:
     141            virtual void notifyAttached() {}
     142
    141143            Ogre::SceneNode* node_;
    142144
Note: See TracChangeset for help on using the changeset viewer.