Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Trying to synchronise phyiscs over the network.

  • Removed derivation of CollisionShape from WorldEntity (BaseObject instead).
Location:
code/branches/physics/src/orxonox
Files:
2 deleted
24 edited

Legend:

Unmodified
Added
Removed
  • code/branches/physics/src/orxonox/CMakeLists.txt

    r2321 r2374  
    4646  objects/EventDispatcher.cc
    4747  objects/EventTarget.cc
    48   objects/HelloBullet.cc
    4948  objects/Radar.cc
    5049  objects/RadarListener.cc
  • code/branches/physics/src/orxonox/OrxonoxPrereqs.h

    r2303 r2374  
    154154    class CollisionShape;
    155155    class SphereCollisionShape;
     156    class CompoundCollisionShape;
     157    class PlaneCollisionShape;
    156158
    157159    // tools
     
    217219class btSphereShape;
    218220class btCompoundShape;
     221class btStaticPlaneShape;
    219222
    220223class btDiscreteDynamicsWorld;
  • code/branches/physics/src/orxonox/objects/Scene.cc

    r2315 r2374  
    4343#include "core/Core.h"
    4444#include "core/XMLPort.h"
     45#include "tools/BulletConversions.h"
    4546#include "objects/worldentities/WorldEntity.h"
    4647
     
    117118        XMLPortParam(Scene, "shadow", setShadow, getShadow, xmlelement, mode).defaultValues(true);
    118119
    119         const int defaultMaxWorldSize = 100000;
    120         Vector3 worldAabbMin(-defaultMaxWorldSize, -defaultMaxWorldSize, -defaultMaxWorldSize);
    121         Vector3 worldAabbMax( defaultMaxWorldSize,  defaultMaxWorldSize,  defaultMaxWorldSize);
    122         XMLPortParamVariable(Scene, "negativeWorldRange", worldAabbMin, xmlelement, mode);
    123         XMLPortParamVariable(Scene, "positiveWorldRange", worldAabbMax, xmlelement, mode);
    124         XMLPortParam(Scene, "hasPhysics", setPhysicalWorld, hasPhysics, xmlelement, mode).defaultValue(0, true).defaultValue(1, worldAabbMin).defaultValue(2, worldAabbMax);
     120        //const int defaultMaxWorldSize = 100000;
     121        //Vector3 worldAabbMin(-defaultMaxWorldSize, -defaultMaxWorldSize, -defaultMaxWorldSize);
     122        //Vector3 worldAabbMax( defaultMaxWorldSize,  defaultMaxWorldSize,  defaultMaxWorldSize);
     123        //XMLPortParamVariable(Scene, "negativeWorldRange", worldAabbMin, xmlelement, mode);
     124        //XMLPortParamVariable(Scene, "positiveWorldRange", worldAabbMax, xmlelement, mode);
     125        XMLPortParam(Scene, "hasPhysics", setPhysicalWorld, hasPhysics, xmlelement, mode).defaultValue(0, true);//.defaultValue(1, worldAabbMin).defaultValue(2, worldAabbMax);
    125126
    126127        XMLPortObjectExtended(Scene, BaseObject, "", addObject, getObject, xmlelement, mode, true, false);
     
    131132        REGISTERSTRING(this->skybox_,     network::direction::toclient, new network::NetworkCallback<Scene>(this, &Scene::networkcallback_applySkybox));
    132133        REGISTERDATA(this->ambientLight_, network::direction::toclient, new network::NetworkCallback<Scene>(this, &Scene::networkcallback_applyAmbientLight));
    133     }
    134 
    135     void Scene::setPhysicalWorld(bool wantPhysics, const Vector3& worldAabbMin, const Vector3& worldAabbMax)
    136     {
     134        REGISTERDATA(this->bHasPhysics_,  network::direction::toclient, new network::NetworkCallback<Scene>(this, &Scene::networkcallback_hasPhysics));
     135    }
     136
     137    void Scene::setPhysicalWorld(bool wantPhysics)//, const Vector3& worldAabbMin, const Vector3& worldAabbMax)
     138    {
     139        this->bHasPhysics_ = wantPhysics;
    137140        if (wantPhysics && !hasPhysics())
    138141        {
    139                         float x = worldAabbMin.x;
    140                         float y = worldAabbMin.y;
    141                         float z = worldAabbMin.z;
    142             btVector3 worldAabbMin(x,y,z);
    143                         x = worldAabbMax.x;
    144                         y = worldAabbMax.y;
    145                         z = worldAabbMax.z;
    146             btVector3 worldAabbMax(x,y,z);
     142            //float x = worldAabbMin.x;
     143            //float y = worldAabbMin.y;
     144            //float z = worldAabbMin.z;
     145            btVector3 worldAabbMin(-100000, -100000, -100000);
     146            //x = worldAabbMax.x;
     147            //y = worldAabbMax.y;
     148            //z = worldAabbMax.z;
     149            btVector3 worldAabbMax(100000, 100000, 100000);
    147150
    148151            btDefaultCollisionConfiguration*     collisionConfig = new btDefaultCollisionConfiguration();
     
    173176                {
    174177                    if (!(*it)->isInWorld())
     178                    {
     179                        //COUT(0) << "body position: " << omni_cast<Vector3>((*it)->getWorldTransform().getOrigin()) << std::endl;
     180                        //COUT(0) << "body velocity: " << omni_cast<Vector3>((*it)->getLinearVelocity()) << std::endl;
     181                        //COUT(0) << "body orientation: " << omni_cast<Quaternion>((*it)->getWorldTransform().getRotation()) << std::endl;
     182                        //COUT(0) << "body angular: " << omni_cast<Vector3>((*it)->getAngularVelocity()) << std::endl;
     183                        //COUT(0) << "body mass: " << omni_cast<float>((*it)->getInvMass()) << std::endl;
     184                        //COUT(0) << "body inertia: " << omni_cast<Vector3>((*it)->getInvInertiaDiagLocal()) << std::endl;
    175185                        this->physicalWorld_->addRigidBody(*it);
     186                    }
    176187                }
    177188                this->physicsQueue_.clear();
     
    234245    {
    235246        if (!this->physicalWorld_)
    236             COUT(1) << "Error: Cannot WorldEntity body to physical Scene: No physics." << std::endl;
     247            COUT(1) << "Error: Cannot add WorldEntity body to physical Scene: No physics." << std::endl;
    237248        else if (body)
    238249            this->physicsQueue_.insert(body);
     
    242253    {
    243254        if (!this->physicalWorld_)
    244             COUT(1) << "Error: Cannot WorldEntity body to physical Scene: No physics." << std::endl;
     255            COUT(1) << "Error: Cannot remove WorldEntity body from physical Scene: No physics." << std::endl;
    245256        else if (body)
    246257        {
  • code/branches/physics/src/orxonox/objects/Scene.h

    r2313 r2374  
    7070            inline bool hasPhysics()
    7171                { return this->physicalWorld_ != 0; }
    72             void setPhysicalWorld(bool wantsPhysics, const Vector3& worldAabbMin, const Vector3& worldAabbMax);
     72            void setPhysicalWorld(bool wantsPhysics);//, const Vector3& worldAabbMin, const Vector3& worldAabbMax);
    7373
    7474            void addRigidBody(btRigidBody* body);
     
    8585            void networkcallback_applyAmbientLight()
    8686                { this->setAmbientLight(this->ambientLight_); }
     87            void networkcallback_hasPhysics()
     88                { this->setPhysicalWorld(this->bHasPhysics_); }
    8789
    88             Ogre::SceneManager*    sceneManager_;
    89             Ogre::SceneNode*       rootSceneNode_;
     90            Ogre::SceneManager*      sceneManager_;
     91            Ogre::SceneNode*         rootSceneNode_;
    9092
    9193            btDiscreteDynamicsWorld* physicalWorld_;
    9294            std::set<btRigidBody*>   physicsQueue_;
     95            bool                     bHasPhysics_;
    9396
    94             std::string            skybox_;
    95             ColourValue            ambientLight_;
    96             std::list<BaseObject*> objects_;
    97             bool                   bShadows_;
     97            std::string              skybox_;
     98            ColourValue              ambientLight_;
     99            std::list<BaseObject*>   objects_;
     100            bool                     bShadows_;
    98101    };
    99102}
  • code/branches/physics/src/orxonox/objects/worldentities/ControllableEntity.cc

    r2300 r2374  
    5757        this->bDestroyWhenPlayerLeft_ = false;
    5858
    59         this->acceleration_ = Vector3::ZERO;
    60 
    61         this->server_position_ = Vector3::ZERO;
    62         this->client_position_ = Vector3::ZERO;
    63         this->server_velocity_ = Vector3::ZERO;
    64         this->client_velocity_ = Vector3::ZERO;
    65         this->server_orientation_ = Quaternion::IDENTITY;
    66         this->client_orientation_ = Quaternion::IDENTITY;
     59        this->server_position_        = Vector3::ZERO;
     60        this->client_position_         = Vector3::ZERO;
     61        this->server_linear_velocity_ = Vector3::ZERO;
     62        this->client_linear_velocity_ = Vector3::ZERO;
     63        this->server_orientation_      = Quaternion::IDENTITY;
     64        this->client_orientation_      = Quaternion::IDENTITY;
     65        this->server_angular_velocity_ = Vector3::ZERO;
     66        this->client_angular_velocity_ = Vector3::ZERO;
    6767
    6868        this->registerVariables();
     
    226226    void ControllableEntity::tick(float dt)
    227227    {
     228        MovableEntity::tick(dt);
     229
    228230        if (this->isActive())
    229231        {
    230             if (!this->isDynamic())
    231             {
    232                 this->velocity_ += (dt * this->acceleration_);
    233                 this->node_->translate(dt * this->velocity_, Ogre::Node::TS_LOCAL);
    234             }
    235 
    236             if (Core::isMaster())
    237             {
    238                 this->server_velocity_ = this->velocity_;
    239                 this->server_position_ = this->node_->getPosition();
    240             }
    241             else if (this->bControlled_)
    242             {
    243 //                COUT(2) << "setting client position" << endl;
    244                 this->client_velocity_ = this->velocity_;
    245                 this->client_position_ = this->node_->getPosition();
    246             }
    247232        }
    248233    }
     
    252237        REGISTERSTRING(this->cameraPositionTemplate_, network::direction::toclient);
    253238
    254         REGISTERDATA(this->server_position_,    network::direction::toclient, new network::NetworkCallback<ControllableEntity>(this, &ControllableEntity::processServerPosition));
    255         REGISTERDATA(this->server_velocity_,    network::direction::toclient, new network::NetworkCallback<ControllableEntity>(this, &ControllableEntity::processServerVelocity));
    256         REGISTERDATA(this->server_orientation_, network::direction::toclient, new network::NetworkCallback<ControllableEntity>(this, &ControllableEntity::processServerOrientation));
    257 
    258         REGISTERDATA(this->server_overwrite_,   network::direction::toclient, new network::NetworkCallback<ControllableEntity>(this, &ControllableEntity::processOverwrite));
    259         REGISTERDATA(this->client_overwrite_,   network::direction::toserver);
    260 
    261         REGISTERDATA(this->client_position_,    network::direction::toserver, new network::NetworkCallback<ControllableEntity>(this, &ControllableEntity::processClientPosition));
    262         REGISTERDATA(this->client_velocity_,    network::direction::toserver, new network::NetworkCallback<ControllableEntity>(this, &ControllableEntity::processClientVelocity));
    263         REGISTERDATA(this->client_orientation_, network::direction::toserver, new network::NetworkCallback<ControllableEntity>(this, &ControllableEntity::processClientOrientation));
    264 
     239        REGISTERDATA(this->server_position_,         network::direction::toclient, new network::NetworkCallback<ControllableEntity>(this, &ControllableEntity::processServerPosition));
     240        REGISTERDATA(this->server_linear_velocity_,  network::direction::toclient, new network::NetworkCallback<ControllableEntity>(this, &ControllableEntity::processServerLinearVelocity));
     241        REGISTERDATA(this->server_orientation_,      network::direction::toclient, new network::NetworkCallback<ControllableEntity>(this, &ControllableEntity::processServerOrientation));
     242        REGISTERDATA(this->server_angular_velocity_, network::direction::toclient, new network::NetworkCallback<ControllableEntity>(this, &ControllableEntity::processServerAngularVelocity));
     243
     244        REGISTERDATA(this->server_overwrite_,        network::direction::toclient, new network::NetworkCallback<ControllableEntity>(this, &ControllableEntity::processOverwrite));
     245        REGISTERDATA(this->client_overwrite_,        network::direction::toserver);
     246
     247        REGISTERDATA(this->client_position_,         network::direction::toserver, new network::NetworkCallback<ControllableEntity>(this, &ControllableEntity::processClientPosition));
     248        REGISTERDATA(this->client_linear_velocity_,  network::direction::toserver, new network::NetworkCallback<ControllableEntity>(this, &ControllableEntity::processClientLinearVelocity));
     249        REGISTERDATA(this->client_orientation_,      network::direction::toserver, new network::NetworkCallback<ControllableEntity>(this, &ControllableEntity::processClientOrientation));
     250        REGISTERDATA(this->client_angular_velocity_, network::direction::toserver, new network::NetworkCallback<ControllableEntity>(this, &ControllableEntity::processClientAngularVelocity));
    265251
    266252        REGISTERDATA(this->playerID_, network::direction::toclient, new network::NetworkCallback<ControllableEntity>(this, &ControllableEntity::networkcallback_changedplayerID));
     
    270256    {
    271257        if (!this->bControlled_)
    272             this->node_->setPosition(this->server_position_);
    273     }
    274 
    275     void ControllableEntity::processServerVelocity()
    276     {
    277         if (!this->bControlled_)
    278             this->velocity_ = this->server_velocity_;
     258        {
     259            //COUT(0) << "override with server position: " << this << std::endl;
     260            this->setPosition(this->server_position_);
     261        }
     262    }
     263
     264    void ControllableEntity::processServerLinearVelocity()
     265    {
     266        if (!this->bControlled_)
     267            this->setVelocity(this->server_linear_velocity_);
    279268    }
    280269
     
    282271    {
    283272        if (!this->bControlled_)
    284             this->node_->setOrientation(this->server_orientation_);
     273            this->setOrientation(this->server_orientation_);
     274    }
     275
     276    void ControllableEntity::processServerAngularVelocity()
     277    {
     278        if (!this->bControlled_)
     279            this->setAngularVelocity(this->server_angular_velocity_);
    285280    }
    286281
    287282    void ControllableEntity::processOverwrite()
    288283    {
    289         if (this->bControlled_)
    290         {
    291             this->setPosition(this->server_position_);
    292             this->setVelocity(this->server_velocity_);
    293             this->setOrientation(this->server_orientation_);
    294 
    295             this->client_overwrite_ = this->server_overwrite_;
    296         }
     284        //if (this->bControlled_)
     285        //{
     286        //    COUT(0) << "complete override: " << this << std::endl;
     287        //    this->setPosition(this->server_position_);
     288        //    this->setVelocity(this->server_velocity_);
     289        //    this->setOrientation(this->server_orientation_);
     290
     291        //    this->client_overwrite_ = this->server_overwrite_;
     292        //}
    297293    }
    298294
    299295    void ControllableEntity::processClientPosition()
    300296    {
    301         if (this->server_overwrite_ == this->client_overwrite_)
    302         {
     297        //if (this->server_overwrite_ == this->client_overwrite_)
     298        if (!this->bControlled_)
     299        {
     300            //COUT(0) << "override with client position: " << this << std::endl;
    303301//            COUT(2) << "callback: setting client position" << endl;
    304             this->node_->setPosition(this->client_position_);
    305             this->server_position_ = this->client_position_;
    306         }
    307 //        else
    308 //          COUT(2) << "callback: not setting client position" << endl;
    309     }
    310 
    311     void ControllableEntity::processClientVelocity()
    312     {
    313         if (this->server_overwrite_ == this->client_overwrite_)
    314         {
    315             this->velocity_ = this->client_velocity_;
    316             this->server_velocity_ = this->client_velocity_;
     302            this->setPosition(this->client_position_);
     303            //this->server_position_ = this->client_position_;
     304        }
     305        //else
     306        //  COUT(2) << "callback: not setting client position" << endl;
     307    }
     308
     309    void ControllableEntity::processClientLinearVelocity()
     310    {
     311        if (!this->bControlled_)
     312        //if (this->server_overwrite_ == this->client_overwrite_)
     313        {
     314            this->setVelocity(this->client_linear_velocity_);
     315            //this->server_velocity_ = this->client_velocity_;
    317316        }
    318317    }
     
    320319    void ControllableEntity::processClientOrientation()
    321320    {
    322         if (this->server_overwrite_ == this->client_overwrite_)
    323         {
    324             this->node_->setOrientation(this->client_orientation_);
    325             this->server_orientation_ = this->client_orientation_;
    326         }
    327     }
    328 
    329     void ControllableEntity::positionChanged()
     321        if (!this->bControlled_)
     322        //if (this->server_overwrite_ == this->client_overwrite_)
     323        {
     324            this->setOrientation(this->client_orientation_);
     325            //this->server_orientation_ = this->client_orientation_;
     326        }
     327    }
     328
     329    void ControllableEntity::processClientAngularVelocity()
     330    {
     331        if (!this->bControlled_)
     332        //if (this->server_overwrite_ == this->client_overwrite_)
     333        {
     334            this->setAngularVelocity(this->client_angular_velocity_);
     335            //this->server_velocity_ = this->client_velocity_;
     336        }
     337    }
     338
     339    void ControllableEntity::positionChanged(bool bContinuous)
    330340    {
    331341        if (Core::isMaster())
     
    340350    }
    341351
    342     void ControllableEntity::orientationChanged()
     352    void ControllableEntity::orientationChanged(bool bContinuous)
    343353    {
    344354        if (Core::isMaster())
     
    353363    }
    354364
    355     void ControllableEntity::velocityChanged()
     365    void ControllableEntity::linearVelocityChanged(bool bContinuous)
    356366    {
    357367        if (Core::isMaster())
    358368        {
    359             this->server_velocity_ = this->getVelocity();
     369            this->server_linear_velocity_ = this->getVelocity();
    360370            ++this->server_overwrite_;
    361371        }
    362372        else if (this->bControlled_)
    363373        {
    364             this->client_velocity_ = this->getVelocity();
     374            this->client_linear_velocity_ = this->getVelocity();
     375        }
     376    }
     377
     378    void ControllableEntity::angularVelocityChanged(bool bContinuous)
     379    {
     380        if (Core::isMaster())
     381        {
     382            this->server_angular_velocity_ = this->getAngularVelocity();
     383            ++this->server_overwrite_;
     384        }
     385        else if (this->bControlled_)
     386        {
     387            this->client_angular_velocity_ = this->getAngularVelocity();
    365388        }
    366389    }
  • code/branches/physics/src/orxonox/objects/worldentities/ControllableEntity.h

    r2300 r2374  
    3333
    3434#include "MovableEntity.h"
    35 #include "objects/Tickable.h"
    3635
    3736namespace orxonox
    3837{
    39     class _OrxonoxExport ControllableEntity : public MovableEntity, public Tickable
     38    class _OrxonoxExport ControllableEntity : public MovableEntity
    4039    {
    4140        public:
     
    7271            virtual void switchCamera();
    7372
    74             inline const Vector3& getVelocity() const
    75                 { return this->velocity_; }
    76             inline const Vector3& getAcceleration() const
    77                 { return this->acceleration_; }
    7873            inline const std::string& getHudTemplate() const
    7974                { return this->hudtemplate_; }
    80 
    81             inline void setAcceleration(const Vector3& acceleration)
    82                 { this->acceleration_ = acceleration; }
    83             inline void setAcceleration(float x, float y, float z)
    84                 { this->acceleration_.x = x; this->acceleration_.y = y; this->acceleration_.z = z; }
    8575
    8676            inline Camera* getCamera() const
     
    10999                { return this->bControlled_; }
    110100
    111             Vector3 acceleration_;
    112 
    113101        private:
    114102            void overwrite();
     
    116104
    117105            void processServerPosition();
    118             void processServerVelocity();
     106            void processServerLinearVelocity();
    119107            void processServerOrientation();
     108            void processServerAngularVelocity();
    120109
    121110            void processClientPosition();
    122             void processClientVelocity();
     111            void processClientLinearVelocity();
    123112            void processClientOrientation();
     113            void processClientAngularVelocity();
    124114
    125             void positionChanged();
    126             void orientationChanged();
    127             void velocityChanged();
     115            void positionChanged       (bool bContinuous);
     116            void orientationChanged    (bool bContinuous);
     117            void linearVelocityChanged (bool bContinuous);
     118            void angularVelocityChanged(bool bContinuous);
    128119
    129120            void networkcallback_changedplayerID();
     
    135126            Vector3 server_position_;
    136127            Vector3 client_position_;
    137             Vector3 server_velocity_;
    138             Vector3 client_velocity_;
     128            Vector3 server_linear_velocity_;
     129            Vector3 client_linear_velocity_;
    139130            Quaternion server_orientation_;
    140131            Quaternion client_orientation_;
     132            Vector3 server_angular_velocity_;
     133            Vector3 client_angular_velocity_;
    141134
    142135            PlayerInfo* player_;
  • 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}
  • code/branches/physics/src/orxonox/objects/worldentities/LinearEntity.h

    r2300 r2374  
    3333
    3434#include "MovableEntity.h"
    35 #include "objects/Tickable.h"
    3635#include "network/ClientConnectionListener.h"
    3736
    3837namespace orxonox
    3938{
    40     class _OrxonoxExport LinearEntity : public MovableEntity, public network::ClientConnectionListener, public Tickable
     39    class _OrxonoxExport LinearEntity : public MovableEntity, public network::ClientConnectionListener
    4140    {
    4241        public:
     
    4847            void registerVariables();
    4948
    50             inline void setAcceleration(const Vector3& acceleration)
    51                 { this->acceleration_ = acceleration; }
    52             inline void setAcceleration(float x, float y, float z)
    53                 { this->acceleration_.x = x; this->acceleration_.y = y; this->acceleration_.z = z; }
    54             inline const Vector3& getAcceleration() const
    55                 { return this->acceleration_; }
    56 
    57             inline void setRotationAxis(const Vector3& axis)
    58                 { this->rotationAxis_ = axis; this->rotationAxis_.normalise(); }
    59             inline void setRotationAxis(float x, float y, float z)
    60                 { this->rotationAxis_.x = x; this->rotationAxis_.y = y; this->rotationAxis_.z = z; rotationAxis_.normalise(); }
    61             inline const Vector3& getRotationAxis() const
    62                 { return this->rotationAxis_; }
    63 
    64             inline void setRotationRate(const Degree& angle)
    65                 { this->rotationRate_ = angle; }
    66             inline void setRotationRate(const Radian& angle)
    67                 { this->rotationRate_ = angle; }
    68             inline const Degree& getRotationRate() const
    69                 { return this->rotationRate_; }
    70 
    71             inline void setMomentum(const Degree& angle)
    72                 { this->momentum_ = angle; }
    73             inline void setMomentum(const Radian& angle)
    74                 { this->momentum_ = angle; }
    75             inline const Degree& getMomentum() const
    76                 { return this->momentum_; }
    77 
    7849        private:
    7950            void clientConnected(unsigned int clientID);
     
    8152            void resynchronize();
    8253
     54            inline void processLinearVelocity()
     55                { this->setVelocity(this->linearVelocity_); }
     56            inline void processAngularVelocity()
     57                { this->setAngularVelocity(this->angularVelocity_); }
     58
    8359            void overwritePosition();
    8460            void overwriteOrientation();
    8561
    86             void positionChanged();
    87             void orientationChanged();
    88 
    89             Vector3 acceleration_;
    90             Vector3 rotationAxis_;
    91             Degree rotationRate_;
    92             Degree momentum_;
     62            void positionChanged(bool bContinuous);
     63            void orientationChanged(bool bContinuous);
    9364
    9465            Vector3 overwrite_position_;
  • code/branches/physics/src/orxonox/objects/worldentities/MovableEntity.cc

    r2306 r2374  
    3333
    3434#include "util/Debug.h"
     35#include "util/MathConvert.h"
    3536#include "util/Exception.h"
    3637#include "core/CoreIncludes.h"
     
    4546        RegisterObject(MovableEntity);
    4647
    47         this->velocity_ = Vector3::ZERO;
     48        this->linearAcceleration_  = Vector3::ZERO;
     49        this->linearVelocity_      = Vector3::ZERO;
     50        this->angularAcceleration_ = Vector3::ZERO;
     51        this->angularVelocity_     = Vector3::ZERO;
    4852
    4953        this->registerVariables();
     
    5862        SUPER(MovableEntity, XMLPort, xmlelement, mode);
    5963
    60         XMLPortParamTemplate(MovableEntity, "velocity", setVelocity, getVelocity, xmlelement, mode, const Vector3&);
     64        XMLPortParamTemplate(MovableEntity, "velocity",     setVelocity,     getVelocity,     xmlelement, mode, const Vector3&);
     65        XMLPortParamTemplate(MovableEntity, "rotationaxis", setRotationAxis, getRotationAxis, xmlelement, mode, const Vector3&);
     66        XMLPortParam(MovableEntity, "rotationrate", setRotationRate, getRotationRate, xmlelement, mode);
    6167    }
    6268
     
    6571    }
    6672
     73    void MovableEntity::tick(float dt)
     74    {
     75        if (this->isActive())
     76        {
     77            // Check whether Bullet doesn't do the physics for us
     78            if (!this->isDynamic())
     79            {
     80                // Linear part
     81                this->linearVelocity_.x += this->linearAcceleration_.x * dt;
     82                this->linearVelocity_.y += this->linearAcceleration_.y * dt;
     83                this->linearVelocity_.z += this->linearAcceleration_.z * dt;
     84                linearVelocityChanged(true);
     85                this->node_->translate(this->linearVelocity_ * dt);
     86                positionChanged(true);
     87
     88                // Angular part
     89                // Note: angularVelocity_ is a Quaternion with w = 0 while angularAcceleration_ is a Vector3
     90                this->angularVelocity_.x += angularAcceleration_.x * dt;
     91                this->angularVelocity_.y += angularAcceleration_.y * dt;
     92                this->angularVelocity_.z += angularAcceleration_.z * dt;
     93                angularVelocityChanged(true);
     94                // Calculate new orientation with quaternion derivative. This is about 30% faster than with angle/axis method.
     95                float mult = dt * 0.5;
     96                // TODO: this could be optimized by writing it out. The calls currently create 4 new Quaternions!
     97                Quaternion newOrientation(0.0f, this->angularVelocity_.x * mult, this->angularVelocity_.y * mult, this->angularVelocity_.z * mult);
     98                newOrientation = this->node_->getOrientation() + newOrientation * this->node_->getOrientation();
     99                newOrientation.normalise();
     100                this->node_->setOrientation(newOrientation);
     101                orientationChanged(true);
     102            }
     103        }
     104    }
     105
    67106    void MovableEntity::setPosition(const Vector3& position)
    68107    {
    69108        if (this->isDynamic())
    70109        {
     110            //if (this->isPhysicsRunning())
     111            //    return;
    71112            btTransform transf = this->physicalBody_->getWorldTransform();
    72113            transf.setOrigin(btVector3(position.x, position.y, position.z));
     
    74115        }
    75116
     117        //COUT(0) << "setting position: " << position << std::endl;
    76118        this->node_->setPosition(position);
    77         positionChanged();
     119        positionChanged(false);
    78120    }
    79121
     
    88130
    89131        this->node_->translate(distance, relativeTo);
    90         positionChanged();
     132        positionChanged(false);
    91133    }
    92134
     
    96138        {
    97139            btTransform transf = this->physicalBody_->getWorldTransform();
    98             transf.setRotation(btQuaternion(orientation.w, orientation.x, orientation.y, orientation.z));
     140            transf.setRotation(btQuaternion(orientation.x, orientation.y, orientation.z, orientation.w));
    99141            this->physicalBody_->setWorldTransform(transf);
    100142        }
    101143
    102144        this->node_->setOrientation(orientation);
    103         orientationChanged();
     145        orientationChanged(false);
    104146    }
    105147
     
    111153                                                          to any other space than TS_LOCAL.");
    112154            btTransform transf = this->physicalBody_->getWorldTransform();
    113             this->physicalBody_->setWorldTransform(transf * btTransform(btQuaternion(rotation.w, rotation.x, rotation.y, rotation.z)));
     155            this->physicalBody_->setWorldTransform(transf * btTransform(btQuaternion(rotation.x, rotation.y, rotation.z, rotation.w)));
    114156        }
    115157
    116158        this->node_->rotate(rotation, relativeTo);
    117         orientationChanged();
     159        orientationChanged(false);
    118160    }
    119161
     
    130172
    131173        this->node_->yaw(angle, relativeTo);
    132         orientationChanged();
     174        orientationChanged(false);
    133175    }
    134176
     
    145187
    146188        this->node_->pitch(angle, relativeTo);
    147         orientationChanged();
     189        orientationChanged(false);
    148190    }
    149191
     
    160202
    161203        this->node_->roll(angle, relativeTo);
    162         orientationChanged();
     204        orientationChanged(false);
    163205    }
    164206
     
    175217
    176218        this->node_->lookAt(target, relativeTo, localDirectionVector);
    177         orientationChanged();
     219        orientationChanged(false);
    178220    }
    179221
     
    190232
    191233        this->node_->setDirection(direction, relativeTo, localDirectionVector);
    192         orientationChanged();
     234        orientationChanged(false);
    193235    }
    194236
     
    196238    {
    197239        if (this->isDynamic())
    198         {
    199240            this->physicalBody_->setLinearVelocity(btVector3(velocity.x, velocity.y, velocity.z));
    200         }
    201 
    202         this->velocity_ = velocity;
    203         velocityChanged();
     241
     242        this->linearVelocity_ = velocity;
     243        linearVelocityChanged(false);
     244    }
     245
     246    void MovableEntity::setAngularVelocity(const Vector3& velocity)
     247    {
     248        if (this->isDynamic())
     249            this->physicalBody_->setAngularVelocity(btVector3(velocity.x, velocity.y, velocity.z));
     250
     251        this->angularVelocity_ = velocity;
     252        angularVelocityChanged(false);
     253    }
     254
     255    void MovableEntity::setAcceleration(const Vector3& acceleration)
     256    {
     257        if (this->isDynamic())
     258            this->physicalBody_->applyCentralForce(btVector3(acceleration.x * this->getMass(), acceleration.y * this->getMass(), acceleration.z * this->getMass()));
     259
     260        this->linearAcceleration_ = acceleration;
     261    }
     262
     263    void MovableEntity::setAngularAcceleration(const Vector3& acceleration)
     264    {
     265        if (this->isDynamic())
     266        {
     267            btVector3 inertia(btVector3(1, 1, 1) / this->physicalBody_->getInvInertiaDiagLocal());
     268            this->physicalBody_->applyTorque(btVector3(acceleration.x, acceleration.y, acceleration.z) * inertia);
     269        }
     270
     271        this->angularAcceleration_ = acceleration;
    204272    }
    205273
     
    220288        this->node_->setPosition(Vector3(worldTrans.getOrigin().x(), worldTrans.getOrigin().y(), worldTrans.getOrigin().z()));
    221289        this->node_->setOrientation(Quaternion(worldTrans.getRotation().w(), worldTrans.getRotation().x(), worldTrans.getRotation().y(), worldTrans.getRotation().z()));
    222         const btVector3& velocity = this->physicalBody_->getLinearVelocity();
    223         this->velocity_.x = velocity.x();
    224         this->velocity_.y = velocity.y();
    225         this->velocity_.z = velocity.z();
    226         velocityChanged();
    227         positionChanged();
    228         orientationChanged();
     290        COUT(0) << "setting world transform: " << omni_cast<std::string>(node_->getPosition()) << std::endl;
     291        this->linearVelocity_.x = this->physicalBody_->getLinearVelocity().x();
     292        this->linearVelocity_.y = this->physicalBody_->getLinearVelocity().y();
     293        this->linearVelocity_.z = this->physicalBody_->getLinearVelocity().z();
     294        this->angularVelocity_.x = this->physicalBody_->getAngularVelocity().x();
     295        this->angularVelocity_.y = this->physicalBody_->getAngularVelocity().y();
     296        this->angularVelocity_.z = this->physicalBody_->getAngularVelocity().z();
     297        linearVelocityChanged(true);
     298        angularVelocityChanged(true);
     299        positionChanged(true);
     300        orientationChanged(true);
    229301    }
    230302
    231303    void MovableEntity::getWorldTransform(btTransform& worldTrans) const
    232304    {
    233         // We use a kinematic body 
     305        // We use a kinematic body
    234306        worldTrans.setOrigin(btVector3(node_->getPosition().x, node_->getPosition().y, node_->getPosition().z));
    235         worldTrans.setRotation(btQuaternion(node_->getOrientation().w, node_->getOrientation().x, node_->getOrientation().y, node_->getOrientation().z));
     307        worldTrans.setRotation(btQuaternion(node_->getOrientation().x, node_->getOrientation().y, node_->getOrientation().z, node_->getOrientation().w));
    236308        if (this->isDynamic())
    237309        {
    238310            // This function gets called only once for dynamic objects to set the initial conditions
    239             // We have to set the velocity too.
    240             this->physicalBody_->setLinearVelocity(btVector3(velocity_.x, velocity_.y, velocity_.z));
     311            // We have to set the velocities too.
     312            this->physicalBody_->setLinearVelocity(btVector3(linearVelocity_.x, linearVelocity_.y, linearVelocity_.z));
     313            this->physicalBody_->setAngularVelocity(btVector3(angularVelocity_.x, angularVelocity_.y, angularVelocity_.z));
    241314        }
    242315    }
  • code/branches/physics/src/orxonox/objects/worldentities/MovableEntity.h

    r2304 r2374  
    3434#include "WorldEntity.h"
    3535#include "objects/Tickable.h"
    36 #include "network/ClientConnectionListener.h"
    3736
    3837namespace orxonox
    3938{
    40     class _OrxonoxExport MovableEntity : public WorldEntity
     39    class _OrxonoxExport MovableEntity : public WorldEntity, public Tickable
    4140    {
    4241        public:
     
    4544
    4645            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
     46            virtual void tick(float dt);
    4747            void registerVariables();
    4848
     
    6969            void setVelocity(const Vector3& velocity);
    7070            inline void setVelocity(float x, float y, float z)
    71                 { this->velocity_.x = x; this->velocity_.y = y; this->velocity_.z = z; }
     71                { this->setVelocity(Vector3(x, y, z)); }
    7272            inline const Vector3& getVelocity() const
    73                 { return this->velocity_; }
     73                { return this->linearVelocity_; }
     74
     75            void setAngularVelocity(const Vector3& velocity);
     76            inline void setAngularVelocity(float x, float y, float z)
     77                { this->setAngularVelocity(Vector3(x, y, z)); }
     78            inline const Vector3& getAngularVelocity() const
     79                { return this->linearAcceleration_; }
     80
     81            void setAcceleration(const Vector3& acceleration);
     82            inline void setAcceleration(float x, float y, float z)
     83                { this->setAcceleration(Vector3(x, y, z)); }
     84            inline const Vector3& getAcceleration() const
     85                { return this->linearAcceleration_; }
     86
     87            void setAngularAcceleration(const Vector3& acceleration);
     88            inline void setAngularAcceleration(float x, float y, float z)
     89                { this->setAngularAcceleration(Vector3(x, y, z)); }
     90            inline const Vector3& getAngularAcceleration() const
     91                { return this->angularAcceleration_; }
     92
     93            inline void setRotationRate(Degree rate)
     94                { this->setAngularVelocity(this->getAngularVelocity().normalisedCopy() * rate.valueRadians()); }
     95            inline Degree getRotationRate() const
     96                { return Degree(this->getAngularVelocity().length()); }
     97
     98            inline void setRotationAxis(const Vector3& axis)
     99                { this->setAngularVelocity(axis * this->getAngularVelocity().length()); }
     100            inline Vector3 getRotationAxis() const
     101                { return this->getAngularVelocity().normalisedCopy(); }
    74102
    75103        protected:
    76             Vector3 velocity_;
     104            Vector3 linearAcceleration_;
     105            Vector3 linearVelocity_;
     106            Vector3 angularAcceleration_;
     107            Vector3 angularVelocity_;
    77108
    78109        private:
    79             //void attachPhysicalObject(WorldEntity* object);
    80 
    81             virtual void positionChanged() { }
    82             virtual void orientationChanged() { }
    83             virtual void velocityChanged() { }
     110            virtual void positionChanged       (bool bContinuous) { }
     111            virtual void orientationChanged    (bool bContinuous) { }
     112            virtual void linearVelocityChanged (bool bContinuous) { }
     113            virtual void angularVelocityChanged(bool bContinuous) { }
    84114
    85115            virtual bool isCollisionTypeLegal(WorldEntity::CollisionType type) const;
  • code/branches/physics/src/orxonox/objects/worldentities/StaticEntity.cc

    r2304 r2374  
    3131#include "StaticEntity.h"
    3232
     33#include "BulletDynamics/Dynamics/btRigidBody.h"
     34
    3335#include "util/Exception.h"
    3436#include "core/CoreIncludes.h"
     
    5153    void StaticEntity::registerVariables()
    5254    {
    53         REGISTERDATA(this->getPosition().x, network::direction::toclient);
    54         REGISTERDATA(this->getPosition().y, network::direction::toclient);
    55         REGISTERDATA(this->getPosition().z, network::direction::toclient);
    56 
    57         REGISTERDATA(this->getOrientation().w, network::direction::toclient);
    58         REGISTERDATA(this->getOrientation().x, network::direction::toclient);
    59         REGISTERDATA(this->getOrientation().y, network::direction::toclient);
    60         REGISTERDATA(this->getOrientation().z, network::direction::toclient);
     55        REGISTERDATA(this->getPosition(),    network::direction::toclient, new network::NetworkCallback<StaticEntity>(this, &StaticEntity::positionChanged));
     56        REGISTERDATA(this->getOrientation(), network::direction::toclient, new network::NetworkCallback<StaticEntity>(this, &StaticEntity::orientationChanged));
     57    }
     58
     59
     60    void StaticEntity::setPosition(const Vector3& position)
     61    {
     62        if (this->isPhysicsRunning())
     63            ThrowException(PhysicsViolation, "Cannot change position or orientation of a StaticEntity with physics at run time.");
     64        if (this->isStatic())
     65        {
     66            btTransform transf = this->physicalBody_->getWorldTransform();
     67            transf.setOrigin(btVector3(position.x, position.y, position.z));
     68            this->physicalBody_->setWorldTransform(transf);
     69        }
     70
     71        this->node_->setPosition(position);
     72    }
     73
     74    void StaticEntity::translate(const Vector3& distance, Ogre::Node::TransformSpace relativeTo)
     75    {
     76        if (this->isPhysicsRunning())
     77            ThrowException(PhysicsViolation, "Cannot change position or orientation of a StaticEntity with physics at run time.");
     78        if (this->isStatic())
     79        {
     80            OrxAssert(relativeTo == Ogre::Node::TS_LOCAL, "Cannot translate physical object relative \
     81                                                          to any other space than TS_LOCAL.");
     82            this->physicalBody_->translate(btVector3(distance.x, distance.y, distance.z));
     83        }
     84
     85        this->node_->translate(distance, relativeTo);
     86    }
     87
     88    void StaticEntity::setOrientation(const Quaternion& orientation)
     89    {
     90        if (this->isPhysicsRunning())
     91            ThrowException(PhysicsViolation, "Cannot change position or orientation of a StaticEntity with physics at run time.");
     92        if (this->isStatic())
     93        {
     94            btTransform transf = this->physicalBody_->getWorldTransform();
     95            transf.setRotation(btQuaternion(orientation.x, orientation.y, orientation.z, orientation.w));
     96            this->physicalBody_->setWorldTransform(transf);
     97        }
     98
     99        this->node_->setOrientation(orientation);
     100    }
     101
     102    void StaticEntity::rotate(const Quaternion& rotation, Ogre::Node::TransformSpace relativeTo)
     103    {
     104        if (this->isPhysicsRunning())
     105            ThrowException(PhysicsViolation, "Cannot change position or orientation of a StaticEntity with physics at run time.");
     106        if (this->isStatic())
     107        {
     108            OrxAssert(relativeTo == Ogre::Node::TS_LOCAL, "Cannot rotate physical object relative \
     109                                                          to any other space than TS_LOCAL.");
     110            btTransform transf = this->physicalBody_->getWorldTransform();
     111            this->physicalBody_->setWorldTransform(transf * btTransform(btQuaternion(rotation.x, rotation.y, rotation.z, rotation.w)));
     112        }
     113
     114        this->node_->rotate(rotation, relativeTo);
     115    }
     116
     117    void StaticEntity::yaw(const Degree& angle, Ogre::Node::TransformSpace relativeTo)
     118    {
     119        if (this->isPhysicsRunning())
     120            ThrowException(PhysicsViolation, "Cannot change position or orientation of a StaticEntity with physics at run time.");
     121        if (this->isStatic())
     122        {
     123            OrxAssert(relativeTo == Ogre::Node::TS_LOCAL, "Cannot yaw physical object relative \
     124                                                          to any other space than TS_LOCAL.");
     125            btTransform transf = this->physicalBody_->getWorldTransform();
     126            btTransform rotation(btQuaternion(angle.valueRadians(), 0.0f, 0.0f));
     127            this->physicalBody_->setWorldTransform(transf * rotation);
     128        }
     129
     130        this->node_->yaw(angle, relativeTo);
     131    }
     132
     133    void StaticEntity::pitch(const Degree& angle, Ogre::Node::TransformSpace relativeTo)
     134    {
     135        if (this->isPhysicsRunning())
     136            ThrowException(PhysicsViolation, "Cannot change position or orientation of a StaticEntity with physics at run time.");
     137        if (this->isStatic())
     138        {
     139            OrxAssert(relativeTo == Ogre::Node::TS_LOCAL, "Cannot pitch physical object relative \
     140                                                          to any other space than TS_LOCAL.");
     141            btTransform transf = this->physicalBody_->getWorldTransform();
     142            btTransform rotation(btQuaternion(0.0f, angle.valueRadians(), 0.0f));
     143            this->physicalBody_->setWorldTransform(transf * rotation);
     144        }
     145
     146        this->node_->pitch(angle, relativeTo);
     147    }
     148
     149    void StaticEntity::roll(const Degree& angle, Ogre::Node::TransformSpace relativeTo)
     150    {
     151        if (this->isPhysicsRunning())
     152            ThrowException(PhysicsViolation, "Cannot change position or orientation of a StaticEntity with physics at run time.");
     153        if (this->isStatic())
     154        {
     155            OrxAssert(relativeTo == Ogre::Node::TS_LOCAL, "Cannot roll physical object relative \
     156                                                          to any other space than TS_LOCAL.");
     157            btTransform transf = this->physicalBody_->getWorldTransform();
     158            btTransform rotation(btQuaternion(angle.valueRadians(), 0.0f, 0.0f));
     159            this->physicalBody_->setWorldTransform(transf * rotation);
     160        }
     161
     162        this->node_->roll(angle, relativeTo);
     163    }
     164
     165    void StaticEntity::lookAt(const Vector3& target, Ogre::Node::TransformSpace relativeTo, const Vector3& localDirectionVector)
     166    {
     167        if (this->isPhysicsRunning())
     168            ThrowException(PhysicsViolation, "Cannot change position or orientation of a StaticEntity with physics at run time.");
     169        if (this->isStatic())
     170        {
     171            ThrowException(NotImplemented, "ControllableEntity::lookAt() is not yet supported for physical objects.");
     172            OrxAssert(relativeTo == Ogre::Node::TS_LOCAL, "Cannot align physical object relative \
     173                                                          to any other space than TS_LOCAL.");
     174        }
     175
     176        this->node_->lookAt(target, relativeTo, localDirectionVector);
     177    }
     178
     179    void StaticEntity::setDirection(const Vector3& direction, Ogre::Node::TransformSpace relativeTo, const Vector3& localDirectionVector)
     180    {
     181        if (this->isPhysicsRunning())
     182            ThrowException(PhysicsViolation, "Cannot change position or orientation of a StaticEntity with physics at run time.");
     183        if (this->isStatic())
     184        {
     185            ThrowException(NotImplemented, "ControllableEntity::setDirection() is not yet supported for physical objects.");
     186            OrxAssert(relativeTo == Ogre::Node::TS_LOCAL, "Cannot align physical object relative \
     187                                                          to any other space than TS_LOCAL.");
     188        }
     189
     190        this->node_->setDirection(direction, relativeTo, localDirectionVector);
    61191    }
    62192
     
    81211    {
    82212        worldTrans.setOrigin(btVector3(node_->getPosition().x, node_->getPosition().y, node_->getPosition().z));
    83         worldTrans.setRotation(btQuaternion(node_->getOrientation().w, node_->getOrientation().x, node_->getOrientation().y, node_->getOrientation().z));
     213        worldTrans.setRotation(btQuaternion(node_->getOrientation().x, node_->getOrientation().y, node_->getOrientation().z, node_->getOrientation().w));
    84214    }
    85215}
  • code/branches/physics/src/orxonox/objects/worldentities/StaticEntity.h

    r2304 r2374  
    5454            using WorldEntity::setDirection;
    5555
    56             inline void setPosition(const Vector3& position)
    57                 { this->node_->setPosition(position); }
    58             inline void translate(const Vector3& distance, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL)
    59                 { this->node_->translate(distance, relativeTo); }
    60             inline void setOrientation(const Quaternion& orientation)
    61                 { this->node_->setOrientation(orientation); }
    62             inline void rotate(const Quaternion& rotation, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL)
    63                 { this->node_->rotate(rotation, relativeTo); }
    64             inline void yaw(const Degree& angle, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL)
    65                 { this->node_->yaw(angle, relativeTo); }
    66             inline void pitch(const Degree& angle, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL)
    67                 { this->node_->pitch(angle, relativeTo); }
    68             inline void roll(const Degree& angle, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL)
    69                 { this->node_->roll(angle, relativeTo); }
    70             inline void lookAt(const Vector3& target, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL, const Vector3& localDirectionVector = Vector3::NEGATIVE_UNIT_Z)
    71                 { this->node_->lookAt(target, relativeTo, localDirectionVector); }
    72             inline void setDirection(const Vector3& direction, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL, const Vector3& localDirectionVector = Vector3::NEGATIVE_UNIT_Z)
    73                 { this->node_->setDirection(direction, relativeTo, localDirectionVector); }
     56            void setPosition(const Vector3& position);
     57            void translate(const Vector3& distance, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL);
     58            void setOrientation(const Quaternion& orientation);
     59            void rotate(const Quaternion& rotation, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL);
     60            void yaw(const Degree& angle, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL);
     61            void pitch(const Degree& angle, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL);
     62            void roll(const Degree& angle, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL);
     63            void lookAt(const Vector3& target, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL, const Vector3& localDirectionVector = Vector3::NEGATIVE_UNIT_Z);
     64            void setDirection(const Vector3& direction, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL, const Vector3& localDirectionVector = Vector3::NEGATIVE_UNIT_Z);
    7465
    7566        private:
     67            bool isCollisionTypeLegal(CollisionType type) const;
    7668
    77             bool isCollisionTypeLegal(CollisionType type) const;
     69            inline void positionChanged()
     70                { this->setPosition(this->getPosition()); }
     71            inline void orientationChanged()
     72                { this->setOrientation(this->getOrientation()); }
    7873
    7974            // Bullet btMotionState related
  • code/branches/physics/src/orxonox/objects/worldentities/WorldEntity.cc

    r2313 r2374  
    1414 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
    1515 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    16  *   GNU General Public License for more details.
     16 *   GNU General Public License for more details. 
    1717 *
    1818 *   You should have received a copy of the GNU General Public License
     
    7373        // Default behaviour does not include physics
    7474        this->physicalBody_ = 0;
    75         this->collisionShape_ = 0;
     75        this->collisionShape_ = new CompoundCollisionShape(this);
    7676        this->mass_ = 0;
    7777        this->childMass_ = 0;
    7878        this->collisionType_ = None;
     79        this->collisionTypeSynchronised_ = None;
    7980
    8081        this->registerVariables();
     
    113114        XMLPortParam(WorldEntity, "scale", setScale, getScale, xmlelement, mode);
    114115
     116        // Physics
    115117        XMLPortParam(WorldEntity, "collisionType", setCollisionTypeStr, getCollisionTypeStr, xmlelement, mode);
    116         //XMLPortParam(WorldEntity, "collisionRadius", setCollisionRadius, getCollisionRadius, xmlelement, mode);
    117118        XMLPortParam(WorldEntity, "mass", setMass, getMass, xmlelement, mode);
    118119
     120        // Other attached WorldEntities
    119121        XMLPortObject(WorldEntity, WorldEntity, "attached", attach, getAttachedObject, xmlelement, mode);
     122        // Attached collision shapes
    120123        XMLPortObject(WorldEntity, CollisionShape, "collisionShapes", attachCollisionShape, getAttachedCollisionShape, xmlelement, mode);
    121124    }
     
    123126    void WorldEntity::registerVariables()
    124127    {
    125         REGISTERDATA(this->bActive_,  network::direction::toclient, new network::NetworkCallback<WorldEntity>(this, &WorldEntity::changedActivity));
    126         REGISTERDATA(this->bVisible_, network::direction::toclient, new network::NetworkCallback<WorldEntity>(this, &WorldEntity::changedVisibility));
    127 
    128         REGISTERDATA(this->getScale3D().x, network::direction::toclient);
    129         REGISTERDATA(this->getScale3D().y, network::direction::toclient);
    130         REGISTERDATA(this->getScale3D().z, network::direction::toclient);
     128        REGISTERDATA(this->bActive_,     network::direction::toclient, new network::NetworkCallback<WorldEntity>(this, &WorldEntity::changedActivity));
     129        REGISTERDATA(this->bVisible_,    network::direction::toclient, new network::NetworkCallback<WorldEntity>(this, &WorldEntity::changedVisibility));
     130
     131        // HACK: Removed the call because it gets called the first time as well
     132        REGISTERDATA(this->getScale3D(), network::direction::toclient);//, new network::NetworkCallback<WorldEntity>(this, &WorldEntity::scaleChanged));
     133
     134        int* collisionType = (int*)&this->collisionTypeSynchronised_;
     135        REGISTERDATA(*collisionType, network::direction::toclient, new network::NetworkCallback<WorldEntity>(this, &WorldEntity::collisionTypeChanged));
     136        REGISTERDATA(this->mass_,    network::direction::toclient, new network::NetworkCallback<WorldEntity>(this, &WorldEntity::massChanged));
    131137
    132138        REGISTERDATA(this->parentID_, network::direction::toclient, new network::NetworkCallback<WorldEntity>(this, &WorldEntity::updateParent));
     
    138144        if (parent)
    139145            this->attachToParent(parent);
     146    }
     147
     148    void WorldEntity::collisionTypeChanged()
     149    {
     150        if (this->collisionTypeSynchronised_ != Dynamic &&
     151            this->collisionTypeSynchronised_ != Kinematic &&
     152            this->collisionTypeSynchronised_ != Static &&
     153            this->collisionTypeSynchronised_ != None)
     154        {
     155            CCOUT(1) << "Error when collsion Type was received over network. Unknown enum value:" << this->collisionTypeSynchronised_ << std::endl;
     156        }
     157        else if (this->collisionTypeSynchronised_ != collisionType_)
     158        {
     159            if (this->parent_)
     160                CCOUT(2) << "Warning: Network connection tried to set the collision type of an attached WE. Ignoring." << std::endl;
     161            else
     162                this->setCollisionType(this->collisionTypeSynchronised_);
     163        }
     164    }
     165
     166    void WorldEntity::massChanged()
     167    {
     168        this->setMass(this->mass_);
    140169    }
    141170
     
    210239    void WorldEntity::attachCollisionShape(CollisionShape* shape)
    211240    {
    212         this->attachedShapes_.push_back(shape);
    213 
    214         if (!this->collisionShape_ && shape->hasNoTransform())
    215         {
    216             // Set local scaling right when adding it. It can include both scaling parameters
    217             // and shape parameters (like sphere radius)
    218             shape->getCollisionShape()->setLocalScaling(shape->getTotalScaling());
    219             this->collisionShape_ = shape;
    220             // recalculate inertia tensor
    221             if (this->isDynamic())
    222                 internalSetMassProps();
    223         }
    224         else
    225         {
    226             if (this->collisionShape_ && !this->collisionShape_->isCompoundShape())
    227             {
    228                 // We have to create a new compound shape and add the old one first.
    229                 CollisionShape* thisShape = this->collisionShape_;
    230                 this->collisionShape_ = 0;
    231                 this->mergeCollisionShape(thisShape);
    232             }
    233             this->mergeCollisionShape(shape);
    234         }
     241        this->collisionShape_->addChildShape(shape);
    235242
    236243        if (this->physicalBody_)
     
    241248                removeFromPhysicalWorld();
    242249            }
    243             this->physicalBody_->setCollisionShape(this->collisionShape_->getCollisionShape());
    244         }
    245 
    246         addToPhysicalWorld();
     250            if (this->collisionShape_->getCollisionShape())
     251                this->physicalBody_->setCollisionShape(this->collisionShape_->getCollisionShape());
     252            // recalculate inertia tensor
     253            internalSetMassProps();
     254            addToPhysicalWorld();
     255        }
    247256    }
    248257
    249258    CollisionShape* WorldEntity::getAttachedCollisionShape(unsigned int index) const
    250259    {
    251         if (index < this->attachedShapes_.size())
    252             return attachedShapes_[index];
    253         else
    254             return 0;
    255     }
    256 
    257     void WorldEntity::mergeCollisionShape(CollisionShape* shape)
    258     {
    259         if (!this->collisionShape_)
    260             this->collisionShape_ = new CompoundCollisionShape(this);
    261         assert(this->collisionShape_->isCompoundShape());
    262 
    263         // merge with transform
    264         CompoundCollisionShape* compoundShape = static_cast<CompoundCollisionShape*>(this->collisionShape_);
    265         assert(compoundShape);
    266         compoundShape->addChildShape(shape);
    267 
    268         // recalculate inertia tensor
    269         internalSetMassProps();
     260        return this->collisionShape_->getChildShape(index);
    270261    }
    271262
     
    302293        this->mass_ = mass;
    303294        if (!this->hasPhysics())
    304             COUT(3) << "Warning: Setting the mass of a WorldEntity with no physics has no effect." << std::endl;
     295            return;
     296        // TODO: Add this again when new network callbacks work properly
     297            //COUT(3) << "Warning: Setting the mass of a WorldEntity with no physics has no effect." << std::endl;
    305298        else
    306299        {
     
    320313        assert(hasPhysics());
    321314
    322         if ((this->isKinematic() || this->isStatic()) && (this->mass_ + this->childMass_) != 0.0f)
    323         {
    324             // Mass non zero is a bad idea for kinematic and static objects
     315        if (this->isStatic())
     316        {
     317            // Just set everything to zero
    325318            this->physicalBody_->setMassProps(0.0f, btVector3(0, 0, 0));
    326319        }
    327         else if (this->isDynamic() && (this->mass_ + this->childMass_) == 0.0f)
    328         {
    329             // Mass zero is not such a good idea for dynamic objects
     320        else if ((this->mass_ + this->childMass_) == 0.0f)
     321        {
     322            // Use default values to avoid very large or very small values
     323            CCOUT(2) << "Warning: Setting the internal physical mass to 1.0 because mass_ is 0.0." << std::endl;
    330324            this->physicalBody_->setMassProps(1.0f, this->getLocalInertia(1.0f));
    331325        }
     
    337331    {
    338332        btVector3 inertia(0, 0, 0);
    339         if (this->collisionShape_)
     333        if (this->collisionShape_->getCollisionShape())
    340334            this->collisionShape_->getCollisionShape()->calculateLocalInertia(mass, inertia);
    341335        return inertia;
     
    368362            this->physicalBody_ = new btRigidBody(bodyConstructionInfo);
    369363            this->physicalBody_->setUserPointer(this);
     364            this->physicalBody_->setActivationState(DISABLE_DEACTIVATION);
    370365        }
    371366        else if (type == None && this->collisionType_ != None)
     
    377372            this->physicalBody_ = 0;
    378373            this->collisionType_ = None;
     374            this->collisionTypeSynchronised_ = None;
    379375            return;
    380376        }
     
    401397
    402398        // update mass and inertia tensor
    403         internalSetMassProps(); // type is not None! See case None: in switch
     399        internalSetMassProps(); // type is not None! See case None in switch
    404400
    405401        addToPhysicalWorld();
     
    451447        else
    452448            this->collisionType_ = Dynamic;
     449        this->collisionTypeSynchronised_ = this->collisionType_;
     450    }
     451
     452    bool WorldEntity::isPhysicsRunning() const
     453    {
     454        return this->physicalBody_ && this->physicalBody_->isInWorld();
    453455    }
    454456
  • code/branches/physics/src/orxonox/objects/worldentities/WorldEntity.h

    r2313 r2374  
    164164                { this->roll(angle); }
    165165
     166            inline void scaleChanged()
     167                { this->setScale3D(this->getScale3D()); }
     168
    166169            WorldEntity* parent_;
    167170            unsigned int parentID_;
     
    186189            bool isKinematic() const { return getCollisionType() == Kinematic; }
    187190            bool isDynamic()   const { return getCollisionType() == Dynamic  ; }
     191            bool isPhysicsRunning() const;
    188192
    189193            inline CollisionType getCollisionType() const
     
    201205            CollisionShape* getAttachedCollisionShape(unsigned int index) const;
    202206
    203             inline CollisionShape* getCollisionShape()
     207            inline CompoundCollisionShape* getCollisionShape()
    204208                { return this->collisionShape_; }
    205209            inline btRigidBody* getPhysicalBody()
     
    220224            void removeFromPhysicalWorld() const;
    221225
     226            // network callbacks
     227            void collisionTypeChanged();
     228            void massChanged();
     229
    222230            CollisionType                collisionType_;
    223             std::vector<CollisionShape*> attachedShapes_;
    224             CollisionShape*              collisionShape_;
     231            CollisionType                collisionTypeSynchronised_;
     232            CompoundCollisionShape*      collisionShape_;
    225233            btScalar                     mass_;
    226234            btScalar                     childMass_;
  • code/branches/physics/src/orxonox/objects/worldentities/collisionshapes/CollisionShape.cc

    r2306 r2374  
    3737#include "tools/BulletConversions.h"
    3838
     39#include "CompoundCollisionShape.h"
     40
    3941namespace orxonox
    4042{
    4143    CreateFactory(CollisionShape);
    4244
    43     CollisionShape::CollisionShape(BaseObject* creator) : StaticEntity(creator)
     45    CollisionShape::CollisionShape(BaseObject* creator)
     46        : BaseObject(creator)
     47        , network::Synchronisable(creator)
    4448    {
    4549        RegisterObject(CollisionShape);
    4650
    47         this->bIsCompound_ = false;
     51        this->parent_ = 0;
     52        this->parentID_ = (unsigned int)-1;
     53        this->collisionShape_ = 0;
    4854    }
    4955
     
    5561    {
    5662        SUPER(CollisionShape, XMLPort, xmlelement, mode);
     63
     64        XMLPortParamTemplate(CollisionShape, "position", setPosition, getPosition, xmlelement, mode, const Vector3&);
     65        XMLPortParamTemplate(CollisionShape, "orientation", setOrientation, getOrientation, xmlelement, mode, const Quaternion&);
     66        XMLPortParamLoadOnly(CollisionShape, "yaw",   yaw,   xmlelement, mode);
     67        XMLPortParamLoadOnly(CollisionShape, "pitch", pitch, xmlelement, mode);
     68        XMLPortParamLoadOnly(CollisionShape, "roll",  roll,  xmlelement, mode);
     69        XMLPortParamTemplate(CollisionShape, "scale3D", setScale3D, getScale3D, xmlelement, mode, const Vector3&);
     70        XMLPortParamLoadOnly(CollisionShape, "scale", setScale, xmlelement, mode);
    5771    }
    5872
    59     bool CollisionShape::isCollisionTypeLegal(WorldEntity::CollisionType type) const
     73    void CollisionShape::registerVariables()
    6074    {
    61         if (type != WorldEntity::None)
    62         {
    63             ThrowException(PhysicsViolation, "A CollisionShape can only have CollisionType 'None'.");
    64             return false;
    65         }
    66         else
    67             return true;
     75        REGISTERDATA(this->parentID_, network::direction::toclient, new network::NetworkCallback<CollisionShape>(this, &CollisionShape::updateParent));
    6876    }
    6977
    70     bool CollisionShape::hasNoTransform() const
     78    void CollisionShape::updateParent()
    7179    {
    72         return (this->getPosition().positionEquals(Vector3(0, 0, 0), 0.001) &&
    73                 this->getOrientation().equals(Quaternion(1,0,0,0), Degree(0.1)));
     80        CompoundCollisionShape* parent = dynamic_cast<CompoundCollisionShape*>(Synchronisable::getSynchronisable(this->parentID_));
     81        if (parent)
     82            parent->addChildShape(this);
    7483    }
    7584
    76     btVector3 CollisionShape::getTotalScaling()
     85    bool CollisionShape::hasTransform() const
    7786    {
    78         return omni_cast<btVector3>(this->node_->getScale());
     87        return (!this->position_.positionEquals(Vector3(0, 0, 0), 0.001) ||
     88                !this->orientation_.equals(Quaternion(1,0,0,0), Degree(0.1)));
    7989    }
    8090
     
    8494    }
    8595
    86     void CollisionShape::scale3D(const Vector3& scale)
     96    void CollisionShape::setScale(float scale)
    8797    {
    8898        ThrowException(NotImplemented, "Cannot set the scale of a collision shape: Not yet implemented.");
  • code/branches/physics/src/orxonox/objects/worldentities/collisionshapes/CollisionShape.h

    r2306 r2374  
    3232#include "OrxonoxPrereqs.h"
    3333
    34 #include "objects/worldentities/StaticEntity.h"
     34#include "util/Math.h"
     35#include "core/BaseObject.h"
    3536
    3637namespace orxonox
    3738{
    38     class _OrxonoxExport CollisionShape : public StaticEntity
     39    class _OrxonoxExport CollisionShape : public BaseObject, public network::Synchronisable
    3940    {
    4041        public:
     
    4344
    4445            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
     46            void registerVariables();
    4547
    46             btCollisionShape* getCollisionShape() const { return this->collisionShape_; }
    47             bool isCompoundShape() const { return this->bIsCompound_; }
     48            inline void setPosition(const Vector3& position)
     49                { this->position_ = position; }
     50            inline const Vector3& getPosition() const
     51                { return this->position_; }
    4852
    49             bool hasNoTransform() const;
    50             virtual btVector3 getTotalScaling();
     53            inline void setOrientation(const Quaternion& orientation)
     54                { this->orientation_ = orientation; }
     55            inline const Quaternion& getOrientation() const
     56                { return this->orientation_; }
     57
     58            void yaw(const Degree& angle)   { this->orientation_ = this->orientation_ * Quaternion(angle, Vector3::UNIT_Y); }
     59            void pitch(const Degree& angle) { this->orientation_ = this->orientation_ * Quaternion(angle, Vector3::UNIT_X); }
     60            void roll(const Degree& angle)  { this->orientation_ = this->orientation_ * Quaternion(angle, Vector3::UNIT_Z); }
     61
     62            virtual void setScale3D(const Vector3& scale);
     63            virtual void setScale(float scale);
     64            inline const Vector3& getScale3D(void) const
     65                { return this->scale_; }
     66
     67            virtual inline btCollisionShape* getCollisionShape() const
     68                { return this->collisionShape_; }
     69
     70            bool hasTransform() const;
     71
     72            inline void setParent(CompoundCollisionShape* shape, unsigned int ID)
     73                { this->parent_ = shape; this->parentID_ = ID; }
    5174
    5275        protected:
    53             bool              bIsCompound_;
    5476            btCollisionShape* collisionShape_;
    5577
    5678        private:
    57             virtual void setScale3D(const Vector3& scale);
    58             virtual void scale3D(const Vector3& scale);
     79            void updateParent();
    5980
    60             bool isCollisionTypeLegal(WorldEntity::CollisionType type) const;
     81            Vector3           position_;
     82            Quaternion        orientation_;
     83            Vector3           scale_;
     84            CompoundCollisionShape* parent_;
     85            unsigned int      parentID_;
    6186    };
    6287}
  • code/branches/physics/src/orxonox/objects/worldentities/collisionshapes/CompoundCollisionShape.cc

    r2304 r2374  
    4444        RegisterObject(CompoundCollisionShape);
    4545
    46         this->bIsCompound_    = true;
     46        this->collisionShape_ = 0;
    4747        this->compoundShape_  = new btCompoundShape();
    48         this->collisionShape_ = this->compoundShape_;
    4948    }
    5049
     
    5857    {
    5958        SUPER(CompoundCollisionShape, XMLPort, xmlelement, mode);
     59        // Attached collision shapes
     60        XMLPortObject(CompoundCollisionShape, CollisionShape, "", addChildShape, getChildShape, xmlelement, mode);
     61    }
    6062
    61         XMLPortObject(CompoundCollisionShape, CollisionShape, "", addChildShape, getChildShape, xmlelement, mode);
     63    btCollisionShape* CompoundCollisionShape::getCollisionShape() const
     64    {
     65        // Note: Returning collisionShape_ means that it's the only one and has no transform.
     66        //       So we can get rid of the additional overhead with the compound shape.
     67        if (this->collisionShape_)
     68            return this->collisionShape_;
     69        else if (this->childShapes_.size() != 0)
     70            return this->compoundShape_;
     71        else
     72            return 0;
    6273    }
    6374
    6475    void CompoundCollisionShape::addChildShape(CollisionShape* shape)
    6576    {
    66         this->childShapes_.push_back(shape);
     77        if (!shape || !shape->getCollisionShape())
     78            return;
     79        assert(this->compoundShape_);
    6780        btTransform transf(omni_cast<btQuaternion>(shape->getOrientation()), omni_cast<btVector3>(shape->getPosition()));
    68         shape->getCollisionShape()->setLocalScaling(shape->getTotalScaling());
    6981        this->compoundShape_->addChildShape(transf, shape->getCollisionShape());
     82
     83        if (this->childShapes_.size() == 1 && this->childShapes_[0] && !this->childShapes_[0]->hasTransform())
     84        {
     85            // --> Only shape to be added, no transform; add it directly
     86            this->collisionShape_ = shape->getCollisionShape();
     87        }
     88        else
     89        {
     90            // Make sure we use the compound shape
     91            this->collisionShape_ = 0;
     92        }
     93
     94        // network synchro
     95        shape->setParent(this, this->getObjectID());
    7096    }
    7197
  • code/branches/physics/src/orxonox/objects/worldentities/collisionshapes/CompoundCollisionShape.h

    r2304 r2374  
    4848            CollisionShape* getChildShape(unsigned int index) const;
    4949
     50            virtual btCollisionShape* getCollisionShape() const;
     51
    5052        private:
    5153            btCompoundShape* compoundShape_;
  • code/branches/physics/src/orxonox/objects/worldentities/collisionshapes/PlaneCollisionShape.cc

    r2323 r2374  
    2121 *
    2222 *   Author:
    23  *      Reto Grieder
     23 *      Martin Stypinski
    2424 *   Co-authors:
    2525 *      ...
     
    3030#include "PlaneCollisionShape.h"
    3131
    32 #include "BulletCollision/CollisionShapes/btStaticPlaneShape.h"
    33 
    34 #include "tools/BulletConversions.h"
    3532#include "core/CoreIncludes.h"
    3633#include "core/XMLPort.h"
     
    4542        RegisterObject(PlaneCollisionShape);
    4643
    47         this->planeShape_ = new btStaticPlaneShape(btVector3(1,1,1), 0);
     44        this->planeShape_ = new btStaticPlaneShape(btVector3(1, 1, 1), 0);
    4845        this->collisionShape_ = this->planeShape_;
     46        this->planeNormal_ = Vector3(1, 1, 1);
     47        this->planeOffset_ = 0.0f;
    4948    }
    5049
     
    5251    {
    5352        if (this->isInitialized())
    54             delete this->collisionShape_;
     53            delete this->planeShape_;
    5554    }
    5655
    57     void PlaneCollisionShape::setNormal(const Vector3& normal)
     56    void PlaneCollisionShape::registerVariables()
    5857    {
    59         btScalar offset = this->planeShape_->getPlaneConstant();
    60         delete this->collisionShape_;
    61         this->planeShape_ = new btStaticPlaneShape(omni_cast<btVector3>(normal), offset);
    62         this->collisionShape_ = this->planeShape_;
    63     }
    64 
    65     void PlaneCollisionShape::setOffset(float offset)
    66     {
    67         btVector3 normal = this->planeShape_->getPlaneNormal();
    68         delete this->collisionShape_;
    69         this->planeShape_ = new btStaticPlaneShape(normal, offset);
    70         this->collisionShape_ = this ->planeShape_;
     58        REGISTERDATA(this->planeNormal_, network::direction::toclient, new network::NetworkCallback<PlaneCollisionShape>(this, &PlaneCollisionShape::planeNormalChanged));
     59        REGISTERDATA(this->planeOffset_, network::direction::toclient, new network::NetworkCallback<PlaneCollisionShape>(this, &PlaneCollisionShape::planeOffsetChanged));
    7160    }
    7261
     
    7564        SUPER(PlaneCollisionShape, XMLPort, xmlelement, mode);
    7665
    77         XMLPortParam(PlaneCollisionShape, "normal", setNormal, getNormal, xmlelement, mode);
    78         XMLPortParam(PlaneCollisionShape, "offset", setOffset, getOffset, xmlelement, mode);   
     66        XMLPortParam(PlaneCollisionShape, "planeNormal", setNormal, getNormal, xmlelement, mode);
     67        XMLPortParam(PlaneCollisionShape, "planeOffset", setOffset, getOffset, xmlelement, mode);   
    7968    }
    8069
    81     btVector3 PlaneCollisionShape::getTotalScaling()
     70    void PlaneCollisionShape::setNormal(const Vector3& normal)
    8271    {
    83         return omni_cast<btVector3>(this->node_->getScale()); //* this->radius_;
     72        delete this->planeShape_;
     73        this->planeNormal_ = normal;
     74        this->planeShape_ = new btStaticPlaneShape(omni_cast<btVector3>(normal), this->planeOffset_);
     75        this->collisionShape_ = this->planeShape_;
     76    }
     77
     78    void PlaneCollisionShape::setOffset(float offset)
     79    {
     80        delete this->planeShape_;
     81        this->planeOffset_ = offset;
     82        this->planeShape_ = new btStaticPlaneShape(omni_cast<btVector3>(this->planeNormal_), offset);
     83        this->collisionShape_ = this->planeShape_;
    8484    }
    8585}
  • code/branches/physics/src/orxonox/objects/worldentities/collisionshapes/PlaneCollisionShape.h

    r2323 r2374  
    2121 *
    2222 *   Author:
    23  *      Reto Grieder
     23 *      Martin Stypinski
    2424 *   Co-authors:
    2525 *      ...
     
    3333
    3434#include "BulletCollision/CollisionShapes/btStaticPlaneShape.h"
    35 
    3635#include "CollisionShape.h"
    3736
     
    4443            virtual ~PlaneCollisionShape();
    4544
     45            void registerVariables();
    4646            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    4747
    48                
    49            
    5048            inline float getOffset()
    5149                { return this->planeShape_->getPlaneConstant();}
     50            void setOffset(float offset);
    5251
    5352            inline btVector3 getNormal()
    5453                { return this->planeShape_->getPlaneNormal();}
    55             void setOffset(float offset);
    5654            void setNormal(const Vector3& normal);
    5755
    58            private:
    59             virtual btVector3 getTotalScaling();
     56            inline void planeNormalChanged()
     57                { this->setNormal(this->planeNormal_); }
    6058
     59            inline void planeOffsetChanged()
     60                { this->setOffset(this->planeOffset_); }
     61
     62        private:
    6163            btStaticPlaneShape* planeShape_;
     64            Vector3             planeNormal_;
     65            float               planeOffset_;
    6266     };
    6367}
  • code/branches/physics/src/orxonox/objects/worldentities/collisionshapes/SphereCollisionShape.cc

    r2304 r2374  
    4646        this->sphereShape_ = new btSphereShape(1.0f);
    4747        this->collisionShape_ = this->sphereShape_;
     48
     49        this->registerVariables();
    4850    }
    4951
     
    5254        if (this->isInitialized())
    5355            delete this->collisionShape_;
     56    }
     57
     58    void SphereCollisionShape::registerVariables()
     59    {
     60        REGISTERDATA(this->radius_, network::direction::toclient, new network::NetworkCallback<SphereCollisionShape>(this, &SphereCollisionShape::radiusChanged));
    5461    }
    5562
     
    6168    }
    6269
    63     btVector3 SphereCollisionShape::getTotalScaling()
     70    void SphereCollisionShape::setRadius(float radius)
    6471    {
    65         return omni_cast<btVector3>(this->node_->getScale()) * this->radius_;
     72        // TODO: Think about where this could be referenced already.
     73        this->radius_ = radius;
     74        delete this->sphereShape_;
     75        this->sphereShape_ = new btSphereShape(radius);
    6676    }
    6777}
  • code/branches/physics/src/orxonox/objects/worldentities/collisionshapes/SphereCollisionShape.h

    r2304 r2374  
    4242            virtual ~SphereCollisionShape();
    4343
     44            void registerVariables();
    4445            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    4546
    46             inline void setRadius(float radius)
    47                 { this->radius_ = radius; }
     47            void setRadius(float radius);
    4848            inline float getRadius() const
    4949                { return this->radius_;}
    5050
     51            inline void radiusChanged()
     52                { this->setRadius(this->radius_); }
     53
    5154        private:
    52             virtual btVector3 getTotalScaling();
    53 
    5455            btSphereShape* sphereShape_;
    5556            float          radius_;
  • code/branches/physics/src/orxonox/objects/worldentities/pawns/SpaceShip.cc

    r2314 r2374  
    4040namespace orxonox
    4141{
     42    const float orientationGain = 100;
    4243    CreateFactory(SpaceShip);
    4344
     
    8485        if (this->physicalBody_)
    8586        {
    86             this->physicalBody_->setDamping(0.8, 0.9);
    87             this->physicalBody_->setActivationState(DISABLE_DEACTIVATION);
     87            this->physicalBody_->setDamping(0.7, 0.3);
    8888        }
    8989    }
     
    106106    void SpaceShip::tick(float dt)
    107107    {
    108         if (this->isLocallyControlled())
    109         {
    110             // #####################################
    111             // ############# STEERING ##############
    112             // #####################################
    113 
    114             //Vector3 velocity = this->getVelocity();
    115             //if (velocity.x > this->maxSecondarySpeed_)
    116             //    velocity.x = this->maxSecondarySpeed_;
    117             //if (velocity.x < -this->maxSecondarySpeed_)
    118             //    velocity.x = -this->maxSecondarySpeed_;
    119             //if (velocity.y > this->maxSecondarySpeed_)
    120             //    velocity.y = this->maxSecondarySpeed_;
    121             //if (velocity.y < -this->maxSecondarySpeed_)
    122             //    velocity.y = -this->maxSecondarySpeed_;
    123             //if (velocity.z > this->maxSecondarySpeed_)
    124             //    velocity.z = this->maxSecondarySpeed_;
    125             //if (velocity.z < -this->maxSpeed_)
    126             //    velocity.z = -this->maxSpeed_;
    127 
    128             // normalize velocity and acceleration
    129             //for (size_t dimension = 0; dimension < 3; ++dimension)
    130             //{
    131             //    if (this->acceleration_[dimension] == 0)
    132             //    {
    133             //        if (velocity[dimension] > 0)
    134             //        {
    135             //            velocity[dimension] -= (this->translationDamping_ * dt);
    136             //            if (velocity[dimension] < 0)
    137             //                velocity[dimension] = 0;
    138             //        }
    139             //        else if (velocity[dimension] < 0)
    140             //        {
    141             //            velocity[dimension] += (this->translationDamping_ * dt);
    142             //            if (velocity[dimension] > 0)
    143             //                velocity[dimension] = 0;
    144             //        }
    145             //    }
    146             //}
    147 
    148             //this->setVelocity(velocity);
    149         }
    150 
    151 
    152108        SUPER(SpaceShip, tick, dt);
    153 
    154 
    155         //if (this->isLocallyControlled())
    156         //{
    157         //    this->yaw(this->yawRotation_ * dt);
    158         //    if (this->bInvertYAxis_)
    159         //        this->pitch(Degree(-this->pitchRotation_ * dt));
    160         //    else
    161         //        this->pitch(Degree( this->pitchRotation_ * dt));
    162         //    this->roll(this->rollRotation_ * dt);
    163 
    164         //    this->acceleration_.x = 0;
    165         //    this->acceleration_.y = 0;
    166         //    this->acceleration_.z = 0;
    167 
    168         //    this->yawRotation_   = this->zeroDegree_;
    169         //    this->pitchRotation_ = this->zeroDegree_;
    170         //    this->rollRotation_  = this->zeroDegree_;
    171         //}
    172109    }
    173110
     
    176113        assert(this->physicalBody_);
    177114        this->physicalBody_->applyCentralForce(physicalBody_->getWorldTransform().getBasis() * btVector3(0.0f, 0.0f, -getMass() * value.x * 100));
    178 //        this->acceleration_.z = -this->translationAcceleration_ * value.x;
    179115    }
    180116
     
    182118    {
    183119        this->physicalBody_->applyCentralForce(physicalBody_->getWorldTransform().getBasis() * btVector3(getMass() * value.x * 100, 0.0f, 0.0f));
    184 //        this->acceleration_.x = this->translationAcceleration_ * value.x;
    185120    }
    186121
     
    188123    {
    189124        this->physicalBody_->applyCentralForce(physicalBody_->getWorldTransform().getBasis() * btVector3(0.0f, getMass() * value.x * 100, 0.0f));
    190 //        this->acceleration_.y = this->translationAcceleration_ * value.x;
    191125    }
    192126
    193127    void SpaceShip::rotateYaw(const Vector2& value)
    194128    {
    195         this->physicalBody_->applyTorque(physicalBody_->getWorldTransform().getBasis() * btVector3(0.0f, getMass() * value.x * 10000, 0.0f));
    196         //Degree temp = value.x * value.x * sgn(value.x) * this->rotationAcceleration_;
    197         //if (temp > this->maxRotation_)
    198         //    temp = this->maxRotation_;
    199         //if (temp < -this->maxRotation_)
    200         //    temp = -this->maxRotation_;
    201         //this->yawRotation_ = Degree(temp);
     129        this->physicalBody_->applyTorque(physicalBody_->getWorldTransform().getBasis() * btVector3(0.0f, 1 / this->physicalBody_->getInvInertiaDiagLocal().y() * value.y * orientationGain, 0.0f));
    202130    }
    203131
    204132    void SpaceShip::rotatePitch(const Vector2& value)
    205133    {
    206         this->physicalBody_->applyTorque(physicalBody_->getWorldTransform().getBasis() * btVector3(getMass() * value.x * 10000, 0.0f, 0.0f));
    207         //Degree temp = value.x * value.x * sgn(value.x) * this->rotationAcceleration_;
    208         //if (temp > this->maxRotation_)
    209         //    temp = this->maxRotation_;
    210         //if (temp < -this->maxRotation_)
    211         //    temp = -this->maxRotation_;
    212         //this->pitchRotation_ = Degree(temp);
     134        this->physicalBody_->applyTorque(physicalBody_->getWorldTransform().getBasis() * btVector3(1 / this->physicalBody_->getInvInertiaDiagLocal().x() * value.y * orientationGain, 0.0f, 0.0f));
    213135    }
    214136
    215137    void SpaceShip::rotateRoll(const Vector2& value)
    216138    {
    217         this->physicalBody_->applyTorque(physicalBody_->getWorldTransform().getBasis() * btVector3(0.0f, 0.0f, -getMass() * value.x * 10000));
    218         //Degree temp = value.x * value.x * sgn(value.x) * this->rotationAcceleration_;
    219         //if (temp > this->maxRotation_)
    220         //    temp = this->maxRotation_;
    221         //if (temp < -this->maxRotation_)
    222         //    temp = -this->maxRotation_;
    223         //this->rollRotation_ = Degree(temp);
     139        this->physicalBody_->applyTorque(physicalBody_->getWorldTransform().getBasis() * btVector3(0.0f, 0.0f, -1 / this->physicalBody_->getInvInertiaDiagLocal().z() * value.y * orientationGain));
    224140    }
    225141
  • code/branches/physics/src/orxonox/objects/worldentities/pawns/Spectator.cc

    r2297 r2374  
    108108            Vector3 velocity = this->getVelocity();
    109109            velocity.normalise();
    110             this->setVelocity(velocity * this->speed_);
     110            this->setVelocity(this->getOrientation() * velocity * this->speed_);
    111111
    112112            this->yaw(Radian(this->yaw_ * this->rotationSpeed_));
Note: See TracChangeset for help on using the changeset viewer.