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