Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 21, 2008, 2:44:00 PM (17 years ago)
Author:
rgrieder
Message:

Resolved four issues with the collision shapes:

  • NetworkCallback will of course not call functions virtually
  • CompoundCollisionShapes with a WorldEntity parent don't have to attach themselves when synchronised
  • Just in case: When changing a CollisionShape, the old gets destroyed AFTER everything has been updated
  • CompoundCollisionShapes with a WorldEntity parent now update both the WE and the CompoundCollisionShape when something changes

Other changes

  • Also replaced some redundant code while at it (updating the shapes was done individually)
  • Like in WE, the CompoundCollisionShape deletes all its children when being destroyed itself. This requires in WE that the children get detached before the CompoundCollisionShape gets deleted.
File:
1 edited

Legend:

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

    r2469 r2514  
    4242namespace orxonox
    4343{
    44     CreateFactory(CollisionShape);
    45 
    4644    CollisionShape::CollisionShape(BaseObject* creator)
    4745        : BaseObject(creator)
     
    6260    CollisionShape::~CollisionShape()
    6361    {
     62        // Detach from parent
     63        if (this->isInitialized() && this->parent_)
     64            this->parent_->removeChildShape(this);
    6465    }
    6566
     
    7980    void CollisionShape::registerVariables()
    8081    {
    81         registerVariable(this->parentID_, variableDirection::toclient, new NetworkCallback<CollisionShape>(this, &CollisionShape::parentChanged));
     82        registerVariable(this->parentID_, variableDirection::toclient, new NetworkCallback<CollisionShape>(this, &CollisionShape::parentChangedCallback));
    8283    }
    8384
    8485    void CollisionShape::parentChanged()
    8586    {
    86         Synchronisable* synchronisable = Synchronisable::getSynchronisable(this->parentID_);
    87         CompoundCollisionShape* CCSparent = dynamic_cast<CompoundCollisionShape*>(synchronisable);
    88         if (CCSparent)
    89             CCSparent->addChildShape(this);
    90         else
    91         {
    92             WorldEntity* WEparent = dynamic_cast<WorldEntity*>(synchronisable);
    93             if (WEparent)
    94                 WEparent->attachCollisionShape(this);
    95         }
     87        CompoundCollisionShape* parent = dynamic_cast<CompoundCollisionShape*>(Synchronisable::getSynchronisable(this->parentID_));
     88        if (parent)
     89            parent->addChildShape(this);
    9690    }
    9791
     
    118112    }
    119113
     114    void CollisionShape::updateShape()
     115    {
     116        btCollisionShape* oldShape = this->collisionShape_;
     117        this->collisionShape_ = this->createNewShape();
     118        // When we recreate the shape, we have to inform the parent about this to update the shape
     119        this->updateParent();
     120        if (oldShape)
     121            delete oldShape;
     122    }
     123
    120124    void CollisionShape::calculateLocalInertia(btScalar mass, btVector3& inertia) const
    121125    {
Note: See TracChangeset for help on using the changeset viewer.