| 1 | #include <OgreSceneManager.h> | 
|---|
| 2 | #include <OgreSceneNode.h> | 
|---|
| 3 | #include <OgreRoot.h> | 
|---|
| 4 | #include <OgreRenderWindow.h> | 
|---|
| 5 |  | 
|---|
| 6 | #include <string> | 
|---|
| 7 |  | 
|---|
| 8 | #include "../orxonox.h" | 
|---|
| 9 | #include "../graphicsEngine.h" | 
|---|
| 10 | #include "../../tinyxml/tinyxml.h" | 
|---|
| 11 | #include "../../misc/Tokenizer.h" | 
|---|
| 12 | #include "../../misc/String2Number.h" | 
|---|
| 13 |  | 
|---|
| 14 | #include "Camera.h" | 
|---|
| 15 |  | 
|---|
| 16 | namespace orxonox | 
|---|
| 17 | { | 
|---|
| 18 |     CreateFactory(Camera); | 
|---|
| 19 |  | 
|---|
| 20 |     Camera::Camera() | 
|---|
| 21 |     { | 
|---|
| 22 |         RegisterObject(Camera); | 
|---|
| 23 |     } | 
|---|
| 24 |  | 
|---|
| 25 |     Camera::~Camera() | 
|---|
| 26 |     { | 
|---|
| 27 |     } | 
|---|
| 28 |  | 
|---|
| 29 |     void Camera::loadParams(TiXmlElement* xmlElem) | 
|---|
| 30 |     { | 
|---|
| 31 |         Ogre::SceneManager* mgr = orxonox::Orxonox::getSingleton()->getSceneManager(); | 
|---|
| 32 |          | 
|---|
| 33 |         if (xmlElem->Attribute("name") && xmlElem->Attribute("pos") && xmlElem->Attribute("lookat") && xmlElem->Attribute("node")) | 
|---|
| 34 |         { | 
|---|
| 35 |                 //              <Camera name="Camera" pos="0,0,-250" lookat="0,0,0" /> | 
|---|
| 36 |                  | 
|---|
| 37 |                 std::string name = xmlElem->Attribute("name"); | 
|---|
| 38 |                 std::string pos = xmlElem->Attribute("pos"); | 
|---|
| 39 |                 std::string lookat = xmlElem->Attribute("lookat"); | 
|---|
| 40 |  | 
|---|
| 41 |                 Ogre::Camera *cam = mgr->createCamera(name); | 
|---|
| 42 |  | 
|---|
| 43 |                 float x, y, z; | 
|---|
| 44 |                 std::vector<std::string> posVec = tokenize(xmlElem->Attribute("pos"),","); | 
|---|
| 45 |                 String2Number<float>(x, posVec[0]); | 
|---|
| 46 |                 String2Number<float>(y, posVec[1]); | 
|---|
| 47 |                 String2Number<float>(z, posVec[2]); | 
|---|
| 48 |  | 
|---|
| 49 |                 cam->setPosition(Vector3(x,y,z)); | 
|---|
| 50 |  | 
|---|
| 51 |                 posVec = tokenize(xmlElem->Attribute("lookat"),","); | 
|---|
| 52 |                 String2Number<float>(x, posVec[0]); | 
|---|
| 53 |                 String2Number<float>(y, posVec[1]); | 
|---|
| 54 |                 String2Number<float>(z, posVec[2]); | 
|---|
| 55 |  | 
|---|
| 56 |                 cam->lookAt(Vector3(x,y,z)); | 
|---|
| 57 |  | 
|---|
| 58 |                 std::string node = xmlElem->Attribute("node"); | 
|---|
| 59 |                  | 
|---|
| 60 |                     Ogre::SceneNode* sceneNode = (Ogre::SceneNode*)mgr->getRootSceneNode()->getChild(node); | 
|---|
| 61 |                     sceneNode->attachObject((Ogre::MovableObject*)cam); | 
|---|
| 62 |              | 
|---|
| 63 |                  | 
|---|
| 64 |                     Ogre::Viewport* vp = orxonox::Orxonox::getSingleton()->getOgrePointer()->getRoot()->getAutoCreatedWindow()->addViewport(cam); | 
|---|
| 65 |                              | 
|---|
| 66 |  | 
|---|
| 67 |                 std::cout << "Loader: Created camera "<< name  << std::endl << std::endl; | 
|---|
| 68 |         }        | 
|---|
| 69 |    } | 
|---|
| 70 | } | 
|---|