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 | |
---|
12 | namespace 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 | if (xmlElem->Attribute("name") && xmlElem->Attribute("pos")) |
---|
28 | { |
---|
29 | name_ = xmlElem->Attribute("name"); |
---|
30 | |
---|
31 | std::vector<std::string> pos = tokenize(xmlElem->Attribute("pos"),","); |
---|
32 | //float x, y, z_; |
---|
33 | String2Number<float>(x_, pos[0]); |
---|
34 | String2Number<float>(y_, pos[1]); |
---|
35 | String2Number<float>(z_, pos[2]); |
---|
36 | |
---|
37 | sx_ = 1; sy_ = 1; sz_ = 1; |
---|
38 | if (xmlElem->Attribute("scale")) |
---|
39 | { |
---|
40 | pos = tokenize(xmlElem->Attribute("scale"),","); |
---|
41 | String2Number<float>(sx_, pos[0]); |
---|
42 | String2Number<float>(sy_, pos[1]); |
---|
43 | String2Number<float>(sz_, pos[2]); |
---|
44 | } |
---|
45 | yaw_ = 0.0; |
---|
46 | if (xmlElem->Attribute("yaw")) |
---|
47 | { |
---|
48 | String2Number<float>(yaw_,xmlElem->Attribute("yaw")); |
---|
49 | } |
---|
50 | pitch_ = 0.0; |
---|
51 | if (xmlElem->Attribute("pitch")) |
---|
52 | { |
---|
53 | String2Number<float>(pitch_,xmlElem->Attribute("pitch")); |
---|
54 | } |
---|
55 | roll_ = 0.0; |
---|
56 | if (xmlElem->Attribute("roll")) |
---|
57 | { |
---|
58 | String2Number<float>(roll_,xmlElem->Attribute("roll")); |
---|
59 | } |
---|
60 | |
---|
61 | if(xmlElem->Attribute("node")) |
---|
62 | nodeName_ = xmlElem->Attribute("node"); |
---|
63 | else |
---|
64 | nodeName_ = ""; |
---|
65 | |
---|
66 | create(); |
---|
67 | |
---|
68 | COUT(4) << "Loader: loaded node "<< name_ <<" : "<< x_ <<" " << y_ << " " << z_ << std::endl << std::endl; |
---|
69 | } |
---|
70 | } |
---|
71 | |
---|
72 | void SceneNode::registerAllVariables(){ |
---|
73 | registerVar(&x_, sizeof(float), network::DATA); |
---|
74 | registerVar(&y_, sizeof(float), network::DATA); |
---|
75 | registerVar(&z_, sizeof(float), network::DATA); |
---|
76 | registerVar(&sx_, sizeof(float), network::DATA); |
---|
77 | registerVar(&sy_, sizeof(float), network::DATA); |
---|
78 | registerVar(&sz_, sizeof(float), network::DATA); |
---|
79 | registerVar(&yaw_, sizeof(float), network::DATA); |
---|
80 | registerVar(&pitch_, sizeof(float), network::DATA); |
---|
81 | registerVar(&roll_, sizeof(float), network::DATA); |
---|
82 | registerVar(&name_, sizeof(float), network::STRING); |
---|
83 | registerVar(&nodeName_, sizeof(float), network::STRING); |
---|
84 | } |
---|
85 | |
---|
86 | bool SceneNode::create(){ |
---|
87 | Ogre::SceneManager* mgr = orxonox::Orxonox::getSingleton()->getSceneManager(); |
---|
88 | |
---|
89 | Ogre::SceneNode *parentNode; |
---|
90 | if (nodeName_.compare("")!=0) |
---|
91 | parentNode = mgr->getSceneNode(nodeName_); |
---|
92 | else |
---|
93 | parentNode = mgr->getRootSceneNode(); |
---|
94 | |
---|
95 | Ogre::SceneNode* node = parentNode->createChildSceneNode(name_, Vector3(x_,y_,z_)); |
---|
96 | node->scale(sx_,sy_,sz_); |
---|
97 | node->yaw(Ogre::Degree(yaw_)); |
---|
98 | node->pitch(Ogre::Degree(pitch_)); |
---|
99 | node->roll(Ogre::Degree(roll_)); |
---|
100 | return true; |
---|
101 | } |
---|
102 | |
---|
103 | } |
---|