Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/objecthierarchy/src/orxonox/objects/Scene.cc @ 2019

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

many changes, most important: BaseObject takes now a pointer to it's creator which is needed to build a level hierarchy (with different scenes)

File size: 4.7 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 "Scene.h"
31
32#include <OgreRoot.h>
33#include <OgreSceneManager.h>
34#include <OgreSceneNode.h>
35#include <OgreLight.h>
36
37#include "core/CoreIncludes.h"
38#include "core/XMLPort.h"
39
40namespace orxonox
41{
42    CreateFactory(Scene);
43
44    Scene::Scene(BaseObject* creator) : BaseObject(creator)
45    {
46        RegisterObject(Scene);
47
48        this->setScene(this);
49        this->bShadows_ = false;
50
51        if (Ogre::Root::getSingletonPtr())
52        {
53            this->sceneManager_ = Ogre::Root::getSingleton().createSceneManager(Ogre::ST_GENERIC);
54            this->rootSceneNode_ = this->sceneManager_->getRootSceneNode();
55        }
56        else
57        {
58            this->sceneManager_ = 0;
59            this->rootSceneNode_ = 0;
60        }
61
62        // test test test
63        if (this->sceneManager_)
64        {
65            Ogre::Light* light;
66            light = this->sceneManager_->createLight("Light0");
67            light->setType(Ogre::Light::LT_DIRECTIONAL);
68            light->setDiffuseColour(ColourValue(1.0, 0.9, 0.6, 1.0));
69            light->setSpecularColour(ColourValue(1.0, 0.9, 0.6, 1.0));
70            light->setDirection(1, -0.2, 0.2);
71        }
72        // test test test
73    }
74
75    Scene::~Scene()
76    {
77        if (Ogre::Root::getSingletonPtr())
78        {
79//            this->sceneManager_->destroySceneNode(this->rootSceneNode_->getName()); // TODO: remove getName() for newer versions of Ogre
80            Ogre::Root::getSingleton().destroySceneManager(this->sceneManager_);
81        }
82        else
83        {
84        }
85    }
86
87    void Scene::XMLPort(Element& xmlelement, XMLPort::Mode mode)
88    {
89        SUPER(Scene, XMLPort, xmlelement, mode);
90
91        XMLPortParam(Scene, "skybox", setSkybox, getSkybox, xmlelement, mode);
92        XMLPortParam(Scene, "ambientlight", setAmbientLight, getAmbientLight, xmlelement, mode).defaultValues(ColourValue(0.2, 0.2, 0.2, 1));
93        XMLPortParam(Scene, "shadow", setShadow, getShadow, xmlelement, mode).defaultValues(true);
94
95        XMLPortObjectExtended(Scene, BaseObject, "", addObject, getObject, xmlelement, mode, true, false);
96    }
97
98    void Scene::registerVariables()
99    {
100        REGISTERSTRING(this->skybox_,     network::direction::toclient, new network::NetworkCallback<Scene>(this, &Scene::networkcallback_applySkybox));
101        REGISTERDATA(this->ambientLight_, network::direction::toclient, new network::NetworkCallback<Scene>(this, &Scene::networkcallback_applyAmbientLight));
102    }
103
104    void Scene::setSkybox(const std::string& skybox)
105    {
106        if (this->sceneManager_)
107            this->sceneManager_->setSkyBox(true, skybox);
108
109        this->skybox_ = skybox;
110    }
111
112    void Scene::setAmbientLight(const ColourValue& colour)
113    {
114        if (this->sceneManager_)
115            this->sceneManager_->setAmbientLight(colour);
116
117        this->ambientLight_ = colour;
118    }
119
120    void Scene::setShadow(bool bShadow)
121    {
122        if (this->sceneManager_)
123        {
124            if (bShadow)
125                this->sceneManager_->setShadowTechnique(Ogre::SHADOWTYPE_STENCIL_ADDITIVE);
126            else
127                this->sceneManager_->setShadowTechnique(Ogre::SHADOWTYPE_NONE);
128        }
129
130        this->bShadows_ = bShadow;
131    }
132
133    void Scene::addObject(BaseObject* object)
134    {
135        this->objects_.push_back(object);
136        object->setScene(this);
137    }
138
139    BaseObject* Scene::getObject(unsigned int index) const
140    {
141        unsigned int i = 0;
142        for (std::list<BaseObject*>::const_iterator it = this->objects_.begin(); it != this->objects_.end(); ++it)
143        {
144            if (i == index)
145                return (*it);
146            ++i;
147        }
148        return 0;
149    }
150}
Note: See TracBrowser for help on using the repository browser.