Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 10, 2008, 1:38:17 PM (17 years ago)
Author:
rgrieder
Message:

Trying to synchronise phyiscs over the network.

  • Removed derivation of CollisionShape from WorldEntity (BaseObject instead).
File:
1 edited

Legend:

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

    r2300 r2374  
    4545        RegisterObject(LinearEntity);
    4646
    47         this->acceleration_ = Vector3::ZERO;
    48         this->rotationAxis_ = Vector3::ZERO;
    49         this->rotationRate_ = 0;
    50         this->momentum_ = 0;
    51 
    52         this->overwrite_position_ = Vector3::ZERO;
     47        this->overwrite_position_    = Vector3::ZERO;
    5348        this->overwrite_orientation_ = Quaternion::IDENTITY;
    5449
     
    6358    {
    6459        SUPER(LinearEntity, XMLPort, xmlelement, mode);
    65 
    66         XMLPortParamTemplate(LinearEntity, "rotationaxis", setRotationAxis, getRotationAxis, xmlelement, mode, const Vector3&);
    67         XMLPortParamTemplate(LinearEntity, "rotationrate", setRotationRate, getRotationRate, xmlelement, mode, const Degree&);
    68     }
    69 
    70     void LinearEntity::tick(float dt)
    71     {
    72         if (this->isActive())
    73         {
    74             if (!this->isDynamic())
    75             {
    76                 // we have to do 'physics' ourselves.
    77                 this->velocity_ += (dt * this->acceleration_);
    78                 this->node_->translate(dt * this->velocity_);
    79 
    80                 this->rotationRate_ += (dt * this->momentum_);
    81                 this->node_->rotate(this->rotationAxis_, this->rotationRate_  * dt);
    82             }
    83         }
    8460    }
    8561
    8662    void LinearEntity::registerVariables()
    8763    {
    88         REGISTERDATA(this->velocity_.x, network::direction::toclient);
    89         REGISTERDATA(this->velocity_.y, network::direction::toclient);
    90         REGISTERDATA(this->velocity_.z, network::direction::toclient);
    91 
    92         REGISTERDATA(this->rotationAxis_.x, network::direction::toclient);
    93         REGISTERDATA(this->rotationAxis_.y, network::direction::toclient);
    94         REGISTERDATA(this->rotationAxis_.z, network::direction::toclient);
    95 
    96         REGISTERDATA(this->rotationRate_, network::direction::toclient);
     64        REGISTERDATA(this->linearVelocity_,        network::direction::toclient, new network::NetworkCallback<LinearEntity>(this, &LinearEntity::processLinearVelocity));
     65        REGISTERDATA(this->angularVelocity_,       network::direction::toclient, new network::NetworkCallback<LinearEntity>(this, &LinearEntity::processAngularVelocity));
    9766
    9867        REGISTERDATA(this->overwrite_position_,    network::direction::toclient, new network::NetworkCallback<LinearEntity>(this, &LinearEntity::overwritePosition));
     
    10069    }
    10170
     71    void LinearEntity::tick(float dt)
     72    {
     73        MovableEntity::tick(dt);
     74
     75        if (this->isActive())
     76        {
     77        }
     78    }
     79
    10280    void LinearEntity::overwritePosition()
    10381    {
    104         this->node_->setPosition(this->overwrite_position_);
     82        //COUT(0) << "Setting position on client: " << this->overwrite_position_ << std::endl;
     83        this->setPosition(this->overwrite_position_);
    10584    }
    10685
    10786    void LinearEntity::overwriteOrientation()
    10887    {
    109         this->node_->setOrientation(this->overwrite_orientation_);
     88        //COUT(0) << "Setting orientation on client: " << this->overwrite_orientation_ << std::endl;
     89        this->setOrientation(this->overwrite_orientation_);
    11090    }
    11191
    11292    void LinearEntity::clientConnected(unsigned int clientID)
    11393    {
    114         new Timer<LinearEntity>(rnd() * MAX_RESYNCHRONIZE_TIME, false, this, createExecutor(createFunctor(&LinearEntity::resynchronize)), true);
     94        resynchronize();
     95        new Timer<LinearEntity>(rnd() * MAX_RESYNCHRONIZE_TIME, true, this, createExecutor(createFunctor(&LinearEntity::resynchronize)), false);
    11596    }
    11697
     
    121102    void LinearEntity::resynchronize()
    122103    {
    123         this->overwrite_position_ = this->getPosition();
    124         this->overwrite_orientation_ = this->getOrientation();
     104        positionChanged(false);
     105        orientationChanged(false);
    125106    }
    126107
    127     void LinearEntity::positionChanged()
     108    void LinearEntity::positionChanged(bool bContinuous)
    128109    {
    129         this->overwrite_position_  = this->getPosition();
     110        if (!bContinuous)
     111        {
     112            //if (Core::isMaster())
     113            //    COUT(0) << "Setting position on server: " << this->getPosition() << std::endl;
     114            this->overwrite_position_ = this->getPosition();
     115        }
    130116    }
    131117
    132     void LinearEntity::orientationChanged()
     118    void LinearEntity::orientationChanged(bool bContinuous)
    133119    {
    134         this->overwrite_orientation_  = this->getOrientation();
     120        if (!bContinuous)
     121        {
     122            //if (Core::isMaster())
     123            //    COUT(0) << "Setting orientation on server: " << this->getOrientation() << std::endl;
     124            this->overwrite_orientation_ = this->getOrientation();
     125        }
    135126    }
    136127}
Note: See TracChangeset for help on using the changeset viewer.