Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 2427


Ignore:
Timestamp:
Dec 13, 2008, 9:38:30 PM (15 years ago)
Author:
rgrieder
Message:

Changed the way setPosition, setVelocity, setOrientation and setAngularVelocity is handled in MobileEntity and upwards.
This allows to introduce a lost feature: Position of an enemy ship on the client can't be set anymore at all (local changes were allowed before).

Location:
code/branches/physics/src/orxonox/objects/worldentities
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • code/branches/physics/src/orxonox/objects/worldentities/ControllableEntity.cc

    r2408 r2427  
    230230        if (this->isActive())
    231231        {
     232            // Check whether Bullet doesn't do the physics for us
     233            if (!this->isDynamic())
     234            {
     235                if (Core::isMaster())
     236                {
     237                    this->server_position_ = this->getPosition();
     238                    this->server_orientation_ = this->getOrientation();
     239                    this->server_linear_velocity_ = this->getVelocity();
     240                    this->server_angular_velocity_ = this->getAngularVelocity();
     241                }
     242                else if (this->bControlled_)
     243                {
     244                    this->client_position_ = this->getPosition();
     245                    this->client_orientation_ = this->getOrientation();
     246                    this->client_linear_velocity_ = this->getVelocity();
     247                    this->client_angular_velocity_ = this->getAngularVelocity();
     248                }
     249            }
    232250        }
    233251    }
     
    330348    }
    331349
    332     void ControllableEntity::positionChanged(bool bContinuous)
     350    void ControllableEntity::setPosition(const Vector3& position)
    333351    {
    334352        if (Core::isMaster())
    335353        {
     354            MobileEntity::setPosition(position);
    336355            this->server_position_ = this->getPosition();
    337             if (!bContinuous)
    338                 ++this->server_overwrite_;
     356            ++this->server_overwrite_;
    339357        }
    340358        else if (this->bControlled_)
    341359        {
     360            MobileEntity::setPosition(position);
    342361            this->client_position_ = this->getPosition();
    343362        }
    344363    }
    345364
    346     void ControllableEntity::orientationChanged(bool bContinuous)
     365    void ControllableEntity::setOrientation(const Quaternion& orientation)
    347366    {
    348367        if (Core::isMaster())
    349368        {
     369            MobileEntity::setOrientation(orientation);
    350370            this->server_orientation_ = this->getOrientation();
    351             if (!bContinuous)
    352                 ++this->server_overwrite_;
     371            ++this->server_overwrite_;
    353372        }
    354373        else if (this->bControlled_)
    355374        {
     375            MobileEntity::setOrientation(orientation);
    356376            this->client_orientation_ = this->getOrientation();
    357377        }
    358378    }
    359379
    360     void ControllableEntity::linearVelocityChanged(bool bContinuous)
     380    void ControllableEntity::setVelocity(const Vector3& velocity)
    361381    {
    362382        if (Core::isMaster())
    363383        {
     384            MobileEntity::setVelocity(velocity);
    364385            this->server_linear_velocity_ = this->getVelocity();
    365             if (!bContinuous)
    366                 ++this->server_overwrite_;
     386            ++this->server_overwrite_;
    367387        }
    368388        else if (this->bControlled_)
    369389        {
     390            MobileEntity::setVelocity(velocity);
    370391            this->client_linear_velocity_ = this->getVelocity();
    371392        }
    372393    }
    373394
    374     void ControllableEntity::angularVelocityChanged(bool bContinuous)
     395    void ControllableEntity::setAngularVelocity(const Vector3& velocity)
    375396    {
    376397        if (Core::isMaster())
    377398        {
     399            MobileEntity::setAngularVelocity(velocity);
    378400            this->server_angular_velocity_ = this->getAngularVelocity();
    379             if (!bContinuous)
    380                 ++this->server_overwrite_;
     401            ++this->server_overwrite_;
    381402        }
    382403        else if (this->bControlled_)
    383404        {
     405            MobileEntity::setAngularVelocity(velocity);
    384406            this->client_angular_velocity_ = this->getAngularVelocity();
    385407        }
    386408    }
     409
     410    void ControllableEntity::setWorldTransform(const btTransform& worldTrans)
     411    {
     412        MobileEntity::setWorldTransform(worldTrans);
     413        if (Core::isMaster())
     414        {
     415            this->server_position_ = this->getPosition();
     416            this->server_orientation_ = this->getOrientation();
     417            this->server_linear_velocity_ = this->getVelocity();
     418            this->server_angular_velocity_ = this->getAngularVelocity();
     419        }
     420        else if (this->bControlled_)
     421        {
     422            this->client_position_ = this->getPosition();
     423            this->client_orientation_ = this->getOrientation();
     424            this->client_linear_velocity_ = this->getVelocity();
     425            this->client_angular_velocity_ = this->getAngularVelocity();
     426        }
     427    }
    387428}
  • code/branches/physics/src/orxonox/objects/worldentities/ControllableEntity.h

    r2408 r2427  
    8989                { return this->cameraPositionTemplate_; }
    9090
     91            using WorldEntity::setPosition;
     92            using WorldEntity::setOrientation;
     93            using MobileEntity::setVelocity;
     94            using MobileEntity::setAngularVelocity;
     95
     96            void setPosition(const Vector3& position);
     97            void setOrientation(const Quaternion& orientation);
     98            void setVelocity(const Vector3& velocity);
     99            void setAngularVelocity(const Vector3& velocity);
     100
    91101        protected:
    92102            virtual void startLocalControl();
     
    113123            void processClientAngularVelocity();
    114124
    115             void positionChanged       (bool bContinuous);
    116             void orientationChanged    (bool bContinuous);
    117             void linearVelocityChanged (bool bContinuous);
    118             void angularVelocityChanged(bool bContinuous);
     125            void networkcallback_changedplayerID();
    119126
    120             void networkcallback_changedplayerID();
     127            // Bullet btMotionState related
     128            void setWorldTransform(const btTransform& worldTrans);
    121129
    122130            unsigned int server_overwrite_;
  • code/branches/physics/src/orxonox/objects/worldentities/MobileEntity.cc

    r2426 r2427  
    8383                this->linearVelocity_.y += this->linearAcceleration_.y * dt;
    8484                this->linearVelocity_.z += this->linearAcceleration_.z * dt;
    85                 linearVelocityChanged(true);
    8685                this->node_->translate(this->linearVelocity_ * dt);
    87                 positionChanged(true);
    8886
    8987                // Angular part
     
    9290                this->angularVelocity_.y += angularAcceleration_.y * dt;
    9391                this->angularVelocity_.z += angularAcceleration_.z * dt;
    94                 angularVelocityChanged(true);
    9592                // Calculate new orientation with quaternion derivative. This is about 30% faster than with angle/axis method.
    9693                float mult = dt * 0.5;
     
    10097                newOrientation.normalise();
    10198                this->node_->setOrientation(newOrientation);
    102                 orientationChanged(true);
    10399            }
    104100        }
     
    115111
    116112        this->node_->setPosition(position);
    117         positionChanged(false);
    118113    }
    119114
     
    128123
    129124        this->node_->setOrientation(orientation);
    130         orientationChanged(false);
    131125    }
    132126
     
    137131
    138132        this->linearVelocity_ = velocity;
    139         linearVelocityChanged(false);
    140133    }
    141134
     
    146139
    147140        this->angularVelocity_ = velocity;
    148         angularVelocityChanged(false);
    149141    }
    150142
     
    190182        this->angularVelocity_.y = this->physicalBody_->getAngularVelocity().y();
    191183        this->angularVelocity_.z = this->physicalBody_->getAngularVelocity().z();
    192         linearVelocityChanged(true);
    193         angularVelocityChanged(true);
    194         positionChanged(true);
    195         orientationChanged(true);
    196184    }
    197185
  • code/branches/physics/src/orxonox/objects/worldentities/MobileEntity.h

    r2426 r2427  
    4747            void registerVariables();
    4848
    49             using WorldEntity::setPosition;
    50             using WorldEntity::setOrientation;
     49            virtual void setPosition(const Vector3& position);
     50            virtual void setOrientation(const Quaternion& orientation);
    5151
    52             void setPosition(const Vector3& position);
    53             void setOrientation(const Quaternion& orientation);
    54 
    55             void setVelocity(const Vector3& velocity);
     52            virtual void setVelocity(const Vector3& velocity);
    5653            inline void setVelocity(float x, float y, float z)
    5754                { this->setVelocity(Vector3(x, y, z)); }
     
    5956                { return this->linearVelocity_; }
    6057
    61             void setAngularVelocity(const Vector3& velocity);
     58            virtual void setAngularVelocity(const Vector3& velocity);
    6259            inline void setAngularVelocity(float x, float y, float z)
    6360                { this->setAngularVelocity(Vector3(x, y, z)); }
     
    8885
    8986        protected:
     87            // Bullet btMotionState related
     88            virtual void setWorldTransform(const btTransform& worldTrans);
     89            void getWorldTransform(btTransform& worldTrans) const;
     90
    9091            Vector3 linearAcceleration_;
    9192            Vector3 linearVelocity_;
     
    9495
    9596        private:
    96             virtual void positionChanged       (bool bContinuous) = 0;
    97             virtual void orientationChanged    (bool bContinuous) = 0;
    98             virtual void linearVelocityChanged (bool bContinuous) { }
    99             virtual void angularVelocityChanged(bool bContinuous) { }
    100 
    10197            virtual bool isCollisionTypeLegal(WorldEntity::CollisionType type) const;
    102 
    103             // Bullet btMotionState related
    104             void setWorldTransform(const btTransform& worldTrans);
    105             void getWorldTransform(btTransform& worldTrans) const;
    10698    };
    10799}
  • code/branches/physics/src/orxonox/objects/worldentities/MovableEntity.cc

    r2421 r2427  
    2222 *   Author:
    2323 *      Fabian 'x3n' Landau
     24 *      Reto Grieder
    2425 *   Co-authors:
    2526 *      ...
     
    7677    }
    7778
    78     void MovableEntity::tick(float dt)
    79     {
    80         MobileEntity::tick(dt);
    81 
    82         if (this->isActive())
    83         {
    84         }
    85     }
    86 
    87     void MovableEntity::overwritePosition()
    88     {
    89         this->setPosition(this->overwrite_position_);
    90     }
    91 
    92     void MovableEntity::overwriteOrientation()
    93     {
    94         this->setOrientation(this->overwrite_orientation_);
    95     }
    96 
    9779    void MovableEntity::clientConnected(unsigned int clientID)
    9880    {
     
    10688    void MovableEntity::resynchronize()
    10789    {
    108         positionChanged(false);
    109         orientationChanged(false);
    110     }
    111 
    112     void MovableEntity::positionChanged(bool bContinuous)
    113     {
    114         if (!bContinuous)
    115             this->overwrite_position_ = this->getPosition();
    116     }
    117 
    118     void MovableEntity::orientationChanged(bool bContinuous)
    119     {
    120         if (!bContinuous)
    121             this->overwrite_orientation_ = this->getOrientation();
     90        this->overwrite_position_ = this->getPosition();
     91        this->overwrite_orientation_ = this->getOrientation();
    12292    }
    12393}
  • code/branches/physics/src/orxonox/objects/worldentities/MovableEntity.h

    r2421 r2427  
    2222 *   Author:
    2323 *      Fabian 'x3n' Landau
     24 *      Reto Grieder
    2425 *   Co-authors:
    2526 *      ...
     
    4445
    4546            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    46             virtual void tick(float dt);
    4747            void registerVariables();
     48
     49            using WorldEntity::setPosition;
     50            using WorldEntity::setOrientation;
     51
     52            inline void setPosition(const Vector3& position)
     53                { MobileEntity::setPosition(position); this->overwrite_position_ = this->getPosition(); }
     54            inline void setOrientation(const Quaternion& orientation)
     55                { MobileEntity::setOrientation(orientation); this->overwrite_orientation_ = this->getOrientation(); }
    4856
    4957        private:
     
    5765                { this->setAngularVelocity(this->angularVelocity_); }
    5866
    59             void overwritePosition();
    60             void overwriteOrientation();
     67            inline void overwritePosition()
     68                { this->setPosition(this->overwrite_position_); }
     69            inline void overwriteOrientation()
     70                { this->setOrientation(this->overwrite_orientation_); }
    6171
    62             void positionChanged(bool bContinuous);
    63             void orientationChanged(bool bContinuous);
    64 
    65             Vector3 overwrite_position_;
     72            Vector3    overwrite_position_;
    6673            Quaternion overwrite_orientation_;
    6774            Timer<MovableEntity>* continuousResynchroTimer_;
Note: See TracChangeset for help on using the changeset viewer.