Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/physics/src/orxonox/objects/worldentities/MovableEntity.cc @ 2408

Last change on this file since 2408 was 2408, checked in by rgrieder, 15 years ago

Renamed MovableEntity to MobileEntity and LinearEntity to MovableEntity.

  • Property svn:eol-style set to native
File size: 3.5 KB
RevLine 
[2072]1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *                    > www.orxonox.net <
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:
[2408]23 *      Fabian 'x3n' Landau
[2072]24 *   Co-authors:
[2408]25 *      ...
[2072]26 *
27 */
28
29#include "OrxonoxStableHeaders.h"
30#include "MovableEntity.h"
31
32#include "core/CoreIncludes.h"
33#include "core/XMLPort.h"
[2408]34#include "core/Executor.h"
35#include "tools/Timer.h"
[2072]36
37namespace orxonox
38{
[2408]39    static const float MAX_RESYNCHRONIZE_TIME = 3.0f;
40
41    CreateFactory(MovableEntity);
42
43    MovableEntity::MovableEntity(BaseObject* creator) : MobileEntity(creator)
[2072]44    {
45        RegisterObject(MovableEntity);
46
[2408]47        this->overwrite_position_    = Vector3::ZERO;
48        this->overwrite_orientation_ = Quaternion::IDENTITY;
[2300]49
[2072]50        this->registerVariables();
51    }
52
53    MovableEntity::~MovableEntity()
54    {
55    }
56
57    void MovableEntity::XMLPort(Element& xmlelement, XMLPort::Mode mode)
58    {
59        SUPER(MovableEntity, XMLPort, xmlelement, mode);
60    }
61
62    void MovableEntity::registerVariables()
63    {
[2408]64        REGISTERDATA(this->linearVelocity_,        network::direction::toclient, new network::NetworkCallback<MovableEntity>(this, &MovableEntity::processLinearVelocity));
65        REGISTERDATA(this->angularVelocity_,       network::direction::toclient, new network::NetworkCallback<MovableEntity>(this, &MovableEntity::processAngularVelocity));
66
67        REGISTERDATA(this->overwrite_position_,    network::direction::toclient, new network::NetworkCallback<MovableEntity>(this, &MovableEntity::overwritePosition));
68        REGISTERDATA(this->overwrite_orientation_, network::direction::toclient, new network::NetworkCallback<MovableEntity>(this, &MovableEntity::overwriteOrientation));
[2072]69    }
[2201]70
[2374]71    void MovableEntity::tick(float dt)
72    {
[2408]73        MobileEntity::tick(dt);
74
[2374]75        if (this->isActive())
76        {
77        }
78    }
79
[2408]80    void MovableEntity::overwritePosition()
[2292]81    {
[2408]82        this->setPosition(this->overwrite_position_);
[2201]83    }
84
[2408]85    void MovableEntity::overwriteOrientation()
[2292]86    {
[2408]87        this->setOrientation(this->overwrite_orientation_);
[2201]88    }
89
[2408]90    void MovableEntity::clientConnected(unsigned int clientID)
[2292]91    {
[2408]92        resynchronize();
93        new Timer<MovableEntity>(rnd() * MAX_RESYNCHRONIZE_TIME, true, this, createExecutor(createFunctor(&MovableEntity::resynchronize)), false);
[2201]94    }
95
[2408]96    void MovableEntity::clientDisconnected(unsigned int clientID)
[2292]97    {
[2201]98    }
99
[2408]100    void MovableEntity::resynchronize()
[2292]101    {
[2408]102        positionChanged(false);
[2374]103        orientationChanged(false);
[2201]104    }
105
[2408]106    void MovableEntity::positionChanged(bool bContinuous)
[2292]107    {
[2408]108        if (!bContinuous)
109            this->overwrite_position_ = this->getPosition();
[2201]110    }
111
[2408]112    void MovableEntity::orientationChanged(bool bContinuous)
[2292]113    {
[2408]114        if (!bContinuous)
115            this->overwrite_orientation_ = this->getOrientation();
[2201]116    }
[2072]117}
Note: See TracBrowser for help on using the repository browser.