[515] | 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" |
---|
[560] | 8 | #include "../core/Debug.h" |
---|
[515] | 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 | { |
---|
[599] | 29 | name_ = xmlElem->Attribute("name"); |
---|
[515] | 30 | |
---|
| 31 | std::vector<std::string> pos = tokenize(xmlElem->Attribute("pos"),","); |
---|
[599] | 32 | //float x, y, z_; |
---|
| 33 | String2Number<float>(x_, pos[0]); |
---|
| 34 | String2Number<float>(y_, pos[1]); |
---|
| 35 | String2Number<float>(z_, pos[2]); |
---|
[515] | 36 | |
---|
[599] | 37 | sx_ = 1; sy_ = 1; sz_ = 1; |
---|
[580] | 38 | if (xmlElem->Attribute("scale")) |
---|
| 39 | { |
---|
| 40 | pos = tokenize(xmlElem->Attribute("scale"),","); |
---|
[599] | 41 | String2Number<float>(sx_, pos[0]); |
---|
| 42 | String2Number<float>(sy_, pos[1]); |
---|
| 43 | String2Number<float>(sz_, pos[2]); |
---|
[580] | 44 | } |
---|
[599] | 45 | yaw_ = 0.0; |
---|
[580] | 46 | if (xmlElem->Attribute("yaw")) |
---|
| 47 | { |
---|
[599] | 48 | String2Number<float>(yaw_,xmlElem->Attribute("yaw")); |
---|
[580] | 49 | } |
---|
[599] | 50 | pitch_ = 0.0; |
---|
[580] | 51 | if (xmlElem->Attribute("pitch")) |
---|
| 52 | { |
---|
[599] | 53 | String2Number<float>(pitch_,xmlElem->Attribute("pitch")); |
---|
[580] | 54 | } |
---|
[599] | 55 | roll_ = 0.0; |
---|
[580] | 56 | if (xmlElem->Attribute("roll")) |
---|
| 57 | { |
---|
[599] | 58 | String2Number<float>(roll_,xmlElem->Attribute("roll")); |
---|
[580] | 59 | } |
---|
[560] | 60 | |
---|
[599] | 61 | if(xmlElem->Attribute("node")) |
---|
| 62 | nodeName_ = xmlElem->Attribute("node"); |
---|
[580] | 63 | else |
---|
[599] | 64 | nodeName_ = ""; |
---|
| 65 | |
---|
| 66 | create(); |
---|
[580] | 67 | |
---|
[599] | 68 | COUT(4) << "Loader: loaded node "<< name_ <<" : "<< x_ <<" " << y_ << " " << z_ << std::endl << std::endl; |
---|
[560] | 69 | } |
---|
[515] | 70 | } |
---|
[590] | 71 | |
---|
| 72 | void SceneNode::registerAllVariables(){ |
---|
[599] | 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); |
---|
[590] | 84 | } |
---|
| 85 | |
---|
| 86 | bool SceneNode::create(){ |
---|
[599] | 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_)); |
---|
[590] | 100 | return true; |
---|
| 101 | } |
---|
| 102 | |
---|
[515] | 103 | } |
---|