Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/core/src/orxonox/objects/WorldEntity.cc @ 850

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

umh, svn is strange… here's the rest of my changes from r848

File size: 7.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 *      Fabian 'x3n' Landau
23 *   Co-authors:
24 *      ...
25 *
26 */
27
28#include "OrxonoxStableHeaders.h"
29
30#include <string>
31#include <sstream>
32
33#include "util/tinyxml/tinyxml.h"
34#include "util/Tokenizer.h"
35#include "util/String2Number.h"
36#include "../core/CoreIncludes.h"
37#include "../Orxonox.h"
38#include "WorldEntity.h"
39#include "core/XMLPort.h"
40
41namespace orxonox
42{
43    CreateFactory(WorldEntity);
44
45    unsigned int WorldEntity::worldEntityCounter_s = 0;
46
47    WorldEntity::WorldEntity()
48    {
49        RegisterObject(WorldEntity);
50
51        if (Orxonox::getSingleton()->getSceneManager())
52        {
53            std::ostringstream name;
54            name << (WorldEntity::worldEntityCounter_s++);
55            this->setName("WorldEntity" + name.str());
56            this->node_ = Orxonox::getSingleton()->getSceneManager()->getRootSceneNode()->createChildSceneNode(this->getName());
57        }
58        else
59        {
60            this->node_ = 0;
61        }
62
63        this->bStatic_ = true;
64        this->velocity_ = Vector3(0, 0, 0);
65        this->acceleration_ = Vector3(0, 0, 0);
66        this->rotationAxis_ = Vector3(0, 1, 0);
67        this->rotationRate_ = 0;
68        this->momentum_ = 0;
69    }
70
71    WorldEntity::~WorldEntity()
72    {
73    }
74
75    void WorldEntity::tick(float dt)
76    {
77        if (!this->bStatic_)
78        {
79            this->velocity_ += (dt * this->acceleration_);
80            this->translate(dt * this->velocity_, Ogre::Node::TS_LOCAL);
81
82            this->rotationRate_ += (dt * this->momentum_);
83            this->rotate(this->rotationAxis_, dt * this->rotationRate_);
84        }
85    }
86
87    void WorldEntity::loadParams(TiXmlElement* xmlElem)
88    {
89
90        BaseObject::loadParams(xmlElem);
91/*
92        if (xmlElem->Attribute("position"))
93        {
94            std::vector<std::string> pos = tokenize(xmlElem->Attribute("position"),",");
95            float x, y, z;
96            String2Number<float>(x, pos[0]);
97            String2Number<float>(y, pos[1]);
98            String2Number<float>(z, pos[2]);
99            this->setPosition(x, y, z);
100        }
101
102        if (xmlElem->Attribute("direction"))
103        {
104            std::vector<std::string> pos = tokenize(xmlElem->Attribute("direction"),",");
105            float x, y, z;
106            String2Number<float>(x, pos[0]);
107            String2Number<float>(y, pos[1]);
108            String2Number<float>(z, pos[2]);
109            this->setDirection(x, y, z);
110        }
111
112        if (xmlElem->Attribute("yaw") || xmlElem->Attribute("pitch") || xmlElem->Attribute("roll"))
113        {
114            float yaw = 0.0, pitch = 0.0, roll = 0.0;
115            if (xmlElem->Attribute("yaw"))
116                String2Number<float>(yaw,xmlElem->Attribute("yaw"));
117
118            if (xmlElem->Attribute("pitch"))
119                String2Number<float>(pitch,xmlElem->Attribute("pitch"));
120
121            if (xmlElem->Attribute("roll"))
122                String2Number<float>(roll,xmlElem->Attribute("roll"));
123
124            this->yaw(Degree(yaw));
125            this->pitch(Degree(pitch));
126            this->roll(Degree(roll));
127        }
128
129        if (xmlElem->Attribute("scale"))
130        {
131            std::string scaleStr = xmlElem->Attribute("scale");
132            float scale;
133            String2Number<float>(scale, scaleStr);
134            this->setScale(scale);
135        }
136
137        if (xmlElem->Attribute("rotationAxis"))
138        {
139            std::vector<std::string> pos = tokenize(xmlElem->Attribute("rotationAxis"),",");
140            float x, y, z;
141            String2Number<float>(x, pos[0]);
142            String2Number<float>(y, pos[1]);
143            String2Number<float>(z, pos[2]);
144            this->setRotationAxis(x, y, z);
145        }
146
147        if (xmlElem->Attribute("rotationRate"))
148        {
149            float rotationRate;
150            String2Number<float>(rotationRate, xmlElem->Attribute("rotationRate"));
151            this->setRotationRate(Degree(rotationRate));
152            if (rotationRate != 0)
153                this->setStatic(false);
154        }
155
156        create();
157*/
158    }
159
160
161    /**
162        @brief XML loading and saving.
163        @param xmlelement The XML-element
164        @param loading Loading (true) or saving (false)
165        @return The XML-element
166    */
167    Element& WorldEntity::XMLPort(Element& xmlelement, bool loading)
168    {
169std::cout << "2_1: " << this->getPosition() << std::endl;
170        BaseObject::XMLPort(xmlelement, loading);
171
172        XMLPortParam(WorldEntity, "position", setPosition, getPosition, xmlelement, loading);
173//        XMLPortParam(WorldEntity, "direction", setDirection, getDirection, xmlelement, loading);
174//        XMLPortParam(WorldEntity, "yaw", yaw, getYaw, xmlelement, loading);
175//        XMLPortParam(WorldEntity, "pitch", pitch, getPitch, xmlelement, loading);
176//        XMLPortParam(WorldEntity, "roll", roll, getRoll, xmlelement, loading);
177        XMLPortParam(WorldEntity, "scale", setScale, getScale, xmlelement, loading);
178        XMLPortParam(WorldEntity, "rotationAxis", setRotationAxis, getRotationAxis, xmlelement, loading);
179        XMLPortParam(WorldEntity, "rotationRate", setRotationRate, getRotationRate, xmlelement, loading);
180std::cout << "2_2: " << this->getPosition() << std::endl;
181
182        return xmlelement;
183    }
184
185    bool WorldEntity::create(){
186      registerAllVariables();
187      return true;
188    }
189
190    void WorldEntity::registerAllVariables()
191    {
192/*      // register coordinates
193      registerVar( (void*) &(this->getPosition().x), sizeof(this->getPosition().x), network::DATA);
194      registerVar( (void*) &(this->getPosition().y), sizeof(this->getPosition().y), network::DATA);
195      registerVar( (void*) &(this->getPosition().z), sizeof(this->getPosition().z), network::DATA);
196      // register orientation
197      registerVar( (void*) &(this->getOrientation().w), sizeof(this->getOrientation().w), network::DATA);
198      registerVar( (void*) &(this->getOrientation().x), sizeof(this->getOrientation().x), network::DATA);
199      registerVar( (void*) &(this->getOrientation().y), sizeof(this->getOrientation().y), network::DATA);
200      registerVar( (void*) &(this->getOrientation().z), sizeof(this->getOrientation().z), network::DATA);*/
201      // not needed at the moment, because we don't have prediction yet
202      /*// register velocity_
203      registerVar( (void*) &(this->getVelocity().x), sizeof(this->getVelocity().x), network::DATA);
204      registerVar( (void*) &(this->getVelocity().y), sizeof(this->getVelocity().y), network::DATA);
205      registerVar( (void*) &(this->getVelocity().z), sizeof(this->getVelocity().z), network::DATA);
206      // register rotationAxis/rate
207      registerVar( (void*) &(this->getRotationRate()), sizeof(this->getRotationRate()), network::DATA);
208      registerVar( (void*) &(this->getRotationAxis().x), sizeof(this->getRotationAxis().x), network::DATA);
209      registerVar( (void*) &(this->getRotationAxis().y), sizeof(this->getRotationAxis().y), network::DATA);
210      registerVar( (void*) &(this->getRotationAxis().z), sizeof(this->getRotationAxis().z), network::DATA);*/
211    }
212}
Note: See TracBrowser for help on using the repository browser.