Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/orxonox/objects/Camera.cc @ 1067

Last change on this file since 1067 was 1067, checked in by rgrieder, 16 years ago

Substring.h —> SubString.h

File size: 3.1 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 "Camera.h"
31
32#include <string>
33
34#include <OgreSceneManager.h>
35#include <OgreSceneNode.h>
36#include <OgreRenderWindow.h>
37#include <OgreViewport.h>
38
39#include "util/tinyxml/tinyxml.h"
40#include "util/SubString.h"
41#include "util/Convert.h"
42#include "util/Math.h"
43#include "core/Debug.h"
44#include "core/CoreIncludes.h"
45#include "GraphicsEngine.h"
46
47namespace orxonox
48{
49    CreateFactory(Camera);
50
51    Camera::Camera()
52    {
53        RegisterObject(Camera);
54    }
55
56    Camera::~Camera()
57    {
58    }
59
60    void Camera::loadParams(TiXmlElement* xmlElem)
61    {
62      Ogre::SceneManager* mgr = GraphicsEngine::getSingleton().getSceneManager();
63
64      if (xmlElem->Attribute("name") && xmlElem->Attribute("pos") && xmlElem->Attribute("lookat") && xmlElem->Attribute("node"))
65      {
66        //    <Camera name="Camera" pos="0,0,-250" lookat="0,0,0" />
67
68        std::string name = xmlElem->Attribute("name");
69        std::string pos = xmlElem->Attribute("pos");
70        std::string lookat = xmlElem->Attribute("lookat");
71
72        Ogre::Camera *cam = mgr->createCamera(name);
73
74        float x, y, z;
75        SubString posVec(xmlElem->Attribute("pos"), ',');
76        convertValue<std::string, float>(&x, posVec[0]);
77        convertValue<std::string, float>(&y, posVec[1]);
78        convertValue<std::string, float>(&z, posVec[2]);
79
80        cam->setPosition(Vector3(x,y,z));
81
82        posVec = SubString(xmlElem->Attribute("lookat"), ',');
83        convertValue<std::string, float>(&x, posVec[0]);
84        convertValue<std::string, float>(&y, posVec[1]);
85        convertValue<std::string, float>(&z, posVec[2]);
86
87        cam->lookAt(Vector3(x,y,z));
88
89        std::string node = xmlElem->Attribute("node");
90
91        Ogre::SceneNode* sceneNode = (Ogre::SceneNode*)mgr->getRootSceneNode()->createChildSceneNode(node); //getChild(node);
92        sceneNode->attachObject((Ogre::MovableObject*)cam);
93
94        // FIXME: unused var
95        //Ogre::Viewport* vp =
96        GraphicsEngine::getSingleton().getRenderWindow()->addViewport(cam);
97
98
99        COUT(4) << "Loader: Created camera "<< name  << std::endl << std::endl;
100      }
101   }
102}
Note: See TracBrowser for help on using the repository browser.