Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 16, 2008, 6:01:13 PM (15 years ago)
Author:
landauf
Message:

Merged objecthierarchy2 into presentation branch

Couln't merge 2 lines in Gamestate.cc and a whole block of code in GSDedicated.cc (it seems like oli implemented in both branches something like a network-tick-limiter but with different approaches)

Not yet tested in network mode and with bots
The SpaceShips movement is also not yet fully adopted to the new physics (see Engine class)

Location:
code/branches/presentation
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/branches/presentation

  • code/branches/presentation/src/orxonox/objects/worldentities/Light.cc

    r2459 r2485  
    3636
    3737#include "util/String.h"
    38 #include "util/Convert.h"
     38#include "util/Exception.h"
     39#include "core/Core.h"
    3940#include "core/CoreIncludes.h"
    4041#include "core/XMLPort.h"
     
    4344namespace orxonox
    4445{
    45     unsigned int Light::lightCounter_s = 0;
    46 
    4746    CreateFactory(Light);
    4847
     
    5150        RegisterObject(Light);
    5251
    53         if (this->getScene() && this->getScene()->getSceneManager())
    54         this->light_ = this->getScene()->getSceneManager()->createLight("Light" + convertToString(Light::lightCounter_s++));
    55         this->attachOgreObject(this->light_);
     52        this->light_ = 0;
     53        this->diffuse_ = ColourValue::White;
     54        this->specular_ = ColourValue::White;
     55        this->type_ = Ogre::Light::LT_POINT;
     56        this->attenuation_ = Vector4(100000, 1, 0, 0);
     57        this->spotlightRange_ = Vector3(40.0f, 30.0f, 1.0f);
     58
     59        if (Core::showsGraphics())
     60        {
     61            if (!this->getScene())
     62                ThrowException(AbortLoading, "Can't create Light, no scene given.");
     63            if (!this->getScene()->getSceneManager())
     64                ThrowException(AbortLoading, "Can't create Light, no scene manager given.");
     65
     66            if (this->getScene() && this->getScene()->getSceneManager())
     67            {
     68                this->light_ = this->getScene()->getSceneManager()->createLight("Light" + getUniqueNumberString());
     69                this->light_->setDirection(WorldEntity::FRONT);
     70                this->attachOgreObject(this->light_);
     71
     72                this->updateType();
     73                this->updateDiffuseColour();
     74                this->updateSpecularColour();
     75                this->updateAttenuation();
     76                this->updateSpotlightRange();
     77            }
     78        }
    5679
    5780        this->registerVariables();
     
    7194        SUPER(Light, XMLPort, xmlelement, mode);
    7295
    73         XMLPortParam(Light, "type", setTypeString, getTypeString, xmlelement, mode).defaultValues("point");
    74         XMLPortParamExternTemplate(Light, Ogre::Light, this->light_, "diffuse",   setDiffuseColour,  getDiffuseColour,  xmlelement, mode, const ColourValue&);
    75         XMLPortParamExternTemplate(Light, Ogre::Light, this->light_, "specular",  setSpecularColour, getSpecularColour, xmlelement, mode, const ColourValue&);
    76         XMLPortParamExternTemplate(Light, Ogre::Light, this->light_, "direction", setDirection,      getDirection,      xmlelement, mode, const Vector3&);
     96        XMLPortParam(Light, "type",           setTypeString,     getTypeString,     xmlelement, mode).defaultValues("point");
     97        XMLPortParam(Light, "diffuse",        setDiffuseColour,  getDiffuseColour,  xmlelement, mode).defaultValues(ColourValue::White);
     98        XMLPortParam(Light, "specular",       setSpecularColour, getSpecularColour, xmlelement, mode).defaultValues(ColourValue::White);
     99        XMLPortParam(Light, "attenuation",    setAttenuation,    getAttenuation,    xmlelement, mode).defaultValues(Vector4(100000, 1, 0, 0));
     100        XMLPortParam(Light, "spotlightrange", setSpotlightRange, getSpotlightRange, xmlelement, mode).defaultValues(Vector3(40.0f, 30.0f, 1.0f));
    77101    }
    78102
    79103    void Light::registerVariables()
    80104    {
    81         registerVariable((int &)this->type_, variableDirection::toclient, new NetworkCallback<Light>(this, &Light::changedType));
    82         registerVariable(this->light_->getDiffuseColour(), variableDirection::toclient);
    83         registerVariable(this->light_->getSpecularColour(), variableDirection::toclient);
    84         registerVariable(this->light_->getDirection(), variableDirection::toclient);
     105        registerVariable((int&)this->type_,     variableDirection::toclient, new NetworkCallback<Light>(this, &Light::updateType));
     106        registerVariable(this->diffuse_,        variableDirection::toclient, new NetworkCallback<Light>(this, &Light::updateDiffuseColour));
     107        registerVariable(this->specular_,       variableDirection::toclient, new NetworkCallback<Light>(this, &Light::updateSpecularColour));
     108        registerVariable(this->attenuation_,    variableDirection::toclient, new NetworkCallback<Light>(this, &Light::updateAttenuation));
     109        registerVariable(this->spotlightRange_, variableDirection::toclient, new NetworkCallback<Light>(this, &Light::updateSpotlightRange));
    85110    }
    86111
    87     const std::string& Light::getName() const
     112    void Light::updateDiffuseColour()
    88113    {
    89114        if (this->light_)
    90             return this->light_->getName();
    91         else
    92             return BLANKSTRING;
     115            this->light_->setDiffuseColour(this->diffuse_);
    93116    }
    94117
    95     void Light::setDiffuseColour(const ColourValue& colour)
     118    void Light::updateSpecularColour()
    96119    {
    97120        if (this->light_)
    98             this->light_->setDiffuseColour(colour);
     121            this->light_->setSpecularColour(this->specular_);
    99122    }
    100123
    101     const ColourValue& Light::getDiffuseColour() const
     124    void Light::updateAttenuation()
    102125    {
    103         if (this->light_)
    104             return this->light_->getDiffuseColour();
    105         else
    106             return ColourValue::White;
     126        if (this->light_ && this->type_ != Ogre::Light::LT_DIRECTIONAL)
     127            this->light_->setAttenuation(this->attenuation_.x, this->attenuation_.y, this->attenuation_.z, this->attenuation_.w);
    107128    }
    108129
    109     void Light::setSpecularColour(const ColourValue& colour)
     130    void Light::updateSpotlightRange()
    110131    {
    111         if (this->light_)
    112             this->light_->setSpecularColour(colour);
    113     }
    114 
    115     const ColourValue& Light::getSpecularColour() const
    116     {
    117         if (this->light_)
    118             return this->light_->getSpecularColour();
    119         else
    120             return ColourValue::White;
    121     }
    122 
    123     void Light::setDirection(const Vector3& direction)
    124     {
    125         if (this->light_)
    126             this->light_->setDirection(direction);
    127     }
    128 
    129     const Vector3& Light::getDirection() const
    130     {
    131         if (this->light_)
    132             return this->light_->getDirection();
    133         else
    134             return Vector3::ZERO;
     132        if (this->light_ && this->type_ == Ogre::Light::LT_SPOTLIGHT)
     133            this->light_->setSpotlightRange(Degree(this->spotlightRange_.x), Degree(this->spotlightRange_.y), this->spotlightRange_.z);
    135134    }
    136135
     
    157156            case Ogre::Light::LT_POINT:
    158157            default:
    159                 return "poinT";
     158                return "point";
    160159        }
    161160    }
    162161
    163     void Light::changedType()
     162    void Light::updateType()
    164163    {
    165         this->light_->setType(this->type_);
     164        if (this->light_)
     165        {
     166            this->light_->setType(this->type_);
     167
     168            if (this->type_ != Ogre::Light::LT_DIRECTIONAL)
     169                this->updateAttenuation();
     170            if (this->type_ == Ogre::Light::LT_SPOTLIGHT)
     171                this->updateSpotlightRange();
     172        }
    166173    }
    167174
     
    170177        SUPER(Light, changedVisibility);
    171178
    172         this->light_->setVisible(this->isVisible());
     179        if (this->light_)
     180            this->light_->setVisible(this->isVisible());
    173181    }
    174182}
Note: See TracChangeset for help on using the changeset viewer.