Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 633 was 633, checked in by landauf, 17 years ago

added blinkies :D

File size: 6.7 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        if (Orxonox::getSingleton()->getSceneManager())
49        {
50            std::ostringstream name;
51            name << (WorldEntity::worldEntityCounter_s++);
52            this->setName("WorldEntity" + name.str());
53            this->node_ = Orxonox::getSingleton()->getSceneManager()->getRootSceneNode()->createChildSceneNode(this->getName());
54        }
55        else
56        {
57            this->node_ = 0;
58        }
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        if (xmlElem->Attribute("name"))
89        {
90            this->setName(xmlElem->Attribute("mesh"));
91        }
92
93        if (xmlElem->Attribute("position"))
94        {
95            std::vector<std::string> pos = tokenize(xmlElem->Attribute("position"),",");
96            float x, y, z;
97            String2Number<float>(x, pos[0]);
98            String2Number<float>(y, pos[1]);
99            String2Number<float>(z, pos[2]);
100            this->setPosition(x, y, z);
101        }
102
103        if (xmlElem->Attribute("direction"))
104        {
105            std::vector<std::string> pos = tokenize(xmlElem->Attribute("direction"),",");
106            float x, y, z;
107            String2Number<float>(x, pos[0]);
108            String2Number<float>(y, pos[1]);
109            String2Number<float>(z, pos[2]);
110            this->setDirection(x, y, z);
111        }
112
113        if (xmlElem->Attribute("yaw") || xmlElem->Attribute("pitch") || xmlElem->Attribute("roll"))
114        {
115            float yaw = 0.0, pitch = 0.0, roll = 0.0;
116            if (xmlElem->Attribute("yaw"))
117                String2Number<float>(yaw,xmlElem->Attribute("yaw"));
118
119            if (xmlElem->Attribute("pitch"))
120                String2Number<float>(pitch,xmlElem->Attribute("pitch"));
121
122            if (xmlElem->Attribute("roll"))
123                String2Number<float>(roll,xmlElem->Attribute("roll"));
124
125            this->yaw(Degree(yaw));
126            this->pitch(Degree(pitch));
127            this->roll(Degree(roll));
128        }
129
130        if (xmlElem->Attribute("scale"))
131        {
132            std::string scaleStr = xmlElem->Attribute("scale");
133            float scale;
134            String2Number<float>(scale, scaleStr);
135            this->setScale(scale);
136        }
137
138        if (xmlElem->Attribute("rotationAxis"))
139        {
140            std::vector<std::string> pos = tokenize(xmlElem->Attribute("rotationAxis"),",");
141            float x, y, z;
142            String2Number<float>(x, pos[0]);
143            String2Number<float>(y, pos[1]);
144            String2Number<float>(z, pos[2]);
145            this->setRotationAxis(x, y, z);
146        }
147
148        if (xmlElem->Attribute("rotationRate"))
149        {
150            float rotationRate;
151            String2Number<float>(rotationRate, xmlElem->Attribute("rotationRate"));
152            this->setRotationRate(Degree(rotationRate));
153            if (rotationRate != 0)
154                this->setStatic(false);
155        }
156
157        create();
158       
159    }
160
161    bool WorldEntity::create(){
162      registerAllVariables();
163      return true;
164    }
165   
166    void WorldEntity::registerAllVariables()
167    {
168      // register coordinates
169      registerVar( (void*) &(this->getPosition().x), sizeof(this->getPosition().x), network::DATA);
170      registerVar( (void*) &(this->getPosition().y), sizeof(this->getPosition().y), network::DATA);
171      registerVar( (void*) &(this->getPosition().z), sizeof(this->getPosition().z), network::DATA);
172      // register orientation
173      registerVar( (void*) &(this->getOrientation().w), sizeof(this->getOrientation().w), network::DATA);
174      registerVar( (void*) &(this->getOrientation().x), sizeof(this->getOrientation().x), network::DATA);
175      registerVar( (void*) &(this->getOrientation().y), sizeof(this->getOrientation().y), network::DATA);
176      registerVar( (void*) &(this->getOrientation().z), sizeof(this->getOrientation().z), network::DATA);
177      // not needed at the moment, because we don't have prediction yet
178      /*// register velocity_
179      registerVar( (void*) &(this->getVelocity().x), sizeof(this->getVelocity().x), network::DATA);
180      registerVar( (void*) &(this->getVelocity().y), sizeof(this->getVelocity().y), network::DATA);
181      registerVar( (void*) &(this->getVelocity().z), sizeof(this->getVelocity().z), network::DATA);
182      // register rotationAxis/rate
183      registerVar( (void*) &(this->getRotationRate()), sizeof(this->getRotationRate()), network::DATA);
184      registerVar( (void*) &(this->getRotationAxis().x), sizeof(this->getRotationAxis().x), network::DATA);
185      registerVar( (void*) &(this->getRotationAxis().y), sizeof(this->getRotationAxis().y), network::DATA);
186      registerVar( (void*) &(this->getRotationAxis().z), sizeof(this->getRotationAxis().z), network::DATA);*/
187    }
188}
Note: See TracBrowser for help on using the repository browser.