Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/FICN/src/orxonox/objects/SceneNode.cc @ 580

Last change on this file since 580 was 580, checked in by rgrieder, 16 years ago
  • fixed the problem about the ship being static.
  • added SceneNode hierarchy support in parser
File size: 2.2 KB
Line 
1#include <OgreSceneManager.h>
2#include <string>
3
4#include "../orxonox.h"
5#include "../../tinyxml/tinyxml.h"
6#include "../../misc/Tokenizer.h"
7#include "../../misc/String2Number.h"
8#include "../core/Debug.h"
9
10#include "SceneNode.h"
11
12namespace orxonox
13{
14    CreateFactory(SceneNode);
15
16    SceneNode::SceneNode()
17    {
18        RegisterObject(SceneNode);
19    }
20
21    SceneNode::~SceneNode()
22    {
23    }
24
25    void SceneNode::loadParams(TiXmlElement* xmlElem)
26    {
27        Ogre::SceneManager* mgr = orxonox::Orxonox::getSingleton()->getSceneManager();
28
29        if (xmlElem->Attribute("name") && xmlElem->Attribute("pos"))
30        {
31                std::string name = xmlElem->Attribute("name");
32
33                std::vector<std::string> pos = tokenize(xmlElem->Attribute("pos"),",");
34                float x, y, z;
35                String2Number<float>(x, pos[0]);
36                String2Number<float>(y, pos[1]);
37                String2Number<float>(z, pos[2]);
38
39        float sx = 1, sy = 1, sz = 1;
40        if (xmlElem->Attribute("scale"))
41        {
42                  pos = tokenize(xmlElem->Attribute("scale"),",");
43                  String2Number<float>(sx, pos[0]);
44                  String2Number<float>(sy, pos[1]);
45                  String2Number<float>(sz, pos[2]);
46        }
47
48        float yaw = 0.0;
49        if (xmlElem->Attribute("yaw"))
50        {
51          String2Number<float>(yaw,xmlElem->Attribute("yaw"));
52        }
53        float pitch = 0.0;
54        if (xmlElem->Attribute("pitch"))
55        {
56          String2Number<float>(pitch,xmlElem->Attribute("pitch"));
57        }
58        float roll = 0.0;
59        if (xmlElem->Attribute("roll"))
60        {
61          String2Number<float>(roll,xmlElem->Attribute("roll"));
62        }
63
64        Ogre::SceneNode *parentNode;
65        if (xmlElem->Attribute("node"))
66          parentNode = mgr->getSceneNode(xmlElem->Attribute("node"));
67        else
68          parentNode = mgr->getRootSceneNode();
69
70        Ogre::SceneNode* node = parentNode->createChildSceneNode(name, Vector3(x,y,z));
71        node->scale(sx,sy,sz);
72        node->yaw(Ogre::Degree(yaw));
73        node->pitch(Ogre::Degree(pitch));
74        node->roll(Ogre::Degree(roll));
75
76                COUT(4) << "Loader: Created node "<< name <<" : "<<x<<" " << y << " " << z  << std::endl << std::endl;
77        }
78   }
79}
Note: See TracBrowser for help on using the repository browser.