[1039] | 1 | /* |
---|
| 2 | * ORXONOX - the hottest 3D action shooter ever to exist |
---|
| 3 | * |
---|
| 4 | * |
---|
| 5 | * License notice: |
---|
| 6 | * |
---|
| 7 | * This program is free software; you can redistribute it and/or |
---|
| 8 | * modify it under the terms of the GNU General Public License |
---|
| 9 | * as published by the Free Software Foundation; either version 2 |
---|
| 10 | * of the License, or (at your option) any later version. |
---|
| 11 | * |
---|
| 12 | * This program is distributed in the hope that it will be useful, |
---|
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 15 | * GNU General Public License for more details. |
---|
| 16 | * |
---|
| 17 | * You should have received a copy of the GNU General Public License |
---|
| 18 | * along with this program; if not, write to the Free Software |
---|
| 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
---|
| 20 | * |
---|
| 21 | * Author: |
---|
| 22 | * Fabian 'x3n' Landau |
---|
| 23 | * Co-authors: |
---|
| 24 | * ... |
---|
| 25 | * |
---|
| 26 | */ |
---|
[784] | 27 | |
---|
[786] | 28 | #include "OrxonoxStableHeaders.h" |
---|
[1039] | 29 | #include "Camera.h" |
---|
[784] | 30 | |
---|
[715] | 31 | #include <string> |
---|
| 32 | |
---|
[515] | 33 | #include <OgreSceneManager.h> |
---|
| 34 | #include <OgreSceneNode.h> |
---|
| 35 | #include <OgreRenderWindow.h> |
---|
[708] | 36 | #include <OgreViewport.h> |
---|
[515] | 37 | |
---|
[742] | 38 | #include "util/tinyxml/tinyxml.h" |
---|
| 39 | #include "util/Tokenizer.h" |
---|
| 40 | #include "util/String2Number.h" |
---|
| 41 | #include "util/Math.h" |
---|
[1032] | 42 | #include "core/Debug.h" |
---|
| 43 | #include "core/CoreIncludes.h" |
---|
| 44 | #include "GraphicsEngine.h" |
---|
[515] | 45 | |
---|
| 46 | namespace orxonox |
---|
| 47 | { |
---|
| 48 | CreateFactory(Camera); |
---|
| 49 | |
---|
| 50 | Camera::Camera() |
---|
| 51 | { |
---|
| 52 | RegisterObject(Camera); |
---|
| 53 | } |
---|
| 54 | |
---|
| 55 | Camera::~Camera() |
---|
| 56 | { |
---|
| 57 | } |
---|
| 58 | |
---|
| 59 | void Camera::loadParams(TiXmlElement* xmlElem) |
---|
| 60 | { |
---|
[1032] | 61 | Ogre::SceneManager* mgr = GraphicsEngine::getSingleton().getSceneManager(); |
---|
[560] | 62 | |
---|
[618] | 63 | if (xmlElem->Attribute("name") && xmlElem->Attribute("pos") && xmlElem->Attribute("lookat") && xmlElem->Attribute("node")) |
---|
| 64 | { |
---|
| 65 | // <Camera name="Camera" pos="0,0,-250" lookat="0,0,0" /> |
---|
[560] | 66 | |
---|
[715] | 67 | std::string name = xmlElem->Attribute("name"); |
---|
| 68 | std::string pos = xmlElem->Attribute("pos"); |
---|
| 69 | std::string lookat = xmlElem->Attribute("lookat"); |
---|
[515] | 70 | |
---|
[618] | 71 | Ogre::Camera *cam = mgr->createCamera(name); |
---|
[515] | 72 | |
---|
[618] | 73 | float x, y, z; |
---|
[715] | 74 | std::vector<std::string> posVec = tokenize(xmlElem->Attribute("pos"),","); |
---|
[708] | 75 | String2Number<float>(x, posVec[0]); |
---|
[618] | 76 | String2Number<float>(y, posVec[1]); |
---|
| 77 | String2Number<float>(z, posVec[2]); |
---|
[515] | 78 | |
---|
[618] | 79 | cam->setPosition(Vector3(x,y,z)); |
---|
[515] | 80 | |
---|
[618] | 81 | posVec = tokenize(xmlElem->Attribute("lookat"),","); |
---|
| 82 | String2Number<float>(x, posVec[0]); |
---|
| 83 | String2Number<float>(y, posVec[1]); |
---|
| 84 | String2Number<float>(z, posVec[2]); |
---|
[515] | 85 | |
---|
[618] | 86 | cam->lookAt(Vector3(x,y,z)); |
---|
[515] | 87 | |
---|
[715] | 88 | std::string node = xmlElem->Attribute("node"); |
---|
[560] | 89 | |
---|
[618] | 90 | Ogre::SceneNode* sceneNode = (Ogre::SceneNode*)mgr->getRootSceneNode()->createChildSceneNode(node); //getChild(node); |
---|
| 91 | sceneNode->attachObject((Ogre::MovableObject*)cam); |
---|
[560] | 92 | |
---|
[660] | 93 | // FIXME: unused var |
---|
[1032] | 94 | Ogre::Viewport* vp = GraphicsEngine::getSingleton().getRenderWindow()->addViewport(cam); |
---|
[515] | 95 | |
---|
[560] | 96 | |
---|
[618] | 97 | COUT(4) << "Loader: Created camera "<< name << std::endl << std::endl; |
---|
| 98 | } |
---|
[515] | 99 | } |
---|
| 100 | } |
---|