Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 2207


Ignore:
Timestamp:
Nov 14, 2008, 1:47:33 AM (15 years ago)
Author:
landauf
Message:

fixed Backlight initialization with a workaround, but there are still strange crashes.

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

Legend:

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

    r2182 r2207  
    3535#include "core/Core.h"
    3636#include "core/CoreIncludes.h"
     37#include "core/Executor.h"
    3738#include "core/XMLPort.h"
    3839#include "objects/Scene.h"
     
    5152        this->width_ = 0;
    5253        this->length_ = 1.0f;
    53         this->lifetime_ = 1.0f;
     54        this->lifetime_ = 0.001f;
     55        this->turnofftime_ = 0.5f;
     56        this->bTurningOff_ = false;
    5457        this->maxelements_ = 1;
     58
     59        this->tickcount_ = 0;
    5560
    5661        if (Core::showsGraphics())
     
    6166
    6267            this->ribbonTrail_ = this->getScene()->getSceneManager()->createRibbonTrail(this->getNode()->getName());
     68            this->ribbonTrail_->addNode(this->getNode());
    6369            this->ribbonTrailNode_ = this->getScene()->getRootSceneNode()->createChildSceneNode();
    6470            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_);
     71            this->ribbonTrail_->setInitialWidth(0, 0);
    7072        }
    7173
     
    9799        XMLPortParam(Backlight, "elements",      setMaxElements,   getMaxElements,   xmlelement, mode).defaultValues(10);
    98100        XMLPortParam(Backlight, "lifetime",      setLifetime,      getLifetime,      xmlelement, mode).defaultValues(1.0f);
     101        XMLPortParam(Backlight, "turnofftime",   setTurnOffTime,   getTurnOffTime,   xmlelement, mode).defaultValues(0.5f);
    99102        XMLPortParam(Backlight, "trailmaterial", setTrailMaterial, getTrailMaterial, xmlelement, mode);
    100103    }
     
    113116        Billboard::changedColour();
    114117
    115         if (this->ribbonTrail_ && this->isActive())
     118        if (this->ribbonTrail_ && this->isActive() && this->tickcount_ >= 2)
    116119            this->ribbonTrail_->setInitialColour(0, this->getColour());
    117120    }
     
    119122    void Backlight::update_width()
    120123    {
    121         if (this->ribbonTrail_)
     124        if (this->ribbonTrail_ && this->tickcount_ >= 2)
    122125            this->ribbonTrail_->setInitialWidth(0, this->width_);
    123126        this->update_lifetime();
     
    126129    void Backlight::update_lifetime()
    127130    {
    128         if (this->ribbonTrail_)
     131        if (this->ribbonTrail_ && this->tickcount_ >= 2)
    129132        {
    130133            this->ribbonTrail_->setWidthChange(0, this->width_ / this->lifetime_/* * Backlight::timeFactor_s*/);
     
    135138    void Backlight::update_length()
    136139    {
    137 //        if (this->ribbonTrail_)
    138 //            this->ribbonTrail_->setTrailLength(this->length_);
     140        if (this->ribbonTrail_ && this->tickcount_ >= 2)
     141            this->ribbonTrail_->setTrailLength(this->length_);
    139142    }
    140143
    141144    void Backlight::update_maxelements()
    142145    {
    143         if (this->ribbonTrail_)
     146        if (this->ribbonTrail_ && this->tickcount_ >= 2)
    144147            this->ribbonTrail_->setMaxChainElements(this->maxelements_);
    145148    }
     
    147150    void Backlight::update_trailmaterial()
    148151    {
    149         if (this->ribbonTrail_)
     152        if (this->ribbonTrail_ && this->tickcount_ >= 2)
    150153            this->ribbonTrail_->setMaterialName(this->trailmaterial_);
    151154    }
     
    168171                this->ribbonTrail_->setInitialColour(0, this->getColour());
    169172            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_);
     173            {
     174                this->bTurningOff_ = true;
     175                this->turnofftimer_.setTimer(this->turnofftime_, false, this, createExecutor(createFunctor(&Backlight::stopturnoff)));
     176            }
     177        }
     178    }
     179
     180    void Backlight::stopturnoff()
     181    {
     182        this->bTurningOff_ = false;
    183183    }
    184184
    185185    void Backlight::tick(float dt)
    186186    {
    187         if (this->ribbonTrail_)
    188             this->ribbonTrail_->setTrailLength(this->length_);
     187        if (this->tickcount_ < 2)
     188        {
     189            ++this->tickcount_;
     190            if (this->tickcount_ == 2)
     191            {
     192                this->changedColour();
     193                this->update_width();
     194                this->update_lifetime();
     195                this->update_length();
     196                this->update_maxelements();
     197                this->update_trailmaterial();
     198            }
     199        }
     200
     201        if (this->bTurningOff_ && this->ribbonTrail_)
     202        {
     203            this->ribbonTrail_->setInitialColour(0, this->ribbonTrail_->getInitialColour(0) - this->getColour() / this->turnofftime_ * dt);
     204        }
    189205    }
    190206
  • code/branches/objecthierarchy2/src/orxonox/objects/worldentities/Backlight.h

    r2182 r2207  
    3333#include "Billboard.h"
    3434#include "objects/Tickable.h"
     35#include "tools/Timer.h"
    3536
    3637namespace orxonox
     
    5960                { return this->lifetime_; }
    6061
     62            inline void setTurnOffTime(float turnofftime)
     63                { this->turnofftime_ = turnofftime; }
     64            inline float getTurnOffTime() const
     65                { return this->turnofftime_; }
     66
    6167            inline void setLength(float length)
    6268                { this->length_ = length; this->update_length(); }
     
    7480                { return this->trailmaterial_; }
    7581
    76         protected:
    77             virtual void notifyAttached();
    78 
    7982        private:
     83            void stopturnoff();
    8084            virtual void changedColour();
    8185            void update_width();
     
    9094            float length_;
    9195            float lifetime_;
     96            float turnofftime_;
     97            bool bTurningOff_;
    9298            size_t maxelements_;
    9399            std::string trailmaterial_;
     100            char tickcount_;
     101            Timer<Backlight> turnofftimer_;
    94102    };
    95103
  • code/branches/objecthierarchy2/src/orxonox/objects/worldentities/Billboard.cc

    r2182 r2207  
    7373    void Billboard::changedMaterial()
    7474    {
     75        if (this->material_ == "")
     76            return;
     77
    7578        if (!this->billboard_.getBillboardSet())
    7679        {
  • code/branches/objecthierarchy2/src/orxonox/objects/worldentities/WorldEntity.cc

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

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