Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jan 1, 2009, 7:34:44 PM (16 years ago)
Author:
rgrieder
Message:
  • Added WorldEntityCollisionShape to clarify when a CompoundCollisionShape belongs to a WE.
  • Also fixed problems with the synchronisation of the CollisionShape hierarchy.
Location:
code/branches/presentation/src/orxonox/objects/collisionshapes
Files:
2 added
5 edited

Legend:

Unmodified
Added
Removed
  • code/branches/presentation/src/orxonox/objects/collisionshapes/CMakeLists.txt

    r2486 r2562  
    66  PlaneCollisionShape.cc
    77  SphereCollisionShape.cc
     8  WorldEntityCollisionShape.cc
    89)
    910
  • code/branches/presentation/src/orxonox/objects/collisionshapes/CollisionShape.cc

    r2527 r2562  
    3737#include "tools/BulletConversions.h"
    3838
     39#include "objects/worldentities/WorldEntity.h"
    3940#include "CompoundCollisionShape.h"
    40 #include "objects/worldentities/WorldEntity.h"
     41#include "WorldEntityCollisionShape.h"
    4142
    4243namespace orxonox
     
    8586    void CollisionShape::parentChanged()
    8687    {
    87         CompoundCollisionShape* parent = dynamic_cast<CompoundCollisionShape*>(Synchronisable::getSynchronisable(this->parentID_));
    88         if (parent)
    89             parent->attach(this);
     88        Synchronisable* parent = Synchronisable::getSynchronisable(this->parentID_);
     89        // Parent can either be a WorldEntity or a CompoundCollisionShape. The reason is that the
     90        // internal collision shape (which is compound) of a WE doesn't get synchronised.
     91        CompoundCollisionShape* parentCCS = dynamic_cast<CompoundCollisionShape*>(parent);
     92        if (parentCCS)
     93            parentCCS->attach(this);
     94        else
     95        {
     96            WorldEntity* parentWE = dynamic_cast<WorldEntity*>(parent);
     97            if (parentWE)
     98                parentWE->attachCollisionShape(this);
     99        }
     100    }
     101
     102    bool CollisionShape::notifyBeingAttached(CompoundCollisionShape* newParent)
     103    {
     104        if (this->parent_)
     105            this->parent_->detach(this);
     106
     107        this->parent_ = newParent;
     108
     109        WorldEntityCollisionShape* parentWECCS = dynamic_cast<WorldEntityCollisionShape*>(newParent);
     110        if (parentWECCS)
     111            this->parentID_ = parentWECCS->getWorldEntityOwner()->getObjectID();
     112        else
     113            this->parentID_ = newParent->getObjectID();
     114
     115        return true;
     116    }
     117
     118    void CollisionShape::notifyDetached()
     119    {
     120        this->parent_ = 0;
     121        this->parentID_ = OBJECTID_UNKNOWN;
    90122    }
    91123
  • code/branches/presentation/src/orxonox/objects/collisionshapes/CollisionShape.h

    r2515 r2562  
    7575            bool hasTransform() const;
    7676
    77             inline void setParent(CompoundCollisionShape* shape, unsigned int ID)
    78                 { this->parent_ = shape; this->parentID_ = ID; }
     77            bool notifyBeingAttached(CompoundCollisionShape* newParent);
     78            void notifyDetached();
    7979
    8080        protected:
     
    8585            btCollisionShape*       collisionShape_;
    8686            CompoundCollisionShape* parent_;
     87            unsigned int            parentID_;
    8788
    8889        private:
     
    9091            Quaternion              orientation_;
    9192            Vector3                 scale_;
    92             unsigned int            parentID_;
    9393    };
    9494}
  • code/branches/presentation/src/orxonox/objects/collisionshapes/CompoundCollisionShape.cc

    r2527 r2562  
    3636#include "core/XMLPort.h"
    3737#include "tools/BulletConversions.h"
    38 #include "objects/worldentities/WorldEntity.h"
    3938
    4039namespace orxonox
     
    4746
    4847        this->compoundShape_  = new btCompoundShape();
    49         this->worldEntityParent_ = 0;
    5048    }
    5149
     
    5957            {
    6058                // make sure that the child doesn't want to detach itself --> speedup because of the missing update
    61                 it->first->setParent(0, OBJECTID_UNKNOWN);
     59                it->first->notifyDetached();
    6260                delete it->first;
    6361            }
     
    7472    }
    7573
    76     void CompoundCollisionShape::setWorldEntityParent(WorldEntity* parent)
    77     {
    78         // suppress synchronisation
    79         this->setObjectMode(0x0);
    80 
    81         this->worldEntityParent_ = parent;
    82     }
    83 
    8474    void CompoundCollisionShape::attach(CollisionShape* shape)
    8575    {
     
    9181            return;
    9282        }
     83
     84        if (!shape->notifyBeingAttached(this))
     85            return;
     86
    9387        this->attachedShapes_[shape] = shape->getCollisionShape();
    9488
     
    10195            this->updatePublicShape();
    10296        }
    103 
    104         // network synchro
    105         if (this->worldEntityParent_)
    106         {
    107             // This compound collision shape belongs to a WE and doesn't get synchronised
    108             // So set our parent to be the WE
    109             shape->setParent(this, this->worldEntityParent_->getObjectID());
    110         }
    111         else
    112             shape->setParent(this, this->getObjectID());
    11397    }
    11498
     
    117101        if (this->attachedShapes_.find(shape) != this->attachedShapes_.end())
    118102        {
    119             shape->setParent(0, OBJECTID_UNKNOWN);
    120103            this->attachedShapes_.erase(shape);
    121104            if (shape->getCollisionShape())
    122105                this->compoundShape_->removeChildShape(shape->getCollisionShape());
     106            shape->notifyDetached();
    123107
    124108            this->updatePublicShape();
     
    197181    }
    198182
    199     void CompoundCollisionShape::updateParent()
    200     {
    201         if (this->parent_)
    202             this->parent_->updateAttachedShape(this);
    203         if (this->worldEntityParent_)
    204             this->worldEntityParent_->notifyCollisionShapeChanged();
    205     }
    206 
    207     void CompoundCollisionShape::parentChanged()
    208     {
    209         if (!this->worldEntityParent_)
    210             CollisionShape::parentChanged();
    211     }
    212 
    213183    CollisionShape* CompoundCollisionShape::getAttachedShape(unsigned int index) const
    214184    {
  • code/branches/presentation/src/orxonox/objects/collisionshapes/CompoundCollisionShape.h

    r2527 r2562  
    5353            void updateAttachedShape(CollisionShape* shape);
    5454
    55             void setWorldEntityParent(WorldEntity* parent);
    56 
    57         protected:
    58             virtual void updateParent();
    59 
    6055        private:
    6156            void updatePublicShape();
    62             void parentChanged();
    6357            inline virtual btCollisionShape* createNewShape() const
    6458                { assert(false); return 0; }
     
    6660            btCompoundShape* compoundShape_;
    6761            std::map<CollisionShape*, btCollisionShape*> attachedShapes_;
    68             WorldEntity* worldEntityParent_;
    6962    };
    7063}
Note: See TracChangeset for help on using the changeset viewer.