Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 22, 2008, 10:23:29 PM (16 years ago)
Author:
rgrieder
Message:
  • Forgot to account for collision shape position and orientation when attaching WEs
  • addChildShape —> attach in CompoundCollisionShape
  • Fixed an issue which allowed WE's to detach themselves from non-parents.
  • Fixed an issue that occurred when physics was not active before attaching
  • Added some forgotten const in WE (physics)
  • When attaching WE's the child doesn't get modified anymore. Alternative: notifyDetached() and notifyBeingAttached(this) —> the child does the work
Location:
code/branches/presentation/src/orxonox/objects/collisionshapes
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • code/branches/presentation/src/orxonox/objects/collisionshapes/CollisionShape.cc

    r2515 r2527  
    6262        // Detach from parent
    6363        if (this->isInitialized() && this->parent_)
    64             this->parent_->removeChildShape(this);
     64            this->parent_->detach(this);
    6565    }
    6666
     
    8787        CompoundCollisionShape* parent = dynamic_cast<CompoundCollisionShape*>(Synchronisable::getSynchronisable(this->parentID_));
    8888        if (parent)
    89             parent->addChildShape(this);
     89            parent->attach(this);
    9090    }
    9191
     
    9393    {
    9494        if (this->parent_)
    95             this->parent_->updateChildShape(this);
     95            this->parent_->updateAttachedShape(this);
    9696    }
    9797
  • code/branches/presentation/src/orxonox/objects/collisionshapes/CompoundCollisionShape.cc

    r2514 r2527  
    5555        {
    5656            // Delete all children
    57             for (std::map<CollisionShape*, btCollisionShape*>::iterator it = this->childShapes_.begin();
    58                 it != this->childShapes_.end(); ++it)
     57            for (std::map<CollisionShape*, btCollisionShape*>::iterator it = this->attachedShapes_.begin();
     58                it != this->attachedShapes_.end(); ++it)
    5959            {
    6060                // make sure that the child doesn't want to detach itself --> speedup because of the missing update
     
    7171        SUPER(CompoundCollisionShape, XMLPort, xmlelement, mode);
    7272        // Attached collision shapes
    73         XMLPortObject(CompoundCollisionShape, CollisionShape, "", addChildShape, getChildShape, xmlelement, mode);
     73        XMLPortObject(CompoundCollisionShape, CollisionShape, "", attach, detach, xmlelement, mode);
    7474    }
    7575
     
    8282    }
    8383
    84     void CompoundCollisionShape::addChildShape(CollisionShape* shape)
     84    void CompoundCollisionShape::attach(CollisionShape* shape)
    8585    {
    8686        if (!shape || static_cast<CollisionShape*>(this) == shape)
    8787            return;
    88         if (this->childShapes_.find(shape) != this->childShapes_.end())
     88        if (this->attachedShapes_.find(shape) != this->attachedShapes_.end())
    8989        {
    9090            CCOUT(2) << "Warning: Attaching a CollisionShape twice is not yet supported." << std::endl;
    9191            return;
    9292        }
    93         this->childShapes_[shape] = shape->getCollisionShape();
     93        this->attachedShapes_[shape] = shape->getCollisionShape();
    9494
    9595        if (shape->getCollisionShape())
     
    113113    }
    114114
    115     void CompoundCollisionShape::removeChildShape(CollisionShape* shape)
    116     {
    117         if (this->childShapes_.find(shape) != this->childShapes_.end())
     115    void CompoundCollisionShape::detach(CollisionShape* shape)
     116    {
     117        if (this->attachedShapes_.find(shape) != this->attachedShapes_.end())
    118118        {
    119119            shape->setParent(0, OBJECTID_UNKNOWN);
    120             this->childShapes_.erase(shape);
     120            this->attachedShapes_.erase(shape);
    121121            if (shape->getCollisionShape())
    122122                this->compoundShape_->removeChildShape(shape->getCollisionShape());
     
    124124            this->updatePublicShape();
    125125        }
    126     }
    127 
    128     void CompoundCollisionShape::removeAllChildShapes()
    129     {
    130         while (this->childShapes_.size() > 0)
    131             this->removeChildShape(this->childShapes_.begin()->first);
    132     }
    133 
    134     void CompoundCollisionShape::updateChildShape(CollisionShape* shape)
     126        else
     127            CCOUT(2) << "Warning: Cannot detach non child collision shape" << std::endl;
     128    }
     129
     130    void CompoundCollisionShape::detachAll()
     131    {
     132        while (this->attachedShapes_.size() > 0)
     133            this->detach(this->attachedShapes_.begin()->first);
     134    }
     135
     136    void CompoundCollisionShape::updateAttachedShape(CollisionShape* shape)
    135137    {
    136138        if (!shape)
    137139            return;
    138         std::map<CollisionShape*, btCollisionShape*>::iterator it = this->childShapes_.find(shape);
    139         if (it == this->childShapes_.end())
     140        std::map<CollisionShape*, btCollisionShape*>::iterator it = this->attachedShapes_.find(shape);
     141        if (it == this->attachedShapes_.end())
    140142        {
    141143            CCOUT(2) << "Warning: Cannot update child shape: Instance not a child." << std::endl;
     
    162164        bool bPrimitive = true;
    163165        bool bEmpty = true;
    164         for (std::map<CollisionShape*, btCollisionShape*>::const_iterator it = this->childShapes_.begin(); it != this->childShapes_.end(); ++it)
     166        for (std::map<CollisionShape*, btCollisionShape*>::const_iterator it = this->attachedShapes_.begin(); it != this->attachedShapes_.end(); ++it)
    165167        {
    166168            if (it->second)
     
    198200    {
    199201        if (this->parent_)
    200             this->parent_->updateChildShape(this);
     202            this->parent_->updateAttachedShape(this);
    201203        if (this->worldEntityParent_)
    202204            this->worldEntityParent_->notifyCollisionShapeChanged();
     
    209211    }
    210212
    211     CollisionShape* CompoundCollisionShape::getChildShape(unsigned int index) const
     213    CollisionShape* CompoundCollisionShape::getAttachedShape(unsigned int index) const
    212214    {
    213215        unsigned int i = 0;
    214         for (std::map<CollisionShape*, btCollisionShape*>::const_iterator it = this->childShapes_.begin(); it != this->childShapes_.end(); ++it)
     216        for (std::map<CollisionShape*, btCollisionShape*>::const_iterator it = this->attachedShapes_.begin(); it != this->attachedShapes_.end(); ++it)
    215217        {
    216218            if (i == index)
  • code/branches/presentation/src/orxonox/objects/collisionshapes/CompoundCollisionShape.h

    r2514 r2527  
    4646            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    4747
    48             void addChildShape(CollisionShape* shape);
    49             void removeChildShape(CollisionShape* shape);
    50             void removeAllChildShapes();
    51             CollisionShape* getChildShape(unsigned int index) const;
     48            void attach(CollisionShape* shape);
     49            void detach(CollisionShape* shape);
     50            void detachAll();
     51            CollisionShape* getAttachedShape(unsigned int index) const;
    5252
    53             void updateChildShape(CollisionShape* shape);
     53            void updateAttachedShape(CollisionShape* shape);
    5454
    5555            void setWorldEntityParent(WorldEntity* parent);
     
    6565
    6666            btCompoundShape* compoundShape_;
    67             std::map<CollisionShape*, btCollisionShape*> childShapes_;
     67            std::map<CollisionShape*, btCollisionShape*> attachedShapes_;
    6868            WorldEntity* worldEntityParent_;
    6969    };
Note: See TracChangeset for help on using the changeset viewer.