Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 14, 2008, 8:13:43 PM (16 years ago)
Author:
landauf
Message:
  • Removed directional-light-hack from Scene
  • Many changes in Light, works in all game-modes (standalone, dedicated, server and client)
  • Fixed a bug which caused clients to not having shadows

There's still a big problem, bug I can't explain it.

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

Legend:

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

    r2438 r2447  
    8181        if (this->isInitialized())
    8282        {
     83            this->bDestroyWhenPlayerLeft_ = false;
     84
    8385            if (this->bHasLocalController_ && this->bHasHumanController_)
    8486                this->stopLocalHumanControl();
    8587
     88            if (this->getPlayer() && this->getPlayer()->getControllableEntity() == this)
     89                this->getPlayer()->stopControl(this, false);
     90
    8691            if (this->hud_)
    8792                delete this->hud_;
     
    8994            if (this->camera_)
    9095                delete this->camera_;
    91 
    92             if (this->getPlayer() && this->getPlayer()->getControllableEntity() == this)
    93                 this->getPlayer()->stopControl(this, false);
    9496        }
    9597    }
     
    231233    void ControllableEntity::startLocalHumanControl()
    232234    {
    233         this->camera_ = new Camera(this);
    234         this->camera_->requestFocus();
    235         if (this->cameraPositionTemplate_ != "")
    236             this->addTemplate(this->cameraPositionTemplate_);
    237         if (this->cameraPositions_.size() > 0)
    238             this->cameraPositions_.front()->attachCamera(this->camera_);
    239         else
    240             this->attach(this->camera_);
    241 
    242         if (this->hudtemplate_ != "")
    243         {
    244             this->hud_ = new OverlayGroup(this);
    245             this->hud_->addTemplate(this->hudtemplate_);
    246             this->hud_->setOwner(this);
     235        if (!this->camera_)
     236        {
     237            this->camera_ = new Camera(this);
     238            this->camera_->requestFocus();
     239            if (this->cameraPositionTemplate_ != "")
     240                this->addTemplate(this->cameraPositionTemplate_);
     241            if (this->cameraPositions_.size() > 0)
     242                this->cameraPositions_.front()->attachCamera(this->camera_);
     243            else
     244                this->attach(this->camera_);
     245        }
     246
     247        if (!this->hud_)
     248        {
     249            if (this->hudtemplate_ != "")
     250            {
     251                this->hud_ = new OverlayGroup(this);
     252                this->hud_->addTemplate(this->hudtemplate_);
     253                this->hud_->setOwner(this);
     254            }
    247255        }
    248256    }
  • code/branches/objecthierarchy2/src/orxonox/objects/worldentities/Light.cc

    r2254 r2447  
    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->getNode()->attachObject(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->getNode()->attachObject(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         REGISTERDATA(this->type_, direction::toclient, new NetworkCallback<Light>(this, &Light::changedType));
    82         REGISTERDATA(this->light_->getDiffuseColour(), direction::toclient);
    83         REGISTERDATA(this->light_->getSpecularColour(), direction::toclient);
    84         REGISTERDATA(this->light_->getDirection(), direction::toclient);
     105        REGISTERDATA(this->type_,           direction::toclient, new NetworkCallback<Light>(this, &Light::updateType));
     106        REGISTERDATA(this->diffuse_,        direction::toclient, new NetworkCallback<Light>(this, &Light::updateDiffuseColour));
     107        REGISTERDATA(this->specular_,       direction::toclient, new NetworkCallback<Light>(this, &Light::updateSpecularColour));
     108        REGISTERDATA(this->attenuation_,    direction::toclient, new NetworkCallback<Light>(this, &Light::updateAttenuation));
     109        REGISTERDATA(this->spotlightRange_, direction::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    {
    165164        if (this->light_)
     165        {
    166166            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        }
    167173    }
    168174
  • code/branches/objecthierarchy2/src/orxonox/objects/worldentities/Light.h

    r2087 r2447  
    5454                { return this->light_; }
    5555
    56             const std::string& getName() const;
    57 
    5856            inline void setType(Ogre::Light::LightTypes type)
    59                 { this->type_ = type; this->changedType(); }
    60             Ogre::Light::LightTypes getType() const
     57                { this->type_ = type; this->updateType(); }
     58            inline Ogre::Light::LightTypes getType() const
    6159                { return this->type_; }
    6260
    63             void setDiffuseColour(const ColourValue& colour);
    64             const ColourValue& getDiffuseColour() const;
     61            inline void setDiffuseColour(const ColourValue& colour)
     62                { this->diffuse_ = colour; this->updateDiffuseColour(); }
     63            inline const ColourValue& getDiffuseColour() const
     64                { return this->diffuse_; }
    6565
    66             void setSpecularColour(const ColourValue& colour);
    67             const ColourValue& getSpecularColour() const;
     66            inline void setSpecularColour(const ColourValue& colour)
     67                { this->specular_ = colour; this->updateSpecularColour(); }
     68            inline const ColourValue& getSpecularColour() const
     69                { return this->specular_; }
    6870
    69             void setDirection(const Vector3& direction);
    70             const Vector3& getDirection() const;
     71            /**
     72                @brief Sets the attenuation parameters of the light source i.e. how it diminishes with distance.
     73
     74                @param attenuation.x range (The absolute upper range of the light in world units)
     75                @param attenuation.y constant (The constant factor in the attenuation formula: 1.0 means never attenuate, 0.0 is complete attenuation)
     76                @param attenuation.z linear (The linear factor in the attenuation formula: 1 means attenuate evenly over the distance)
     77                @param attenuation.w quadratic (The quadratic factor in the attenuation formula: adds a curvature to the attenuation formula)
     78
     79                Quote from the Ogre API:
     80                Lights normally get fainter the further they are away. Also, each light is given a maximum range beyond which it cannot affect any objects.
     81                Light attenuation is not applicable to directional lights since they have an infinite range and constant intensity.
     82                This follows a standard attenuation approach - see any good 3D text for the details of what they mean since i don't have room here!
     83
     84                Quote from the Ogre wiki:
     85                "Using these numbers, the light has 100% intensity at 0 distance, and
     86                trails off to near black at a distance equal to the Range. Keep in mind
     87                that most of the light falls in the first 20% of the range."
     88
     89                Range   Constant   Linear     Quadratic
     90                3250,     1.0,     0.0014,    0.000007
     91                600,      1.0,     0.007,     0.0002
     92                325,      1.0,     0.014,     0.0007
     93                200,      1.0,     0.022,     0.0019
     94                160,      1.0,     0.027,     0.0028
     95                100,      1.0,     0.045,     0.0075
     96                65,       1.0,     0.07,      0.017
     97                50,       1.0,     0.09,      0.032
     98                32,       1.0,     0.14,      0.07
     99                20,       1.0,     0.22,      0.20
     100                13,       1.0,     0.35,      0.44
     101                7,        1.0,     0.7,       1.8
     102            */
     103            inline void setAttenuation(const Vector4& attenuation)
     104                { this->attenuation_ = attenuation; this->updateAttenuation(); }
     105            inline const Vector4& getAttenuation() const
     106                { return this->attenuation_; }
     107
     108            /**
     109                @brief Sets the range of a spotlight, i.e. the angle of the inner and outer cones and the rate of falloff between them.
     110
     111                @param spotlightRange.x innerAngle (The angle covered by the bright inner cone)
     112                @param spotlightRange.x outerAngle (The angle covered by the outer cone)
     113                @param spotlightRange.x falloff (The rate of falloff between the inner and outer cones. 1.0 means a linear falloff, less means slower falloff, higher means faster falloff.)
     114            */
     115            inline void setSpotlightRange(const Vector3& spotlightRange)
     116                { this->spotlightRange_ = spotlightRange; this->updateSpotlightRange(); }
     117            inline const Vector3& getSpotlightRange() const
     118                { return this->spotlightRange_; }
    71119
    72120        private:
     
    74122            std::string getTypeString() const;
    75123
    76             void changedType();
     124            void updateType();
     125            void updateDiffuseColour();
     126            void updateSpecularColour();
     127            void updateAttenuation();
     128            void updateSpotlightRange();
    77129
    78             static unsigned int lightCounter_s;
    79130            Ogre::Light* light_;
    80131            Ogre::Light::LightTypes type_;
    81 
     132            ColourValue diffuse_;
     133            ColourValue specular_;
     134            Vector4 attenuation_;
     135            Vector3 spotlightRange_;
    82136    };
    83137}
  • code/branches/objecthierarchy2/src/orxonox/objects/worldentities/Model.cc

    r2171 r2447  
    4141    {
    4242        RegisterObject(Model);
     43
     44        this->bCastShadows_ = true;
    4345
    4446        this->registerVariables();
  • code/branches/objecthierarchy2/src/orxonox/objects/worldentities/pawns/Pawn.cc

    r2438 r2447  
    180180            effect->setOrientation(this->getOrientation());
    181181            effect->setDestroyAfterLife(true);
    182             effect->setSource("Orxonox/explosion2");
     182            effect->setSource("Orxonox/explosion2b");
    183183            effect->setLifetime(4.0f);
    184184        }
Note: See TracChangeset for help on using the changeset viewer.