Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/FICN/src/orxonox/objects/WorldEntity.cc @ 586

Last change on this file since 586 was 586, checked in by landauf, 16 years ago

bump

File size: 4.1 KB
Line 
1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *
4 *
5 *   License notice:
6 *
7 *   This program is free software; you can redistribute it and/or
8 *   modify it under the terms of the GNU General Public License
9 *   as published by the Free Software Foundation; either version 2
10 *   of the License, or (at your option) any later version.
11 *
12 *   This program is distributed in the hope that it will be useful,
13 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
14 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 *   GNU General Public License for more details.
16 *
17 *   You should have received a copy of the GNU General Public License
18 *   along with this program; if not, write to the Free Software
19 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20 *
21 *   Author:
22 *      ...
23 *   Co-authors:
24 *      ...
25 *
26 */
27
28#include <string>
29#include <sstream>
30
31#include "WorldEntity.h"
32#include "../core/CoreIncludes.h"
33#include "../orxonox.h"
34#include "../../tinyxml/tinyxml.h"
35#include "../../misc/Tokenizer.h"
36#include "../../misc/String2Number.h"
37
38namespace orxonox
39{
40    CreateFactory(WorldEntity);
41
42    unsigned int WorldEntity::worldEntityCounter_s = 0;
43
44    WorldEntity::WorldEntity()
45    {
46        RegisterObject(WorldEntity);
47
48        std::cout << "WE: const: 1_1\n";
49        if (Orxonox::getSingleton()->getSceneManager())
50        {
51        std::cout << "WE: const: 1_2\n";
52            std::ostringstream name;
53            name << (WorldEntity::worldEntityCounter_s++);
54            this->setName("WorldEntity" + name.str());
55            node_ = Orxonox::getSingleton()->getSceneManager()->getRootSceneNode()->createChildSceneNode(this->getName());
56            std::cout << "WE: const: name: " << this->getName() << ", node: " << this->node_ << std::endl;
57        }
58        std::cout << "WE: const: 1_3\n";
59
60        this->bStatic_ = true;
61        this->velocity_ = Vector3(0, 0, 0);
62        this->acceleration_ = Vector3(0, 0, 0);
63        this->rotationAxis_ = Vector3(0, 1, 0);
64        this->rotationRate_ = 0;
65        this->momentum_ = 0;
66    }
67
68    WorldEntity::~WorldEntity()
69    {
70    }
71
72    void WorldEntity::tick(float dt)
73    {
74        if (!this->bStatic_)
75        {
76            this->velocity_ += (dt * this->acceleration_);
77            this->translate(dt * this->velocity_);
78
79            this->rotationRate_ += (dt * this->momentum_);
80            this->rotate(this->rotationAxis_, dt * this->rotationRate_);
81        }
82    }
83
84    void WorldEntity::loadParams(TiXmlElement* xmlElem)
85    {
86std::cout << "### START PARSING WE" << std::endl;
87        BaseObject::loadParams(xmlElem);
88
89        std::cout << "WE: 1\n";
90        if (xmlElem->Attribute("name"))
91        {
92        std::cout << "WE: 2\n";
93                this->setName(xmlElem->Attribute("mesh"));
94        }
95        std::cout << "WE: 3\n";
96        if (xmlElem->Attribute("position"))
97        {
98        std::cout << "WE: 4\n";
99                std::vector<std::string> pos = tokenize(xmlElem->Attribute("position"),",");
100                float x, y, z;
101                String2Number<float>(x, pos[0]);
102                String2Number<float>(y, pos[1]);
103                String2Number<float>(z, pos[2]);
104                this->setPosition(x, y, z);
105        }
106        std::cout << "WE: 5\n";
107        if (xmlElem->Attribute("direction"))
108        {
109        std::cout << "WE: 6\n";
110                std::vector<std::string> pos = tokenize(xmlElem->Attribute("direction"),",");
111                float x, y, z;
112                String2Number<float>(x, pos[0]);
113                String2Number<float>(y, pos[1]);
114                String2Number<float>(z, pos[2]);
115                this->setDirection(x, y, z);
116        }
117        std::cout << "WE: 7\n";
118        if (xmlElem->Attribute("scale"))
119        {
120        std::cout << "WE: 8\n";
121                    std::string scaleStr = xmlElem->Attribute("scale");
122                    float scale;
123                    String2Number<float>(scale, scaleStr);
124                    this->setScale(scale);
125        }
126        std::cout << "WE: 9\n";
127std::cout << "### FINISHED PARSING WE" << std::endl;
128    }
129
130    void WorldEntity::registerAllVariables()
131    {
132      // to be implemented !
133    }
134}
Note: See TracBrowser for help on using the repository browser.