1 | #include <OgreSceneManager.h> |
---|
2 | #include <OgreSceneNode.h> |
---|
3 | #include <OgreRoot.h> |
---|
4 | #include <OgreRenderWindow.h> |
---|
5 | #include <OgreViewport.h> |
---|
6 | |
---|
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" |
---|
14 | #include "../Orxonox.h" |
---|
15 | #include "../GraphicsEngine.h" |
---|
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 | { |
---|
34 | Ogre::SceneManager* mgr = orxonox::Orxonox::getSingleton()->getSceneManager(); |
---|
35 | |
---|
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" /> |
---|
39 | |
---|
40 | String name = xmlElem->Attribute("name"); |
---|
41 | String pos = xmlElem->Attribute("pos"); |
---|
42 | String lookat = xmlElem->Attribute("lookat"); |
---|
43 | |
---|
44 | Ogre::Camera *cam = mgr->createCamera(name); |
---|
45 | |
---|
46 | float x, y, z; |
---|
47 | std::vector<String> posVec = tokenize(xmlElem->Attribute("pos"),","); |
---|
48 | String2Number<float>(x, posVec[0]); |
---|
49 | String2Number<float>(y, posVec[1]); |
---|
50 | String2Number<float>(z, posVec[2]); |
---|
51 | |
---|
52 | cam->setPosition(Vector3(x,y,z)); |
---|
53 | |
---|
54 | posVec = tokenize(xmlElem->Attribute("lookat"),","); |
---|
55 | String2Number<float>(x, posVec[0]); |
---|
56 | String2Number<float>(y, posVec[1]); |
---|
57 | String2Number<float>(z, posVec[2]); |
---|
58 | |
---|
59 | cam->lookAt(Vector3(x,y,z)); |
---|
60 | |
---|
61 | String node = xmlElem->Attribute("node"); |
---|
62 | |
---|
63 | Ogre::SceneNode* sceneNode = (Ogre::SceneNode*)mgr->getRootSceneNode()->createChildSceneNode(node); //getChild(node); |
---|
64 | sceneNode->attachObject((Ogre::MovableObject*)cam); |
---|
65 | |
---|
66 | // FIXME: unused var |
---|
67 | Ogre::Viewport* vp = orxonox::Orxonox::getSingleton()->getOgrePointer()->getRoot()->getAutoCreatedWindow()->addViewport(cam); |
---|
68 | |
---|
69 | |
---|
70 | COUT(4) << "Loader: Created camera "<< name << std::endl << std::endl; |
---|
71 | } |
---|
72 | } |
---|
73 | } |
---|