[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 | #include <OgreLight.h> |
---|
| 36 | |
---|
| 37 | #include "core/CoreIncludes.h" |
---|
| 38 | #include "core/Core.h" |
---|
| 39 | #include "core/XMLPort.h" |
---|
| 40 | |
---|
| 41 | namespace orxonox |
---|
| 42 | { |
---|
| 43 | CreateFactory(Scene); |
---|
| 44 | |
---|
| 45 | Scene::Scene(BaseObject* creator) : BaseObject(creator), network::Synchronisable(creator) |
---|
| 46 | { |
---|
| 47 | RegisterObject(Scene); |
---|
| 48 | |
---|
| 49 | this->setScene(this); |
---|
| 50 | this->bShadows_ = false; |
---|
| 51 | |
---|
| 52 | if (Core::showsGraphics()) |
---|
| 53 | { |
---|
| 54 | if (Ogre::Root::getSingletonPtr()) |
---|
| 55 | { |
---|
| 56 | this->sceneManager_ = Ogre::Root::getSingleton().createSceneManager(Ogre::ST_GENERIC); |
---|
| 57 | this->rootSceneNode_ = this->sceneManager_->getRootSceneNode(); |
---|
| 58 | } |
---|
| 59 | else |
---|
| 60 | { |
---|
| 61 | this->sceneManager_ = 0; |
---|
| 62 | this->rootSceneNode_ = 0; |
---|
| 63 | } |
---|
[2150] | 64 | // create bullet world; bullet solver etc. |
---|
| 65 | |
---|
| 66 | // int maxProxies = 1024; |
---|
| 67 | |
---|
| 68 | btVector3 worldAabbMin(-10000,-10000,-10000); |
---|
| 69 | btVector3 worldAabbMax(10000,10000,10000); |
---|
| 70 | bt32BitAxisSweep3* broadphase = new bt32BitAxisSweep3(worldAabbMin,worldAabbMax); |
---|
| 71 | |
---|
| 72 | this -> collisionConfiguration_ = new btDefaultCollisionConfiguration(); |
---|
| 73 | this -> dispatcher_ = new btCollisionDispatcher(collisionConfiguration_); |
---|
| 74 | |
---|
| 75 | this -> solver_ = new btSequentialImpulseConstraintSolver; |
---|
| 76 | |
---|
| 77 | this -> dynamicsWorld_ = new btDiscreteDynamicsWorld(dispatcher_,broadphase,solver_,collisionConfiguration_); |
---|
| 78 | |
---|
| 79 | // dynamicsWorld->setGravity(btVector3(0,-10,0)); |
---|
| 80 | |
---|
[2072] | 81 | } |
---|
| 82 | else |
---|
| 83 | { |
---|
| 84 | // create a dummy SceneManager of our own since we don't have Ogre::Root. |
---|
| 85 | this->sceneManager_ = new Ogre::DefaultSceneManager(""); |
---|
| 86 | this->rootSceneNode_ = this->sceneManager_->getRootSceneNode(); |
---|
| 87 | } |
---|
| 88 | |
---|
| 89 | // test test test |
---|
| 90 | if (Core::showsGraphics() && this->sceneManager_) |
---|
| 91 | { |
---|
| 92 | Ogre::Light* light; |
---|
| 93 | light = this->sceneManager_->createLight("Light-1"); |
---|
| 94 | light->setType(Ogre::Light::LT_DIRECTIONAL); |
---|
| 95 | light->setDiffuseColour(ColourValue(1.0, 0.9, 0.6, 1.0)); |
---|
| 96 | light->setSpecularColour(ColourValue(1.0, 0.9, 0.6, 1.0)); |
---|
| 97 | light->setDirection(1, -0.3, 0.3); |
---|
| 98 | } |
---|
| 99 | // test test test |
---|
| 100 | |
---|
| 101 | this->registerVariables(); |
---|
| 102 | } |
---|
| 103 | |
---|
| 104 | Scene::~Scene() |
---|
| 105 | { |
---|
| 106 | if (this->isInitialized()) |
---|
| 107 | { |
---|
| 108 | if (Ogre::Root::getSingletonPtr()) |
---|
| 109 | { |
---|
| 110 | // this->sceneManager_->destroySceneNode(this->rootSceneNode_->getName()); // TODO: remove getName() for newer versions of Ogre |
---|
| 111 | Ogre::Root::getSingleton().destroySceneManager(this->sceneManager_); |
---|
| 112 | } |
---|
| 113 | else if (!Core::showsGraphics()) |
---|
| 114 | { |
---|
| 115 | delete this->sceneManager_; |
---|
| 116 | } |
---|
| 117 | } |
---|
| 118 | } |
---|
| 119 | |
---|
| 120 | void Scene::XMLPort(Element& xmlelement, XMLPort::Mode mode) |
---|
| 121 | { |
---|
| 122 | SUPER(Scene, XMLPort, xmlelement, mode); |
---|
| 123 | |
---|
| 124 | XMLPortParam(Scene, "skybox", setSkybox, getSkybox, xmlelement, mode); |
---|
| 125 | XMLPortParam(Scene, "ambientlight", setAmbientLight, getAmbientLight, xmlelement, mode).defaultValues(ColourValue(0.2, 0.2, 0.2, 1)); |
---|
| 126 | XMLPortParam(Scene, "shadow", setShadow, getShadow, xmlelement, mode).defaultValues(true); |
---|
| 127 | |
---|
| 128 | XMLPortObjectExtended(Scene, BaseObject, "", addObject, getObject, xmlelement, mode, true, false); |
---|
| 129 | } |
---|
| 130 | |
---|
| 131 | void Scene::registerVariables() |
---|
| 132 | { |
---|
| 133 | REGISTERSTRING(this->skybox_, network::direction::toclient, new network::NetworkCallback<Scene>(this, &Scene::networkcallback_applySkybox)); |
---|
| 134 | REGISTERDATA(this->ambientLight_, network::direction::toclient, new network::NetworkCallback<Scene>(this, &Scene::networkcallback_applyAmbientLight)); |
---|
| 135 | } |
---|
| 136 | |
---|
| 137 | void Scene::setSkybox(const std::string& skybox) |
---|
| 138 | { |
---|
| 139 | if (Core::showsGraphics() && this->sceneManager_) |
---|
| 140 | this->sceneManager_->setSkyBox(true, skybox); |
---|
| 141 | |
---|
| 142 | this->skybox_ = skybox; |
---|
| 143 | } |
---|
| 144 | |
---|
| 145 | void Scene::setAmbientLight(const ColourValue& colour) |
---|
| 146 | { |
---|
| 147 | if (Core::showsGraphics() && this->sceneManager_) |
---|
| 148 | this->sceneManager_->setAmbientLight(colour); |
---|
| 149 | |
---|
| 150 | this->ambientLight_ = colour; |
---|
| 151 | } |
---|
| 152 | |
---|
| 153 | void Scene::setShadow(bool bShadow) |
---|
| 154 | { |
---|
| 155 | if (Core::showsGraphics() && this->sceneManager_) |
---|
| 156 | { |
---|
| 157 | if (bShadow) |
---|
| 158 | this->sceneManager_->setShadowTechnique(Ogre::SHADOWTYPE_STENCIL_ADDITIVE); |
---|
| 159 | else |
---|
| 160 | this->sceneManager_->setShadowTechnique(Ogre::SHADOWTYPE_NONE); |
---|
| 161 | } |
---|
| 162 | |
---|
| 163 | this->bShadows_ = bShadow; |
---|
| 164 | } |
---|
| 165 | |
---|
| 166 | void Scene::addObject(BaseObject* object) |
---|
| 167 | { |
---|
| 168 | this->objects_.push_back(object); |
---|
| 169 | object->setScene(this); |
---|
| 170 | } |
---|
| 171 | |
---|
| 172 | BaseObject* Scene::getObject(unsigned int index) const |
---|
| 173 | { |
---|
| 174 | unsigned int i = 0; |
---|
| 175 | for (std::list<BaseObject*>::const_iterator it = this->objects_.begin(); it != this->objects_.end(); ++it) |
---|
| 176 | { |
---|
| 177 | if (i == index) |
---|
| 178 | return (*it); |
---|
| 179 | ++i; |
---|
| 180 | } |
---|
| 181 | return 0; |
---|
| 182 | } |
---|
| 183 | } |
---|