Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 10, 2012, 3:26:49 PM (12 years ago)
Author:
davidsa
Message:

Added nested Class Lens to LensFlare, to simplify lens flare configuration and some of the methods. Might also be used to define presets in the future.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/shaders/src/orxonox/graphics/LensFlare.cc

    r9491 r9500  
    5151        RegisterObject(LensFlare);
    5252       
     53        this->lensConfiguration_=new std::vector<LensFlare::Lens*>();
     54        this->lensConfiguration_->push_back(new LensFlare::Lens(new std::string("lensflare/burst"),1.0f,1.0f,1.0f)); //main burst
     55        this->lensConfiguration_->push_back(new LensFlare::Lens(new std::string("lensflare/bursthalo"),0.7f,0.9f,1.0f)); //halo around main burst
     56        this->lensConfiguration_->push_back(new LensFlare::Lens(new std::string("lensflare/halo1"),0.4f,0.2f,0.8f)); //all the different distanced lenses
     57        this->lensConfiguration_->push_back(new LensFlare::Lens(new std::string("lensflare/halo2"),0.7f,0.3f,0.7f));
     58        this->lensConfiguration_->push_back(new LensFlare::Lens(new std::string("lensflare/halo3"),0.3f,0.4f,0.6f));
     59        this->lensConfiguration_->push_back(new LensFlare::Lens(new std::string("lensflare/halo3"),0.1f,0.8f,0.4f));
     60        this->lensConfiguration_->push_back(new LensFlare::Lens(new std::string("lensflare/halo1"),0.15f,0.5f,0.35f));
     61       
    5362        this->createBillboards();
    5463       
     
    6776        XMLPortParam(LensFlare, "fadeResolution", setFadeResolution, getFadeResolution, xmlelement, mode).defaultValues(7);
    6877        XMLPortParam(LensFlare, "fadeExponent", setFadeExponent, getFadeExponent, xmlelement, mode).defaultValues(2.0f);
     78        XMLPortParam(LensFlare, "colour", setColour, getColour, xmlelement, mode);
    6979    }
    7080   
     
    8292    void LensFlare::createBillboards()
    8393    {
    84         //TODO: add more billboards, possibly do some cleaning up, by using a loop
    8594        this->occlusionBillboard_ = new Billboard(this);
    8695        this->occlusionBillboard_->setMaterial("lensflare/hoq");
     
    9099        this->attach(this->occlusionBillboard_);
    91100       
    92         Billboard* burst = new Billboard(this);
    93         burst->setMaterial("lensflare/burst");
    94         burst->disableFrustumCulling();
    95         burst->setVisible(true);
    96         this->attach(burst);
    97        
    98         Billboard* bursthalo = new Billboard(this);
    99         bursthalo->setMaterial("lensflare/bursthalo");
    100         bursthalo->disableFrustumCulling();
    101         bursthalo->setVisible(true);
    102         this->attach(bursthalo);
    103        
    104         bursthalo = new Billboard(this);
    105         bursthalo->setMaterial("lensflare/halo1");
    106         bursthalo->disableFrustumCulling();
    107         bursthalo->setVisible(true);
    108         this->attach(bursthalo);
    109        
    110         bursthalo = new Billboard(this);
    111         bursthalo->setMaterial("lensflare/halo2");
    112         bursthalo->disableFrustumCulling();
    113         bursthalo->setVisible(true);
    114         this->attach(bursthalo);
    115        
    116         bursthalo = new Billboard(this);
    117         bursthalo->setMaterial("lensflare/halo3");
    118         bursthalo->disableFrustumCulling();
    119         bursthalo->setVisible(true);
    120         this->attach(bursthalo);
     101        for(std::vector<LensFlare::Lens*>::iterator it = lensConfiguration_->begin(); it != lensConfiguration_->end(); ++it) {
     102            Billboard* lensPart=new Billboard(this);
     103            lensPart->setMaterial(*(*it)->material_);
     104            lensPart->disableFrustumCulling();
     105            lensPart->setVisible(true);
     106            this->attach(lensPart);
     107        }
    121108    }
    122109
     
    133120    void LensFlare::updateBillboardStates(Vector3& viewDirection, float dimension, bool lightIsVisible)
    134121    {
    135         //TODO: develop a more sane method for determining positions and scale factors of the flare components
    136         //A good solution would probably be to introduce a data structure which stores a lens flare configuration
    137         int i=0;
    138         float step=0.0f;
    139         for(std::set<WorldEntity*>::const_iterator it = this->getAttachedObjects().begin(); it != this->getAttachedObjects().end(); it++) {
     122        this->occlusionBillboard_->setDefaultDimensions(dimension*0.5f,dimension*0.5f);
     123        this->occlusionBillboard_->setVisible(lightIsVisible);
     124        std::set<WorldEntity*>::const_iterator it = this->getAttachedObjects().begin();
     125        it++;
     126        for(int i=0; it != this->getAttachedObjects().end(); it++) {
    140127            Billboard* billboard=static_cast<Billboard*>(*it);
    141             billboard->setPosition(-viewDirection*step);
     128            LensFlare::Lens* lens=lensConfiguration_->at(i);
     129            billboard->setPosition(-viewDirection*(1.0f-lens->position_));
    142130            billboard->setVisible(lightIsVisible);
    143             billboard->setDefaultDimensions((i==0?0.5f:1.0f)*(i>2?0.25f:1.0f)*dimension*std::pow((1.0f-step),-1.0f),(i==0?0.5f:1.0f)*(i>2?0.25f:1.0f)*dimension*std::pow((1.0f-step),-1.0f));
    144             step=0.25f*(i>2?(i-2):0);
     131            billboard->setDefaultDimensions(dimension*lens->scale_,dimension*lens->scale_);
    145132            i++;
    146133        }
     
    159146        it++;
    160147        for(int i=0;it!=this->getAttachedObjects().end(); it++) {
    161             if(i==2)
    162             {
    163                 this->colour_->a*=0.33f;
    164             }
     148            ColourValue* cur=new ColourValue(0,0,0,0);
     149            (*cur)+= *(this->colour_);
     150            cur->a*=lensConfiguration_->at(i)->alpha_;
    165151            Billboard* billboard=static_cast<Billboard*>(*it);
    166             billboard->setColour(*(this->colour_));
     152            billboard->setColour(*cur);
    167153            i++;
    168154        }
Note: See TracChangeset for help on using the changeset viewer.