Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

loadParams

File size: 3.9 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 << "10_1\n";
49        if (Orxonox::getSingleton()->getSceneManager())
50        {
51        std::cout << "10_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 << "blubbbi: " << this->getName() << " .. " << this->node_ << std::endl;
57        }
58        std::cout << "10_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    {
86        BaseObject::loadParams(xmlElem);
87
88        std::cout << "1\n";
89        if (xmlElem->Attribute("name"))
90        {
91        std::cout << "2\n";
92                this->setName(xmlElem->Attribute("mesh"));
93        }
94        std::cout << "3\n";
95        if (xmlElem->Attribute("position"))
96        {
97        std::cout << "4\n";
98                std::vector<std::string> pos = tokenize(xmlElem->Attribute("position"),",");
99                float x, y, z;
100                String2Number<float>(x, pos[0]);
101                String2Number<float>(y, pos[1]);
102                String2Number<float>(z, pos[2]);
103                this->setPosition(x, y, z);
104        }
105        std::cout << "5\n";
106        if (xmlElem->Attribute("direction"))
107        {
108        std::cout << "6\n";
109                std::vector<std::string> pos = tokenize(xmlElem->Attribute("direction"),",");
110                float x, y, z;
111                String2Number<float>(x, pos[0]);
112                String2Number<float>(y, pos[1]);
113                String2Number<float>(z, pos[2]);
114                this->setDirection(x, y, z);
115        }
116        std::cout << "7\n";
117        if (xmlElem->Attribute("scale"))
118        {
119        std::cout << "8\n";
120                    std::string scaleStr = xmlElem->Attribute("scale");
121                    float scale;
122                    String2Number<float>(scale, scaleStr);
123                    this->setScale(scale);
124        }
125        std::cout << "9\n";
126    }
127
128    void WorldEntity::registerAllVariables()
129    {
130      // to be implemented !
131    }
132}
Note: See TracBrowser for help on using the repository browser.