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