Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Nov 28, 2008, 1:25:16 AM (16 years ago)
Author:
rgrieder
Message:

Finally managed to work out some physics. According to my tests, collisions with simple spheres should work with dynamic/kinematic/static objects. There are currently only a limited number of XML parameters, but we're surely going to extend that. Furthermore there is some more thinking to be done concerning changes of btRigidBody properties when it's already added to the world.

File:
1 edited

Legend:

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

    r2201 r2292  
    229229        if (this->isActive())
    230230        {
    231             this->velocity_ += (dt * this->acceleration_);
    232             this->node_->translate(dt * this->velocity_, Ogre::Node::TS_LOCAL);
     231            if (!this->isDynamic())
     232            {
     233                this->velocity_ += (dt * this->acceleration_);
     234                this->node_->translate(dt * this->velocity_, Ogre::Node::TS_LOCAL);
     235            }
    233236
    234237            if (Core::isMaster())
     
    325328    }
    326329
    327 
    328     // virtual void PositionChanged() { }
    329     void ControllableEntity::positionChanged(const Vector3& position)
     330    void ControllableEntity::positionChanged()
    330331    {
    331332        if (Core::isMaster())
    332333        {
    333             this->server_position_ = this->getPosition();
    334             ++this->server_overwrite_;
    335         }
    336         else if (this->bControlled_)
    337         {
    338             this->client_position_ = position;
    339         }
    340     }
    341 
    342     void ControllableEntity::setVelocity(const Vector3& velocity)
    343     {
    344         if (Core::isMaster())
    345         {
    346             this->velocity_ = velocity;
    347             this->server_velocity_ = velocity;
    348             ++this->server_overwrite_;
    349         }
    350         else if (this->bControlled_)
    351         {
    352             this->velocity_ = velocity;
    353             this->client_velocity_ = velocity;
    354         }
    355     }
    356     // virtual void translateChanged() { }
    357     void ControllableEntity::translateChanged(const Vector3& distance, Ogre::Node::TransformSpace relativeTo)
    358     {
    359         if (Core::isMaster())
    360         {
    361             this->node_->translate(distance, relativeTo);
    362334            this->server_position_ = this->node_->getPosition();
    363335            ++this->server_overwrite_;
     
    365337        else if (this->bControlled_)
    366338        {
    367             this->node_->translate(distance, relativeTo);
    368339            this->client_position_ = this->node_->getPosition();
    369340        }
    370341    }
    371     // virtual void orientationChanged() { }
    372     void ControllableEntity::orientationChanged(const Quaternion& orientation)
     342
     343    void ControllableEntity::orientationChanged()
    373344    {
    374345        if (Core::isMaster())
    375346        {
    376             this->node_->setOrientation(orientation);
    377             this->server_orientation_ = orientation;
    378             ++this->server_overwrite_;
    379         }
    380         else if (this->bControlled_)
    381         {
    382             this->node_->setOrientation(orientation);
    383             this->client_orientation_ = orientation;
    384         }
    385     }
    386     // virtual void rotateChanged() { }
    387     void ControllableEntity::rotateChanged(const Quaternion& rotation, Ogre::Node::TransformSpace relativeTo)
    388     {
    389         if (Core::isMaster())
    390         {
    391             this->node_->rotate(rotation, relativeTo);
    392347            this->server_orientation_ = this->node_->getOrientation();
    393348            ++this->server_overwrite_;
     
    395350        else if (this->bControlled_)
    396351        {
    397             this->node_->rotate(rotation, relativeTo);
    398352            this->client_orientation_ = this->node_->getOrientation();
    399353        }
    400354    }
    401     // virtual void yawChanged() { }
    402     void ControllableEntity::yawChanged(const Degree& angle, Ogre::Node::TransformSpace relativeTo)
     355
     356    void ControllableEntity::velocityChanged()
    403357    {
    404358        if (Core::isMaster())
    405359        {
    406             this->node_->yaw(angle, relativeTo);
    407             this->server_orientation_ = this->node_->getOrientation();
     360            this->server_velocity_ = this->velocity_;
    408361            ++this->server_overwrite_;
    409362        }
    410363        else if (this->bControlled_)
    411364        {
    412             this->node_->yaw(angle, relativeTo);
    413             this->client_orientation_ = this->node_->getOrientation();
    414         }
    415     }
    416     // virtual void pitchChanged() { }
    417     void ControllableEntity::pitchChanged(const Degree& angle, Ogre::Node::TransformSpace relativeTo)
    418     {
    419         if (Core::isMaster())
    420         {
    421             this->node_->pitch(angle, relativeTo);
    422             this->server_orientation_ = this->node_->getOrientation();
    423             ++this->server_overwrite_;
    424         }
    425         else if (this->bControlled_)
    426         {
    427             this->node_->pitch(angle, relativeTo);
    428             this->client_orientation_ = this->node_->getOrientation();
    429         }
    430     }
    431     // virtual void rollChanged() { }
    432     void ControllableEntity::rollChanged(const Degree& angle, Ogre::Node::TransformSpace relativeTo)
    433     {
    434         if (Core::isMaster())
    435         {
    436             this->node_->roll(angle, relativeTo);
    437             this->server_orientation_ = this->node_->getOrientation();
    438             ++this->server_overwrite_;
    439         }
    440         else if (this->bControlled_)
    441         {
    442             this->node_->roll(angle, relativeTo);
    443             this->client_orientation_ = this->node_->getOrientation();
    444         }
    445     }
    446     //virtual void lookAtChanged() { }
    447     void ControllableEntity::lookAtChanged(const Vector3& target, Ogre::Node::TransformSpace relativeTo, const Vector3& localDirectionVector)
    448     {
    449         if (Core::isMaster())
    450         {
    451             this->node_->lookAt(target, relativeTo, localDirectionVector);
    452             this->server_orientation_ = this->node_->getOrientation();
    453             ++this->server_overwrite_;
    454         }
    455         else if (this->bControlled_)
    456         {
    457             this->node_->lookAt(target, relativeTo, localDirectionVector);
    458             this->client_orientation_ = this->node_->getOrientation();
    459         }
    460     }
    461     // virtual void directionChanged( ) { }
    462     void ControllableEntity::directionChanged(const Vector3& direction, Ogre::Node::TransformSpace relativeTo, const Vector3& localDirectionVector)
    463     {
    464         if (Core::isMaster())
    465         {
    466             this->node_->setDirection(direction, relativeTo, localDirectionVector);
    467             this->server_orientation_ = this->node_->getOrientation();
    468             ++this->server_overwrite_;
    469         }
    470         else if (this->bControlled_)
    471         {
    472             this->node_->setDirection(direction, relativeTo, localDirectionVector);
    473             this->client_orientation_ = this->node_->getOrientation();
     365            this->client_velocity_ = this->velocity_;
     366        }
     367    }
     368
     369    void ControllableEntity::setVelocity(const Vector3& velocity)
     370    {
     371        if (this->bControlled_ || Core::isMaster())
     372        {
     373            if (!this->isDynamic())
     374            {
     375                // no physics, we do it ourselves
     376                internalSetVelocity(velocity);
     377            }
     378            else
     379            {
     380                this->physicalBody_->setLinearVelocity(btVector3(velocity.x, velocity.y, velocity.z));
     381            }
     382            velocityChanged();
    474383        }
    475384    }
Note: See TracChangeset for help on using the changeset viewer.