Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/objecthierarchy2/src/orxonox/objects/Scene.cc @ 2732

Last change on this file since 2732 was 2447, checked in by landauf, 16 years ago
  • 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.

  • Property svn:eol-style set to native
File size: 5.1 KB
RevLine 
[2072]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 "Scene.h"
31
32#include <OgreRoot.h>
33#include <OgreSceneManagerEnumerator.h>
34#include <OgreSceneNode.h>
35
36#include "core/CoreIncludes.h"
37#include "core/Core.h"
38#include "core/XMLPort.h"
39
40namespace orxonox
41{
42    CreateFactory(Scene);
43
[2171]44    Scene::Scene(BaseObject* creator) : BaseObject(creator), Synchronisable(creator)
[2072]45    {
46        RegisterObject(Scene);
47
48        this->setScene(this);
[2447]49        this->bShadows_ = true;
[2072]50
51        if (Core::showsGraphics())
52        {
53            if (Ogre::Root::getSingletonPtr())
54            {
55                this->sceneManager_ = Ogre::Root::getSingleton().createSceneManager(Ogre::ST_GENERIC);
56                this->rootSceneNode_ = this->sceneManager_->getRootSceneNode();
57            }
58            else
59            {
60                this->sceneManager_ = 0;
61                this->rootSceneNode_ = 0;
62            }
63        }
64        else
65        {
66            // create a dummy SceneManager of our own since we don't have Ogre::Root.
67            this->sceneManager_ = new Ogre::DefaultSceneManager("");
68            this->rootSceneNode_ = this->sceneManager_->getRootSceneNode();
69        }
70
71        this->registerVariables();
72    }
73
74    Scene::~Scene()
75    {
76        if (this->isInitialized())
77        {
78            if (Ogre::Root::getSingletonPtr())
79            {
80//                this->sceneManager_->destroySceneNode(this->rootSceneNode_->getName()); // TODO: remove getName() for newer versions of Ogre
81                Ogre::Root::getSingleton().destroySceneManager(this->sceneManager_);
82            }
83            else if (!Core::showsGraphics())
84            {
85                delete this->sceneManager_;
86            }
87        }
88    }
89
90    void Scene::XMLPort(Element& xmlelement, XMLPort::Mode mode)
91    {
92        SUPER(Scene, XMLPort, xmlelement, mode);
93
94        XMLPortParam(Scene, "skybox", setSkybox, getSkybox, xmlelement, mode);
95        XMLPortParam(Scene, "ambientlight", setAmbientLight, getAmbientLight, xmlelement, mode).defaultValues(ColourValue(0.2, 0.2, 0.2, 1));
96        XMLPortParam(Scene, "shadow", setShadow, getShadow, xmlelement, mode).defaultValues(true);
97
98        XMLPortObjectExtended(Scene, BaseObject, "", addObject, getObject, xmlelement, mode, true, false);
99    }
100
101    void Scene::registerVariables()
102    {
[2171]103        REGISTERSTRING(this->skybox_,     direction::toclient, new NetworkCallback<Scene>(this, &Scene::networkcallback_applySkybox));
104        REGISTERDATA(this->ambientLight_, direction::toclient, new NetworkCallback<Scene>(this, &Scene::networkcallback_applyAmbientLight));
[2447]105        REGISTERDATA(this->bShadows_,     direction::toclient, new NetworkCallback<Scene>(this, &Scene::networkcallback_applyShadows));
[2072]106    }
107
108    void Scene::setSkybox(const std::string& skybox)
109    {
110        if (Core::showsGraphics() && this->sceneManager_)
111            this->sceneManager_->setSkyBox(true, skybox);
112
113        this->skybox_ = skybox;
114    }
115
116    void Scene::setAmbientLight(const ColourValue& colour)
117    {
118        if (Core::showsGraphics() && this->sceneManager_)
119            this->sceneManager_->setAmbientLight(colour);
120
121        this->ambientLight_ = colour;
122    }
123
124    void Scene::setShadow(bool bShadow)
125    {
126        if (Core::showsGraphics() && this->sceneManager_)
127        {
128            if (bShadow)
129                this->sceneManager_->setShadowTechnique(Ogre::SHADOWTYPE_STENCIL_ADDITIVE);
130            else
131                this->sceneManager_->setShadowTechnique(Ogre::SHADOWTYPE_NONE);
132        }
133
134        this->bShadows_ = bShadow;
135    }
136
137    void Scene::addObject(BaseObject* object)
138    {
139        this->objects_.push_back(object);
140        object->setScene(this);
141    }
142
143    BaseObject* Scene::getObject(unsigned int index) const
144    {
145        unsigned int i = 0;
146        for (std::list<BaseObject*>::const_iterator it = this->objects_.begin(); it != this->objects_.end(); ++it)
147        {
148            if (i == index)
149                return (*it);
150            ++i;
151        }
152        return 0;
153    }
[2171]154
155    void Scene::tick(float dt)
156    {
[2361]157        SUPER(Scene, tick, dt);
158
[2171]159        if (!Core::showsGraphics())
160        {
161            // We need to update the scene nodes if we don't render
162            this->rootSceneNode_->_update(true, false);
163        }
164    }
[2072]165}
Note: See TracBrowser for help on using the repository browser.