Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/objecthierarchy2/src/orxonox/objects/worldentities/Light.cc @ 2274

Last change on this file since 2274 was 2254, checked in by landauf, 16 years ago

Update your media repository and delete keybindings.ini if you want to use boost (space).

  • Added new class "Engine" to control the speed of a SpaceShip (Engine is an Item, MultiStateEngine is a specialized version of Engine)
  • Added FadingBillboard, a billboard with the ability to fade in and out smoothly when activated/deactivated.
  • Several changes in Backlight, it's now a child of FadingBillboard
  • Some changes concerning local control in ControllableEntity
  • Fixed a bug in WorldEntity caused by different destruction order of attached objects on server and client
  • Added a "MainState" to BaseObject. An object has several states (activity, visibility, …) and one of it can be defined as "MainState" in the XML file. Other objects can change this state without knowing which state it really is (used by MultiStateEngine).
  • Property svn:eol-style set to native
File size: 5.2 KB
Line 
1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *                    > www.orxonox.net <
4 *
5 *
6 *   License notice:
7 *
8 *   This program is free software; you can redistribute it and/or
9 *   modify it under the terms of the GNU General Public License
10 *   as published by the Free Software Foundation; either version 2
11 *   of the License, or (at your option) any later version.
12 *
13 *   This program is distributed in the hope that it will be useful,
14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 *   GNU General Public License for more details.
17 *
18 *   You should have received a copy of the GNU General Public License
19 *   along with this program; if not, write to the Free Software
20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 *
22 *   Author:
23 *      Fabian 'x3n' Landau
24 *   Co-authors:
25 *      ...
26 *
27 */
28
29#include "OrxonoxStableHeaders.h"
30#include "Light.h"
31
32#include <sstream>
33#include <cassert>
34
35#include <OgreSceneManager.h>
36
37#include "util/String.h"
38#include "util/Convert.h"
39#include "core/CoreIncludes.h"
40#include "core/XMLPort.h"
41#include "objects/Scene.h"
42
43namespace orxonox
44{
45    unsigned int Light::lightCounter_s = 0;
46
47    CreateFactory(Light);
48
49    Light::Light(BaseObject* creator) : PositionableEntity(creator)
50    {
51        RegisterObject(Light);
52
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_);
56
57        this->registerVariables();
58    }
59
60    Light::~Light()
61    {
62        if (this->isInitialized())
63        {
64            if (this->light_ && this->getScene() && this->getScene()->getSceneManager())
65                this->getScene()->getSceneManager()->destroyLight(this->light_);
66        }
67    }
68
69    void Light::XMLPort(Element& xmlelement, XMLPort::Mode mode)
70    {
71        SUPER(Light, XMLPort, xmlelement, mode);
72
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&);
77    }
78
79    void Light::registerVariables()
80    {
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);
85    }
86
87    const std::string& Light::getName() const
88    {
89        if (this->light_)
90            return this->light_->getName();
91        else
92            return BLANKSTRING;
93    }
94
95    void Light::setDiffuseColour(const ColourValue& colour)
96    {
97        if (this->light_)
98            this->light_->setDiffuseColour(colour);
99    }
100
101    const ColourValue& Light::getDiffuseColour() const
102    {
103        if (this->light_)
104            return this->light_->getDiffuseColour();
105        else
106            return ColourValue::White;
107    }
108
109    void Light::setSpecularColour(const ColourValue& colour)
110    {
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;
135    }
136
137    void Light::setTypeString(const std::string& type)
138    {
139        if (type == "point")
140            this->setType(Ogre::Light::LT_POINT);
141        else if (type == "directional")
142            this->setType(Ogre::Light::LT_DIRECTIONAL);
143        else if (type == "spotlight")
144            this->setType(Ogre::Light::LT_SPOTLIGHT);
145        else
146            this->setType(Ogre::Light::LT_POINT);
147    }
148
149    std::string Light::getTypeString() const
150    {
151        switch (this->type_)
152        {
153            case Ogre::Light::LT_DIRECTIONAL:
154                return "directional";
155            case Ogre::Light::LT_SPOTLIGHT:
156                return "spotlight";
157            case Ogre::Light::LT_POINT:
158            default:
159                return "poinT";
160        }
161    }
162
163    void Light::changedType()
164    {
165        if (this->light_)
166            this->light_->setType(this->type_);
167    }
168
169    void Light::changedVisibility()
170    {
171        SUPER(Light, changedVisibility);
172
173        if (this->light_)
174            this->light_->setVisible(this->isVisible());
175    }
176}
Note: See TracBrowser for help on using the repository browser.