Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 24, 2011, 12:28:31 AM (13 years ago)
Author:
marwegma
Message:

Godrays: Safety commit. 90017 N8

File:
1 moved

Legend:

Unmodified
Added
Removed
  • code/branches/environment2/src/orxonox/graphics/GodrayShader.cc

    r8497 r8557  
    3030 @file
    3131 
    32  @brief Implementation of the GlobalGodrayShader class.
     32 @brief Implementation of the GodrayShader class.
    3333 */
    3434
    35 #include "GlobalGodrayShader.h"
     35
     36#include "GodrayShader.h"
    3637
    3738#include "util/Exception.h"
     
    4142namespace orxonox
    4243{
    43     CreateFactory(GlobalGodrayShader);
     44    CreateFactory(GodrayShader);
    4445   
    45     GlobalGodrayShader::GlobalGodrayShader(BaseObject* creator) : BaseObject(creator), globalShader_(creator)
     46    GodrayShader::GodrayShader(BaseObject* creator) : BaseObject(creator), globalShader_(creator)
    4647    {
    47         RegisterObject(GlobalGodrayShader);
     48        RegisterObject(GodrayShader);
    4849       
    49         if (!this->getScene())
    50             ThrowException(AbortLoading, "Can't create GlobalGodrayShader, no scene given.");
    51         //        if (!this->getScene()->getSceneManager())
    52         //            ThrowException(AbortLoading, "Can't create GlobalGodrayShader, no scene manager given.");
    53        
     50        // Default parameters are initialized
     51        this->sunPosition_ = Vector3::Zero;
     52        this->sunColor_ = ColourValue::White;
    5453        this->skyColor_ = ColourValue::Black;
    55         this->exposure_ = 1.0f;
     54        this->exposure_ = 1.0f; 
    5655        this->decay_ = 0.1f;
    5756        this->density_ = 0.7f;
    5857       
    59         //// Init ////
     58        // Godrays.compositor is getting initialized
     59        this->globalShader_.getMutableShader().setCompositorName("Godrays");
     60        this->compositor_ = this->globalShader_.getMutableShader().getMutableCompositorInstance();
    6061    }
    6162   
    62     GlobalGodrayShader::~GlobalGodrayShader()
     63    GodrayShader::~GodrayShader()
    6364    {
    6465        this->setVisible(false);
    6566    }
    6667   
    67     void GlobalGodrayShader::tick(float dt)
     68    void GodrayShader::tick(float dt)
    6869    {
    69         // To-Do
     70        if(this->isVisible())
     71        {
     72           
     73            //Reset sunPosition in the compositor instance every tick
     74            this->compositor_->getTechnique()->getTargetPass(2)
     75        }
    7076    }
    7177   
    72     void GlobalGodrayShader::XMLPort(Element& xmlelement, XMLPort::Mode mode)
     78    void GodrayShader::XMLPort(Element& xmlelement, XMLPort::Mode mode)
    7379    {
    74         SUPER(GlobalGodrayShader, XMLPort, xmlelement, mode);
     80        SUPER(GodrayShader, XMLPort, xmlelement, mode);
    7581       
    76         XMLPortParamTemplate(GlobalGodrayShader, "sunPosition", setSunPosition, getSunPosition, xmlelement, mode, const Vector3&);
    77         XMLPortParamTemplate(GlobalGodrayShader, "skyColor", setSkyColor, getSkyColor, xmlelement, mode, const ColourValue&);
    78         XMLPortParamVariable(GlobalGodrayShader, "exposure", exposure_, xmlelement, mode);
    79         XMLPortParamVariable(GlobalGodrayShader, "decay", decay_, xmlelement, mode);
    80         XMLPortParamVariable(GlobalGodrayShader, "density", density_, xmlelement, mode);
     82        XMLPortParamTemplate(GodrayShader, "sunColor", setSunColor, getSunColor, xmlelement, mode, const ColourValue&);
     83        XMLPortParamTemplate(GodrayShader, "skyColor", setSkyColor, getSkyColor, xmlelement, mode, const ColourValue&);
     84        XMLPortParamVariable(GodrayShader, "exposure", exposure_, xmlelement, mode);
     85        XMLPortParamVariable(GodrayShader, "decay", decay_, xmlelement, mode);
     86        XMLPortParamVariable(GodrayShader, "density", density_, xmlelement, mode);
    8187    }
    8288   
    83     void GlobalGodrayShader::setSunPosition(const Vector3& position)
     89    void GodrayShader::setWorldEntity(WorldEntity* worldEntity)
     90    {
     91        this->worldEntity_ = worldEntity;
     92        this->setSunPosition(worldEntity->getWorldPosition());
     93    }
     94   
     95    void GodrayShader::setSunPosition(const Vector3& position)
    8496    {
    8597        this->sunPosition_ = position;
    8698    }
    87     void GlobalGodrayShader::setSkyColor(const ColourValue& color)
     99    void GodrayShader::setSunColor(const ColourValue& color)
    88100    {
    89101        this->skyColor_ = color;
    90102    }
    91     const Vector3& GlobalGodrayShader::getSunPosition() const
     103    void GodrayShader::setSkyColor(const ColourValue& color)
     104    {
     105        this->skyColor_ = color;
     106    }
     107    const Vector3& GodrayShader::getSunPosition() const
    92108    {
    93109        return this->sunPosition_;
    94110    }
    95     const ColourValue& GlobalGodrayShader::getSkyColor() const
     111    const ColourValue& GodrayShader::getSunColor() const
     112    {
     113        return this->sunColor_;
     114    }
     115    const ColourValue& GodrayShader::getSkyColor() const
    96116    {
    97117        return this->skyColor_;
    98118    }
    99119   
    100     void GlobalGodrayShader::changedVisibility()
     120    void GodrayShader::changedVisibility()
    101121    {
    102         SUPER(GlobalGodrayShader, changedVisibility);
     122        SUPER(GodrayShader, changedVisibility);
    103123       
    104124        this->globalShader_.setVisible(this->isVisible());
Note: See TracChangeset for help on using the changeset viewer.