Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 14, 2008, 4:16:52 PM (15 years ago)
Author:
rgrieder
Message:

Finally merged physics stuff. Target is physics_merge because I'll have to do some testing first.

Location:
code/branches/physics_merge
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/branches/physics_merge

  • code/branches/physics_merge/src/orxonox/objects/worldentities/MovableEntity.cc

    r2415 r2442  
    2222 *   Author:
    2323 *      Fabian 'x3n' Landau
     24 *      Reto Grieder
    2425 *   Co-authors:
    2526 *      ...
     
    3839{
    3940    static const float MAX_RESYNCHRONIZE_TIME = 3.0f;
     41    static const float CONTINUOUS_SYNCHRONIZATION_TIME = 10.0f;
    4042
    4143    CreateFactory(MovableEntity);
    4244
    43     MovableEntity::MovableEntity(BaseObject* creator) : WorldEntity(creator)
     45    MovableEntity::MovableEntity(BaseObject* creator) : MobileEntity(creator)
    4446    {
    4547        RegisterObject(MovableEntity);
    4648
    47         this->velocity_ = Vector3::ZERO;
    48         this->acceleration_ = Vector3::ZERO;
    49         this->rotationAxis_ = Vector3::ZERO;
    50         this->rotationRate_ = 0;
    51         this->momentum_ = 0;
    52 
    53         this->overwrite_position_ = Vector3::ZERO;
     49        this->overwrite_position_    = Vector3::ZERO;
    5450        this->overwrite_orientation_ = Quaternion::IDENTITY;
    5551       
    5652        this->setPriority( priority::low );
     53
     54        // Resynchronise every few seconds because we only work with velocities (no positions)
     55        continuousResynchroTimer_ = new Timer<MovableEntity>(CONTINUOUS_SYNCHRONIZATION_TIME + rnd(-1, 1),
     56                true, this, createExecutor(createFunctor(&MovableEntity::resynchronize)), false);
    5757
    5858        this->registerVariables();
     
    6161    MovableEntity::~MovableEntity()
    6262    {
     63        if (this->isInitialized())
     64            delete this->continuousResynchroTimer_;
    6365    }
    6466
     
    6668    {
    6769        SUPER(MovableEntity, XMLPort, xmlelement, mode);
    68 
    69         XMLPortParamTemplate(MovableEntity, "velocity", setVelocity, getVelocity, xmlelement, mode, const Vector3&);
    70         XMLPortParamTemplate(MovableEntity, "rotationaxis", setRotationAxis, getRotationAxis, xmlelement, mode, const Vector3&);
    71         XMLPortParamTemplate(MovableEntity, "rotationrate", setRotationRate, getRotationRate, xmlelement, mode, const Degree&);
    72     }
    73 
    74     void MovableEntity::tick(float dt)
    75     {
    76         if (this->isActive())
    77         {
    78             this->velocity_ += (dt * this->acceleration_);
    79             this->node_->translate(dt * this->velocity_);
    80 
    81             this->rotationRate_ += (dt * this->momentum_);
    82             this->node_->rotate(this->rotationAxis_, this->rotationRate_  * dt);
    83         }
    8470    }
    8571
    8672    void MovableEntity::registerVariables()
    8773    {
    88         registerVariable(this->velocity_.x, variableDirection::toclient);
    89         registerVariable(this->velocity_.y, variableDirection::toclient);
    90         registerVariable(this->velocity_.z, variableDirection::toclient);
    91  
    92         registerVariable(this->rotationAxis_.x, variableDirection::toclient);
    93         registerVariable(this->rotationAxis_.y, variableDirection::toclient);
    94         registerVariable(this->rotationAxis_.z, variableDirection::toclient);
    95  
    96         registerVariable(this->rotationRate_, variableDirection::toclient);
    97  
     74        registerVariable(this->linearVelocity_,        variableDirection::toclient, new NetworkCallback<MovableEntity>(this, &MovableEntity::processLinearVelocity));
     75        registerVariable(this->angularVelocity_,       variableDirection::toclient, new NetworkCallback<MovableEntity>(this, &MovableEntity::processAngularVelocity));
     76
    9877        registerVariable(this->overwrite_position_,    variableDirection::toclient, new NetworkCallback<MovableEntity>(this, &MovableEntity::overwritePosition));
    9978        registerVariable(this->overwrite_orientation_, variableDirection::toclient, new NetworkCallback<MovableEntity>(this, &MovableEntity::overwriteOrientation));
    100     }
    101 
    102     void MovableEntity::overwritePosition()
    103     {
    104         this->node_->setPosition(this->overwrite_position_);
    105     }
    106 
    107     void MovableEntity::overwriteOrientation()
    108     {
    109         this->node_->setOrientation(this->overwrite_orientation_);
    11079    }
    11180
     
    12493        this->overwrite_orientation_ = this->getOrientation();
    12594    }
    126 
    127     void MovableEntity::setPosition(const Vector3& position)
    128     {
    129         this->node_->setPosition(position);
    130         this->overwrite_position_ = this->node_->getPosition();
    131     }
    132 
    133     void MovableEntity::translate(const Vector3& distance, Ogre::Node::TransformSpace relativeTo)
    134     {
    135         this->node_->translate(distance, relativeTo);
    136         this->overwrite_position_ = this->node_->getPosition();
    137     }
    138 
    139     void MovableEntity::setOrientation(const Quaternion& orientation)
    140     {
    141         this->node_->setOrientation(orientation);
    142         this->overwrite_orientation_ = this->node_->getOrientation();
    143     }
    144 
    145     void MovableEntity::rotate(const Quaternion& rotation, Ogre::Node::TransformSpace relativeTo)
    146     {
    147         this->node_->rotate(rotation, relativeTo);
    148         this->overwrite_orientation_ = this->node_->getOrientation();
    149     }
    150 
    151     void MovableEntity::yaw(const Degree& angle, Ogre::Node::TransformSpace relativeTo)
    152     {
    153         this->node_->yaw(angle, relativeTo);
    154         this->overwrite_orientation_ = this->node_->getOrientation();
    155     }
    156 
    157     void MovableEntity::pitch(const Degree& angle, Ogre::Node::TransformSpace relativeTo)
    158     {
    159         this->node_->pitch(angle, relativeTo);
    160         this->overwrite_orientation_ = this->node_->getOrientation();
    161     }
    162 
    163     void MovableEntity::roll(const Degree& angle, Ogre::Node::TransformSpace relativeTo)
    164     {
    165         this->node_->roll(angle, relativeTo);
    166         this->overwrite_orientation_ = this->node_->getOrientation();
    167     }
    168 
    169     void MovableEntity::lookAt(const Vector3& target, Ogre::Node::TransformSpace relativeTo, const Vector3& localDirectionVector)
    170     {
    171         this->node_->lookAt(target, relativeTo, localDirectionVector);
    172         this->overwrite_orientation_ = this->node_->getOrientation();
    173     }
    174 
    175     void MovableEntity::setDirection(const Vector3& direction, Ogre::Node::TransformSpace relativeTo, const Vector3& localDirectionVector)
    176     {
    177         this->node_->setDirection(direction, relativeTo, localDirectionVector);
    178         this->overwrite_orientation_ = this->node_->getOrientation();
    179     }
    18095}
Note: See TracChangeset for help on using the changeset viewer.