Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/orxonox/objects/WorldEntity.cc @ 1414

Last change on this file since 1414 was 1360, checked in by rgrieder, 17 years ago

merged merge branch back to trunk

File size: 7.1 KB
RevLine 
[513]1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
[1056]3 *                    > www.orxonox.net <
[513]4 *
5 *
6 *   License notice:
7 *
8 *   This program is free software; you can redistribute it and/or
9 *   modify it under the terms of the GNU General Public License
10 *   as published by the Free Software Foundation; either version 2
11 *   of the License, or (at your option) any later version.
12 *
13 *   This program is distributed in the hope that it will be useful,
14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 *   GNU General Public License for more details.
17 *
18 *   You should have received a copy of the GNU General Public License
19 *   along with this program; if not, write to the Free Software
20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 *
22 *   Author:
[670]23 *      Fabian 'x3n' Landau
[513]24 *   Co-authors:
25 *      ...
26 *
27 */
28
[786]29#include "OrxonoxStableHeaders.h"
[1039]30#include "WorldEntity.h"
[784]31
[715]32#include <string>
[497]33#include <sstream>
34
[1209]35#include "tinyxml/tinyxml.h"
[1064]36#include "util/SubString.h"
[1032]37#include "core/CoreIncludes.h"
38#include "GraphicsEngine.h"
[871]39#include "core/XMLPort.h"
[497]40
41namespace orxonox
42{
43    CreateFactory(WorldEntity);
44
45    unsigned int WorldEntity::worldEntityCounter_s = 0;
46
[1293]47    WorldEntity::WorldEntity() :
48      velocity_    (0, 0, 0),
49      acceleration_(0, 0, 0),
50      rotationAxis_(0, 1, 0),
51      rotationRate_(0),
52      momentum_    (0),
53      node_        (0),
54      bStatic_     (true)
[497]55    {
56        RegisterObject(WorldEntity);
57
[1032]58        if (GraphicsEngine::getSingleton().getSceneManager())
[1021]59        {
60          std::ostringstream name;
61          name << (WorldEntity::worldEntityCounter_s++);
62          this->setName("WorldEntity" + name.str());
[1032]63          this->node_ = GraphicsEngine::getSingleton().getSceneManager()->getRootSceneNode()->createChildSceneNode(this->getName());
[1056]64
[1021]65          registerAllVariables();
66        }
[497]67    }
[1293]68   
[497]69
70    WorldEntity::~WorldEntity()
71    {
[1360]72      // just to make sure we clean out all scene nodes
[1293]73      if(this->getNode())
74        this->getNode()->removeAndDestroyAllChildren();
[497]75    }
76
77    void WorldEntity::tick(float dt)
78    {
79        if (!this->bStatic_)
80        {
[1293]81//             COUT(4) << "acceleration: " << this->acceleration_ << " velocity: " << this->velocity_ << std::endl;
[497]82            this->velocity_ += (dt * this->acceleration_);
[643]83            this->translate(dt * this->velocity_, Ogre::Node::TS_LOCAL);
[497]84
85            this->rotationRate_ += (dt * this->momentum_);
86            this->rotate(this->rotationAxis_, dt * this->rotationRate_);
87        }
88    }
[583]89
90    void WorldEntity::loadParams(TiXmlElement* xmlElem)
91    {
[871]92
[583]93        BaseObject::loadParams(xmlElem);
[1021]94        create();
[871]95    }
[1293]96   
[643]97
[871]98    void WorldEntity::setYawPitchRoll(const Degree& yaw, const Degree& pitch, const Degree& roll)
99    {
100        this->yaw(yaw);
101        this->pitch(pitch);
102        this->roll(roll);
[583]103    }
104
[871]105    /**
106        @brief XML loading and saving.
107        @param xmlelement The XML-element
108        @param loading Loading (true) or saving (false)
109        @return The XML-element
110    */
[1052]111    void WorldEntity::XMLPort(Element& xmlelement, XMLPort::Mode mode)
[871]112    {
[1052]113        BaseObject::XMLPort(xmlelement, mode);
[871]114
[1052]115        XMLPortParam(WorldEntity, "position", setPositionLoader2, getPosition, xmlelement, mode);
116        XMLPortParamLoadOnly(WorldEntity, "direction", setDirectionLoader, xmlelement, mode);
117        XMLPortParamLoadOnly(WorldEntity, "yawpitchroll", setYawPitchRoll, xmlelement, mode);
118        XMLPortParam(WorldEntity, "scale", setTotalScale, getScale, xmlelement, mode);
119        XMLPortParam(WorldEntity, "rotationAxis", setRotationAxisLoader, getRotationAxis, xmlelement, mode);
120        XMLPortParam(WorldEntity, "rotationRate", setRotationRate, getRotationRate, xmlelement, mode);
[871]121
[1052]122        XMLPortObject(WorldEntity, WorldEntity, "attached", attachWorldEntity, getAttachedWorldEntity, xmlelement, mode, false, true);
[1293]123       
124        WorldEntity::create();
[871]125    }
126
[643]127
[583]128    void WorldEntity::registerAllVariables()
129    {
[1021]130      // register coordinates
[1293]131      registerVar( (void*) &(this->getPosition().x), sizeof(this->getPosition().x), network::DATA, 0x3);
132      registerVar( (void*) &(this->getPosition().y), sizeof(this->getPosition().y), network::DATA, 0x3);
133      registerVar( (void*) &(this->getPosition().z), sizeof(this->getPosition().z), network::DATA, 0x3);
[630]134      // register orientation
[1293]135      registerVar( (void*) &(this->getOrientation().w), sizeof(this->getOrientation().w), network::DATA, 0x3);
136      registerVar( (void*) &(this->getOrientation().x), sizeof(this->getOrientation().x), network::DATA, 0x3);
137      registerVar( (void*) &(this->getOrientation().y), sizeof(this->getOrientation().y), network::DATA, 0x3);
138      registerVar( (void*) &(this->getOrientation().z), sizeof(this->getOrientation().z), network::DATA, 0x3);
[1021]139      // register velocity_
[1360]140      registerVar( (void*) &(this->getVelocity().x), sizeof(this->getVelocity().x), network::DATA, 0x3);
141      registerVar( (void*) &(this->getVelocity().y), sizeof(this->getVelocity().y), network::DATA, 0x3);
142      registerVar( (void*) &(this->getVelocity().z), sizeof(this->getVelocity().z), network::DATA, 0x3);
143      // register rotationAxis/rate
144      registerVar( (void*) &(this->getRotationRate()), sizeof(this->getRotationRate()), network::DATA, 0x3);
145      registerVar( (void*) &(this->getRotationAxis().x), sizeof(this->getRotationAxis().x), network::DATA, 0x3);
146      registerVar( (void*) &(this->getRotationAxis().y), sizeof(this->getRotationAxis().y), network::DATA, 0x3);
147      registerVar( (void*) &(this->getRotationAxis().z), sizeof(this->getRotationAxis().z), network::DATA, 0x3);
[1293]148      // register scale of node
149      registerVar( (void*) &(this->getScale().x), sizeof(this->getScale().x), network::DATA, 0x3);
150      registerVar( (void*) &(this->getScale().y), sizeof(this->getScale().y), network::DATA, 0x3);
151      registerVar( (void*) &(this->getScale().z), sizeof(this->getScale().z), network::DATA, 0x3);
152      //register staticity
153      registerVar( (void*) &(this->bStatic_), sizeof(this->bStatic_), network::DATA, 0x3);
[1360]154      //register acceleration & momentum
155      registerVar( (void*) &(this->getAcceleration().x), sizeof(this->getAcceleration().x), network::DATA, 0x3);
156      registerVar( (void*) &(this->getAcceleration().y), sizeof(this->getAcceleration().y), network::DATA, 0x3);
157      registerVar( (void*) &(this->getAcceleration().z), sizeof(this->getAcceleration().z), network::DATA, 0x3);
158      registerVar( (void*) &(this->getMomentum()), sizeof(this->getMomentum()), network::DATA);
[565]159    }
[871]160
161    void WorldEntity::attachWorldEntity(WorldEntity* entity)
162    {
163        this->attachedWorldEntities_.push_back(entity);
164    }
165
[1052]166    const WorldEntity* WorldEntity::getAttachedWorldEntity(unsigned int index) const
[871]167    {
168        if (index < this->attachedWorldEntities_.size())
169            return this->attachedWorldEntities_[index];
170        else
171            return 0;
172    }
[497]173}
Note: See TracBrowser for help on using the repository browser.