1 | |
---|
2 | #include "OrxonoxStableHeaders.h" |
---|
3 | |
---|
4 | #include <string> |
---|
5 | |
---|
6 | #include <OgreSceneManager.h> |
---|
7 | #include <OgreSceneNode.h> |
---|
8 | #include <OgreRenderWindow.h> |
---|
9 | #include <OgreViewport.h> |
---|
10 | |
---|
11 | #include "util/tinyxml/tinyxml.h" |
---|
12 | #include "util/Tokenizer.h" |
---|
13 | #include "util/String2Number.h" |
---|
14 | #include "util/Math.h" |
---|
15 | #include "core/Debug.h" |
---|
16 | #include "core/CoreIncludes.h" |
---|
17 | #include "GraphicsEngine.h" |
---|
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 | { |
---|
36 | Ogre::SceneManager* mgr = GraphicsEngine::getSingleton().getSceneManager(); |
---|
37 | |
---|
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" /> |
---|
41 | |
---|
42 | std::string name = xmlElem->Attribute("name"); |
---|
43 | std::string pos = xmlElem->Attribute("pos"); |
---|
44 | std::string lookat = xmlElem->Attribute("lookat"); |
---|
45 | |
---|
46 | Ogre::Camera *cam = mgr->createCamera(name); |
---|
47 | |
---|
48 | float x, y, z; |
---|
49 | std::vector<std::string> posVec = tokenize(xmlElem->Attribute("pos"),","); |
---|
50 | String2Number<float>(x, posVec[0]); |
---|
51 | String2Number<float>(y, posVec[1]); |
---|
52 | String2Number<float>(z, posVec[2]); |
---|
53 | |
---|
54 | cam->setPosition(Vector3(x,y,z)); |
---|
55 | |
---|
56 | posVec = tokenize(xmlElem->Attribute("lookat"),","); |
---|
57 | String2Number<float>(x, posVec[0]); |
---|
58 | String2Number<float>(y, posVec[1]); |
---|
59 | String2Number<float>(z, posVec[2]); |
---|
60 | |
---|
61 | cam->lookAt(Vector3(x,y,z)); |
---|
62 | |
---|
63 | std::string node = xmlElem->Attribute("node"); |
---|
64 | |
---|
65 | Ogre::SceneNode* sceneNode = (Ogre::SceneNode*)mgr->getRootSceneNode()->createChildSceneNode(node); //getChild(node); |
---|
66 | sceneNode->attachObject((Ogre::MovableObject*)cam); |
---|
67 | |
---|
68 | // FIXME: unused var |
---|
69 | Ogre::Viewport* vp = GraphicsEngine::getSingleton().getRenderWindow()->addViewport(cam); |
---|
70 | |
---|
71 | |
---|
72 | COUT(4) << "Loader: Created camera "<< name << std::endl << std::endl; |
---|
73 | } |
---|
74 | } |
---|
75 | } |
---|