Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 2274 was 2245, checked in by scheusso, 16 years ago

most coding is done, still testing now
types should get transfered in platform independent formats now

  • 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        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);
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        this->light_->setType(this->type_);
166    }
167
168    void Light::changedVisibility()
169    {
170        SUPER(Light, changedVisibility);
171
172        this->light_->setVisible(this->isVisible());
173    }
174}
Note: See TracBrowser for help on using the repository browser.