Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Feb 14, 2009, 10:17:35 PM (15 years ago)
Author:
rgrieder
Message:

Merged presentation branch back to trunk.

Location:
code/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/trunk

  • code/trunk/src/orxonox/objects/worldentities/ControllableEntity.cc

    r2171 r2662  
    2323 *      Fabian 'x3n' Landau
    2424 *   Co-authors:
    25  *      ...
     25 *      Reto Grieder
    2626 *
    2727 */
     
    3030#include "ControllableEntity.h"
    3131
     32#include <OgreSceneManager.h>
     33
    3234#include "core/CoreIncludes.h"
     35#include "core/ConfigValueIncludes.h"
    3336#include "core/Core.h"
    3437#include "core/XMLPort.h"
    3538#include "core/Template.h"
    3639
     40#include "objects/Scene.h"
    3741#include "objects/infos/PlayerInfo.h"
    3842#include "objects/worldentities/Camera.h"
    3943#include "objects/worldentities/CameraPosition.h"
     44#include "objects/gametypes/Gametype.h"
    4045#include "overlays/OverlayGroup.h"
    4146
     
    4449    CreateFactory(ControllableEntity);
    4550
    46     ControllableEntity::ControllableEntity(BaseObject* creator) : WorldEntity(creator)
     51    ControllableEntity::ControllableEntity(BaseObject* creator) : MobileEntity(creator)
    4752    {
    4853        RegisterObject(ControllableEntity);
    4954
    50         this->bControlled_ = false;
     55        this->bHasLocalController_ = false;
     56        this->bHasHumanController_ = false;
     57
    5158        this->server_overwrite_ = 0;
    5259        this->client_overwrite_ = 0;
     
    5663        this->camera_ = 0;
    5764        this->bDestroyWhenPlayerLeft_ = false;
    58 
    59         this->velocity_ = Vector3::ZERO;
    60         this->acceleration_ = Vector3::ZERO;
    61 
    62         this->server_position_ = Vector3::ZERO;
    63         this->client_position_ = Vector3::ZERO;
    64         this->server_velocity_ = Vector3::ZERO;
    65         this->client_velocity_ = Vector3::ZERO;
    66         this->server_orientation_ = Quaternion::IDENTITY;
    67         this->client_orientation_ = Quaternion::IDENTITY;
    68 
     65        this->cameraPositionRootNode_ = this->node_->createChildSceneNode();
     66        this->bMouseLook_ = false;
     67        this->mouseLookSpeed_ = 200;
     68
     69        this->gtinfo_ = 0;
     70        this->gtinfoID_ = OBJECTID_UNKNOWN;
     71        this->changedGametype();
     72
     73        this->server_position_         = Vector3::ZERO;
     74        this->client_position_         = Vector3::ZERO;
     75        this->server_linear_velocity_  = Vector3::ZERO;
     76        this->client_linear_velocity_  = Vector3::ZERO;
     77        this->server_orientation_      = Quaternion::IDENTITY;
     78        this->client_orientation_      = Quaternion::IDENTITY;
     79        this->server_angular_velocity_ = Vector3::ZERO;
     80        this->client_angular_velocity_ = Vector3::ZERO;
     81
     82
     83        this->setConfigValues();
     84        this->setPriority( priority::very_high );
    6985        this->registerVariables();
    7086    }
     
    7490        if (this->isInitialized())
    7591        {
    76             if (this->bControlled_)
    77                 this->stopLocalControl();
     92            this->bDestroyWhenPlayerLeft_ = false;
     93
     94            if (this->bHasLocalController_ && this->bHasHumanController_)
     95                this->stopLocalHumanControl();
     96
     97            if (this->getPlayer() && this->getPlayer()->getControllableEntity() == this)
     98                this->getPlayer()->stopControl(this, false);
    7899
    79100            if (this->hud_)
     
    83104                delete this->camera_;
    84105
    85             if (this->getPlayer() && this->getPlayer()->getControllableEntity() == this)
    86                 this->getPlayer()->stopControl(this, false);
     106            for (std::list<CameraPosition*>::const_iterator it = this->cameraPositions_.begin(); it != this->cameraPositions_.end(); ++it)
     107                delete (*it);
     108
     109            if (this->getScene()->getSceneManager())
     110                this->getScene()->getSceneManager()->destroySceneNode(this->cameraPositionRootNode_->getName());
    87111        }
    88112    }
     
    98122    }
    99123
     124    void ControllableEntity::setConfigValues()
     125    {
     126        SetConfigValue(mouseLookSpeed_, 3.0f);
     127    }
     128
     129    void ControllableEntity::changedGametype()
     130    {
     131        //SUPER(ControllableEntity, changedGametype);
     132        WorldEntity::changedGametype();
     133
     134        this->gtinfo_ = 0;
     135        this->gtinfoID_ = OBJECTID_UNKNOWN;
     136
     137        if (this->getGametype() && this->getGametype()->getGametypeInfo())
     138        {
     139            this->gtinfo_ = this->getGametype()->getGametypeInfo();
     140            this->gtinfoID_ = this->gtinfo_->getObjectID();
     141        }
     142    }
     143
    100144    void ControllableEntity::addCameraPosition(CameraPosition* position)
    101145    {
    102         this->attach(position);
     146        if (position->getAllowMouseLook())
     147            position->attachToNode(this->cameraPositionRootNode_);
     148        else
     149            this->attach(position);
    103150        this->cameraPositions_.push_back(position);
    104151    }
     
    141188            else
    142189            {
    143                 this->attach(this->camera_);
     190                this->camera_->attachToNode(this->cameraPositionRootNode_);
    144191            }
    145192        }
     193    }
     194
     195    void ControllableEntity::mouseLook()
     196    {
     197        this->bMouseLook_ = !this->bMouseLook_;
     198
     199        if (!this->bMouseLook_)
     200            this->cameraPositionRootNode_->setOrientation(Quaternion::IDENTITY);
     201    }
     202
     203    void ControllableEntity::rotateYaw(const Vector2& value)
     204    {
     205        if (this->bMouseLook_)
     206            this->cameraPositionRootNode_->yaw(Radian(value.y * this->mouseLookSpeed_), Ogre::Node::TS_LOCAL);
     207    }
     208
     209    void ControllableEntity::rotatePitch(const Vector2& value)
     210    {
     211        if (this->bMouseLook_)
     212            this->cameraPositionRootNode_->pitch(Radian(value.y * this->mouseLookSpeed_), Ogre::Node::TS_LOCAL);
     213    }
     214
     215    void ControllableEntity::rotateRoll(const Vector2& value)
     216    {
     217        if (this->bMouseLook_)
     218            this->cameraPositionRootNode_->roll(Radian(value.y * this->mouseLookSpeed_), Ogre::Node::TS_LOCAL);
    146219    }
    147220
     
    156229        this->player_ = player;
    157230        this->playerID_ = player->getObjectID();
    158         this->bControlled_ = (player->isLocalPlayer() && player->isHumanPlayer());
    159         if (this->bControlled_)
    160         {
    161             this->startLocalControl();
     231        this->bHasLocalController_ = player->isLocalPlayer();
     232        this->bHasHumanController_ = player->isHumanPlayer();
     233
     234        if (this->bHasLocalController_ && this->bHasHumanController_)
     235        {
     236            this->startLocalHumanControl();
    162237
    163238            if (!Core::isMaster())
    164239            {
    165240                this->client_overwrite_ = this->server_overwrite_;
    166 COUT(0) << "CE: bidirectional synchronization" << std::endl;
    167                 this->setObjectMode(direction::bidirectional);
     241                this->setObjectMode(objectDirection::bidirectional);
    168242            }
    169243        }
     
    172246    void ControllableEntity::removePlayer()
    173247    {
    174         if (this->bControlled_)
    175             this->stopLocalControl();
     248        if (this->bHasLocalController_ && this->bHasHumanController_)
     249            this->stopLocalHumanControl();
    176250
    177251        this->player_ = 0;
    178252        this->playerID_ = OBJECTID_UNKNOWN;
    179         this->bControlled_ = false;
    180         this->setObjectMode(direction::toclient);
     253        this->bHasLocalController_ = false;
     254        this->bHasHumanController_ = false;
     255        this->setObjectMode(objectDirection::toclient);
    181256
    182257        if (this->bDestroyWhenPlayerLeft_)
     
    195270    }
    196271
    197     void ControllableEntity::startLocalControl()
    198     {
    199 //        std::cout << this->getObjectID() << " ###### start local control" << std::endl;
    200         this->camera_ = new Camera(this);
    201         this->camera_->requestFocus();
    202         if (this->cameraPositionTemplate_ != "")
    203             this->addTemplate(this->cameraPositionTemplate_);
    204         if (this->cameraPositions_.size() > 0)
    205             this->cameraPositions_.front()->attachCamera(this->camera_);
    206         else
    207             this->attach(this->camera_);
    208 
    209         if (this->hudtemplate_ != "")
    210         {
    211             this->hud_ = new OverlayGroup(this);
    212             this->hud_->addTemplate(this->hudtemplate_);
    213         }
    214     }
    215 
    216     void ControllableEntity::stopLocalControl()
    217     {
    218 //        std::cout << "###### stop local control" << std::endl;
    219         this->camera_->detachFromParent();
    220         delete this->camera_;
    221         this->camera_ = 0;
    222 
    223         delete this->hud_;
    224         this->hud_ = 0;
     272    void ControllableEntity::networkcallback_changedgtinfoID()
     273    {
     274        if (this->gtinfoID_ != OBJECTID_UNKNOWN)
     275        {
     276            this->gtinfo_ = dynamic_cast<GametypeInfo*>(Synchronisable::getSynchronisable(this->gtinfoID_));
     277
     278            if (!this->gtinfo_)
     279                this->gtinfoID_ = OBJECTID_UNKNOWN;
     280        }
     281    }
     282
     283    void ControllableEntity::startLocalHumanControl()
     284    {
     285        if (!this->camera_)
     286        {
     287            this->camera_ = new Camera(this);
     288            this->camera_->requestFocus();
     289            if (this->cameraPositionTemplate_ != "")
     290                this->addTemplate(this->cameraPositionTemplate_);
     291            if (this->cameraPositions_.size() > 0)
     292                this->cameraPositions_.front()->attachCamera(this->camera_);
     293            else
     294                this->camera_->attachToNode(this->cameraPositionRootNode_);
     295        }
     296
     297        if (!this->hud_)
     298        {
     299            if (this->hudtemplate_ != "")
     300            {
     301                this->hud_ = new OverlayGroup(this);
     302                this->hud_->addTemplate(this->hudtemplate_);
     303                this->hud_->setOwner(this);
     304            }
     305        }
     306    }
     307
     308    void ControllableEntity::stopLocalHumanControl()
     309    {
     310        if (this->camera_)
     311        {
     312            this->camera_->detachFromParent();
     313            delete this->camera_;
     314            this->camera_ = 0;
     315        }
     316
     317        if (this->hud_)
     318        {
     319            delete this->hud_;
     320            this->hud_ = 0;
     321        }
    225322    }
    226323
    227324    void ControllableEntity::tick(float dt)
    228325    {
     326        MobileEntity::tick(dt);
     327
    229328        if (this->isActive())
    230329        {
    231             this->velocity_ += (dt * this->acceleration_);
    232             this->node_->translate(dt * this->velocity_, Ogre::Node::TS_LOCAL);
    233 
    234             if (Core::isMaster())
     330            // Check whether Bullet doesn't do the physics for us
     331            if (!this->isDynamic())
    235332            {
    236                 this->server_velocity_ = this->velocity_;
    237                 this->server_position_ = this->node_->getPosition();
     333                if (Core::isMaster())
     334                {
     335                    this->server_position_ = this->getPosition();
     336                    this->server_orientation_ = this->getOrientation();
     337                    this->server_linear_velocity_ = this->getVelocity();
     338                    this->server_angular_velocity_ = this->getAngularVelocity();
     339                }
     340                else if (this->bHasLocalController_)
     341                {
     342                    this->client_position_ = this->getPosition();
     343                    this->client_orientation_ = this->getOrientation();
     344                    this->client_linear_velocity_ = this->getVelocity();
     345                    this->client_angular_velocity_ = this->getAngularVelocity();
     346                }
    238347            }
    239             else if (this->bControlled_)
    240             {
    241 //                COUT(2) << "setting client position" << endl;
    242                 this->client_velocity_ = this->velocity_;
    243                 this->client_position_ = this->node_->getPosition();
    244             }
    245348        }
    246349    }
     
    248351    void ControllableEntity::registerVariables()
    249352    {
    250         REGISTERSTRING(this->cameraPositionTemplate_, direction::toclient);
    251 
    252         REGISTERDATA(this->client_overwrite_,   direction::toserver);
    253        
    254         REGISTERDATA(this->server_position_,    direction::toclient, new NetworkCallback<ControllableEntity>(this, &ControllableEntity::processServerPosition));
    255         REGISTERDATA(this->server_velocity_,    direction::toclient, new NetworkCallback<ControllableEntity>(this, &ControllableEntity::processServerVelocity));
    256         REGISTERDATA(this->server_orientation_, direction::toclient, new NetworkCallback<ControllableEntity>(this, &ControllableEntity::processServerOrientation));
    257         REGISTERDATA(this->server_overwrite_,   direction::toclient, new NetworkCallback<ControllableEntity>(this, &ControllableEntity::processOverwrite));
    258 
    259         REGISTERDATA(this->client_position_,    direction::toserver, new NetworkCallback<ControllableEntity>(this, &ControllableEntity::processClientPosition));
    260         REGISTERDATA(this->client_velocity_,    direction::toserver, new NetworkCallback<ControllableEntity>(this, &ControllableEntity::processClientVelocity));
    261         REGISTERDATA(this->client_orientation_, direction::toserver, new NetworkCallback<ControllableEntity>(this, &ControllableEntity::processClientOrientation));
    262 
    263 
    264         REGISTERDATA(this->playerID_, direction::toclient, new NetworkCallback<ControllableEntity>(this, &ControllableEntity::networkcallback_changedplayerID));
     353        registerVariable(this->cameraPositionTemplate_,  variableDirection::toclient);
     354        registerVariable(this->hudtemplate_,             variableDirection::toclient);
     355
     356        registerVariable(this->server_position_,         variableDirection::toclient, new NetworkCallback<ControllableEntity>(this, &ControllableEntity::processServerPosition));
     357        registerVariable(this->server_linear_velocity_,  variableDirection::toclient, new NetworkCallback<ControllableEntity>(this, &ControllableEntity::processServerLinearVelocity));
     358        registerVariable(this->server_orientation_,      variableDirection::toclient, new NetworkCallback<ControllableEntity>(this, &ControllableEntity::processServerOrientation));
     359        registerVariable(this->server_angular_velocity_, variableDirection::toclient, new NetworkCallback<ControllableEntity>(this, &ControllableEntity::processServerAngularVelocity));
     360
     361        registerVariable(this->server_overwrite_,        variableDirection::toclient, new NetworkCallback<ControllableEntity>(this, &ControllableEntity::processOverwrite));
     362        registerVariable(this->client_overwrite_,        variableDirection::toserver);
     363
     364        registerVariable(this->client_position_,         variableDirection::toserver, new NetworkCallback<ControllableEntity>(this, &ControllableEntity::processClientPosition));
     365        registerVariable(this->client_linear_velocity_,  variableDirection::toserver, new NetworkCallback<ControllableEntity>(this, &ControllableEntity::processClientLinearVelocity));
     366        registerVariable(this->client_orientation_,      variableDirection::toserver, new NetworkCallback<ControllableEntity>(this, &ControllableEntity::processClientOrientation));
     367        registerVariable(this->client_angular_velocity_, variableDirection::toserver, new NetworkCallback<ControllableEntity>(this, &ControllableEntity::processClientAngularVelocity));
     368
     369        registerVariable(this->playerID_,                variableDirection::toclient, new NetworkCallback<ControllableEntity>(this, &ControllableEntity::networkcallback_changedplayerID));
     370        registerVariable(this->gtinfoID_,                variableDirection::toclient, new NetworkCallback<ControllableEntity>(this, &ControllableEntity::networkcallback_changedgtinfoID));
    265371    }
    266372
    267373    void ControllableEntity::processServerPosition()
    268374    {
    269         if (!this->bControlled_)
    270             this->node_->setPosition(this->server_position_);
    271     }
    272 
    273     void ControllableEntity::processServerVelocity()
    274     {
    275         if (!this->bControlled_)
    276             this->velocity_ = this->server_velocity_;
     375        if (!this->bHasLocalController_)
     376            MobileEntity::setPosition(this->server_position_);
     377    }
     378
     379    void ControllableEntity::processServerLinearVelocity()
     380    {
     381        if (!this->bHasLocalController_)
     382            MobileEntity::setVelocity(this->server_linear_velocity_);
    277383    }
    278384
    279385    void ControllableEntity::processServerOrientation()
    280386    {
    281         if (!this->bControlled_)
    282             this->node_->setOrientation(this->server_orientation_);
     387        if (!this->bHasLocalController_)
     388            MobileEntity::setOrientation(this->server_orientation_);
     389    }
     390
     391    void ControllableEntity::processServerAngularVelocity()
     392    {
     393        if (!this->bHasLocalController_)
     394            MobileEntity::setAngularVelocity(this->server_angular_velocity_);
    283395    }
    284396
    285397    void ControllableEntity::processOverwrite()
    286398    {
    287         if (this->bControlled_)
     399        if (this->bHasLocalController_)
    288400        {
    289401            this->setPosition(this->server_position_);
    290             this->setVelocity(this->server_velocity_);
    291402            this->setOrientation(this->server_orientation_);
     403            this->setVelocity(this->server_linear_velocity_);
     404            this->setAngularVelocity(this->server_angular_velocity_);
    292405
    293406            this->client_overwrite_ = this->server_overwrite_;
     
    299412        if (this->server_overwrite_ == this->client_overwrite_)
    300413        {
    301 //            COUT(2) << "callback: setting client position" << endl;
    302             this->node_->setPosition(this->client_position_);
    303             this->server_position_ = this->client_position_;
    304         }
    305 //        else
    306 //          COUT(2) << "callback: not setting client position" << endl;
    307     }
    308 
    309     void ControllableEntity::processClientVelocity()
     414            MobileEntity::setPosition(this->client_position_);
     415            this->server_position_ = this->getPosition();
     416        }
     417    }
     418
     419    void ControllableEntity::processClientLinearVelocity()
    310420    {
    311421        if (this->server_overwrite_ == this->client_overwrite_)
    312422        {
    313             this->velocity_ = this->client_velocity_;
    314             this->server_velocity_ = this->client_velocity_;
     423            MobileEntity::setVelocity(this->client_linear_velocity_);
     424            this->server_linear_velocity_ = this->getVelocity();
    315425        }
    316426    }
     
    320430        if (this->server_overwrite_ == this->client_overwrite_)
    321431        {
    322             this->node_->setOrientation(this->client_orientation_);
    323             this->server_orientation_ = this->client_orientation_;
    324         }
    325     }
    326 
     432            MobileEntity::setOrientation(this->client_orientation_);
     433            this->server_orientation_ = this->getOrientation();
     434        }
     435    }
     436
     437    void ControllableEntity::processClientAngularVelocity()
     438    {
     439        if (this->server_overwrite_ == this->client_overwrite_)
     440        {
     441            MobileEntity::setAngularVelocity(this->client_angular_velocity_);
     442            this->server_angular_velocity_ = this->getAngularVelocity();
     443        }
     444    }
    327445
    328446    void ControllableEntity::setPosition(const Vector3& position)
     
    330448        if (Core::isMaster())
    331449        {
    332             this->node_->setPosition(position);
    333             this->server_position_ = position;
     450            MobileEntity::setPosition(position);
     451            this->server_position_ = this->getPosition();
    334452            ++this->server_overwrite_;
    335453        }
    336         else if (this->bControlled_)
    337         {
    338             this->node_->setPosition(position);
    339             this->client_position_ = position;
     454        else if (this->bHasLocalController_)
     455        {
     456            MobileEntity::setPosition(position);
     457            this->client_position_ = this->getPosition();
     458        }
     459    }
     460
     461    void ControllableEntity::setOrientation(const Quaternion& orientation)
     462    {
     463        if (Core::isMaster())
     464        {
     465            MobileEntity::setOrientation(orientation);
     466            this->server_orientation_ = this->getOrientation();
     467            ++this->server_overwrite_;
     468        }
     469        else if (this->bHasLocalController_)
     470        {
     471            MobileEntity::setOrientation(orientation);
     472            this->client_orientation_ = this->getOrientation();
    340473        }
    341474    }
     
    345478        if (Core::isMaster())
    346479        {
    347             this->velocity_ = velocity;
    348             this->server_velocity_ = velocity;
     480            MobileEntity::setVelocity(velocity);
     481            this->server_linear_velocity_ = this->getVelocity();
    349482            ++this->server_overwrite_;
    350483        }
    351         else if (this->bControlled_)
    352         {
    353             this->velocity_ = velocity;
    354             this->client_velocity_ = velocity;
    355         }
    356     }
    357 
    358     void ControllableEntity::translate(const Vector3& distance, Ogre::Node::TransformSpace relativeTo)
     484        else if (this->bHasLocalController_)
     485        {
     486            MobileEntity::setVelocity(velocity);
     487            this->client_linear_velocity_ = this->getVelocity();
     488        }
     489    }
     490
     491    void ControllableEntity::setAngularVelocity(const Vector3& velocity)
    359492    {
    360493        if (Core::isMaster())
    361494        {
    362             this->node_->translate(distance, relativeTo);
    363             this->server_position_ = this->node_->getPosition();
     495            MobileEntity::setAngularVelocity(velocity);
     496            this->server_angular_velocity_ = this->getAngularVelocity();
    364497            ++this->server_overwrite_;
    365498        }
    366         else if (this->bControlled_)
    367         {
    368             this->node_->translate(distance, relativeTo);
    369             this->client_position_ = this->node_->getPosition();
    370         }
    371     }
    372 
    373     void ControllableEntity::setOrientation(const Quaternion& orientation)
    374     {
     499        else if (this->bHasLocalController_)
     500        {
     501            MobileEntity::setAngularVelocity(velocity);
     502            this->client_angular_velocity_ = this->getAngularVelocity();
     503        }
     504    }
     505
     506    void ControllableEntity::setWorldTransform(const btTransform& worldTrans)
     507    {
     508        MobileEntity::setWorldTransform(worldTrans);
    375509        if (Core::isMaster())
    376510        {
    377             this->node_->setOrientation(orientation);
    378             this->server_orientation_ = orientation;
    379             ++this->server_overwrite_;
    380         }
    381         else if (this->bControlled_)
    382         {
    383             this->node_->setOrientation(orientation);
    384             this->client_orientation_ = orientation;
    385         }
    386     }
    387 
    388     void ControllableEntity::rotate(const Quaternion& rotation, Ogre::Node::TransformSpace relativeTo)
    389     {
    390         if (Core::isMaster())
    391         {
    392             this->node_->rotate(rotation, relativeTo);
    393             this->server_orientation_ = this->node_->getOrientation();
    394             ++this->server_overwrite_;
    395         }
    396         else if (this->bControlled_)
    397         {
    398             this->node_->rotate(rotation, relativeTo);
    399             this->client_orientation_ = this->node_->getOrientation();
    400         }
    401     }
    402 
    403     void ControllableEntity::yaw(const Degree& angle, Ogre::Node::TransformSpace relativeTo)
    404     {
    405         if (Core::isMaster())
    406         {
    407             this->node_->yaw(angle, relativeTo);
    408             this->server_orientation_ = this->node_->getOrientation();
    409             ++this->server_overwrite_;
    410         }
    411         else if (this->bControlled_)
    412         {
    413             this->node_->yaw(angle, relativeTo);
    414             this->client_orientation_ = this->node_->getOrientation();
    415         }
    416     }
    417 
    418     void ControllableEntity::pitch(const Degree& angle, Ogre::Node::TransformSpace relativeTo)
    419     {
    420         if (Core::isMaster())
    421         {
    422             this->node_->pitch(angle, relativeTo);
    423             this->server_orientation_ = this->node_->getOrientation();
    424             ++this->server_overwrite_;
    425         }
    426         else if (this->bControlled_)
    427         {
    428             this->node_->pitch(angle, relativeTo);
    429             this->client_orientation_ = this->node_->getOrientation();
    430         }
    431     }
    432 
    433     void ControllableEntity::roll(const Degree& angle, Ogre::Node::TransformSpace relativeTo)
    434     {
    435         if (Core::isMaster())
    436         {
    437             this->node_->roll(angle, relativeTo);
    438             this->server_orientation_ = this->node_->getOrientation();
    439             ++this->server_overwrite_;
    440         }
    441         else if (this->bControlled_)
    442         {
    443             this->node_->roll(angle, relativeTo);
    444             this->client_orientation_ = this->node_->getOrientation();
    445         }
    446     }
    447 
    448     void ControllableEntity::lookAt(const Vector3& target, Ogre::Node::TransformSpace relativeTo, const Vector3& localDirectionVector)
    449     {
    450         if (Core::isMaster())
    451         {
    452             this->node_->lookAt(target, relativeTo, localDirectionVector);
    453             this->server_orientation_ = this->node_->getOrientation();
    454             ++this->server_overwrite_;
    455         }
    456         else if (this->bControlled_)
    457         {
    458             this->node_->lookAt(target, relativeTo, localDirectionVector);
    459             this->client_orientation_ = this->node_->getOrientation();
    460         }
    461     }
    462 
    463     void ControllableEntity::setDirection(const Vector3& direction, Ogre::Node::TransformSpace relativeTo, const Vector3& localDirectionVector)
    464     {
    465         if (Core::isMaster())
    466         {
    467             this->node_->setDirection(direction, relativeTo, localDirectionVector);
    468             this->server_orientation_ = this->node_->getOrientation();
    469             ++this->server_overwrite_;
    470         }
    471         else if (this->bControlled_)
    472         {
    473             this->node_->setDirection(direction, relativeTo, localDirectionVector);
    474             this->client_orientation_ = this->node_->getOrientation();
     511            this->server_position_ = this->getPosition();
     512            this->server_orientation_ = this->getOrientation();
     513            this->server_linear_velocity_ = this->getVelocity();
     514            this->server_angular_velocity_ = this->getAngularVelocity();
     515        }
     516        else if (this->bHasLocalController_)
     517        {
     518            this->client_position_ = this->getPosition();
     519            this->client_orientation_ = this->getOrientation();
     520            this->client_linear_velocity_ = this->getVelocity();
     521            this->client_angular_velocity_ = this->getAngularVelocity();
    475522        }
    476523    }
Note: See TracChangeset for help on using the changeset viewer.