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/LinearEntity.cc

    r2192 r2292  
    7474        if (this->isActive())
    7575        {
    76             this->velocity_ += (dt * this->acceleration_);
    77             this->node_->translate(dt * this->velocity_);
     76            if (!this->isDynamic())
     77            {
     78                // we have to do 'physics' ourselves.
     79                this->velocity_ += (dt * this->acceleration_);
     80                this->node_->translate(dt * this->velocity_);
    7881
    79             this->rotationRate_ += (dt * this->momentum_);
    80             this->node_->rotate(this->rotationAxis_, this->rotationRate_  * dt);
     82                this->rotationRate_ += (dt * this->momentum_);
     83                this->node_->rotate(this->rotationAxis_, this->rotationRate_  * dt);
     84            }
    8185        }
    8286    }
     
    123127    }
    124128
    125     void LinearEntity::setPosition(const Vector3& position)
     129    void LinearEntity::positionChanged()
    126130    {
    127         this->node_->setPosition(position);
    128         this->overwrite_position_ = this->node_->getPosition();
     131        this->overwrite_position_  = this->node_->getPosition();
    129132    }
    130133
    131     void LinearEntity::translate(const Vector3& distance, Ogre::Node::TransformSpace relativeTo)
     134    void LinearEntity::orientationChanged()
    132135    {
    133         this->node_->translate(distance, relativeTo);
    134         this->overwrite_position_ = this->node_->getPosition();
     136        this->overwrite_orientation_  = this->node_->getOrientation();
    135137    }
    136138
    137     void LinearEntity::setOrientation(const Quaternion& orientation)
     139    void LinearEntity::setVelocity(const Vector3& velocity)
    138140    {
    139         this->node_->setOrientation(orientation);
    140         this->overwrite_orientation_ = this->node_->getOrientation();
    141     }
    142 
    143     void LinearEntity::rotate(const Quaternion& rotation, Ogre::Node::TransformSpace relativeTo)
    144     {
    145         this->node_->rotate(rotation, relativeTo);
    146         this->overwrite_orientation_ = this->node_->getOrientation();
    147     }
    148 
    149     void LinearEntity::yaw(const Degree& angle, Ogre::Node::TransformSpace relativeTo)
    150     {
    151         this->node_->yaw(angle, relativeTo);
    152         this->overwrite_orientation_ = this->node_->getOrientation();
    153     }
    154 
    155     void LinearEntity::pitch(const Degree& angle, Ogre::Node::TransformSpace relativeTo)
    156     {
    157         this->node_->pitch(angle, relativeTo);
    158         this->overwrite_orientation_ = this->node_->getOrientation();
    159     }
    160 
    161     void LinearEntity::roll(const Degree& angle, Ogre::Node::TransformSpace relativeTo)
    162     {
    163         this->node_->roll(angle, relativeTo);
    164         this->overwrite_orientation_ = this->node_->getOrientation();
    165     }
    166 
    167     void LinearEntity::lookAt(const Vector3& target, Ogre::Node::TransformSpace relativeTo, const Vector3& localDirectionVector)
    168     {
    169         this->node_->lookAt(target, relativeTo, localDirectionVector);
    170         this->overwrite_orientation_ = this->node_->getOrientation();
    171     }
    172 
    173     void LinearEntity::setDirection(const Vector3& direction, Ogre::Node::TransformSpace relativeTo, const Vector3& localDirectionVector)
    174     {
    175         this->node_->setDirection(direction, relativeTo, localDirectionVector);
    176         this->overwrite_orientation_ = this->node_->getOrientation();
     141        if (!this->isDynamic())
     142        {
     143            // no physics, we do it ourselves
     144            internalSetVelocity(velocity);
     145        }
     146        else
     147        {
     148            this->physicalBody_->setLinearVelocity(btVector3(velocity.x, velocity.y, velocity.z));
     149        }
    177150    }
    178151}
Note: See TracChangeset for help on using the changeset viewer.