Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 2565


Ignore:
Timestamp:
Jan 4, 2009, 4:32:33 PM (16 years ago)
Author:
rgrieder
Message:

Added XML parameter "collisionResponse" in WE for Oli ;)

Location:
code/branches/presentation/src/orxonox/objects/worldentities
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/branches/presentation/src/orxonox/objects/worldentities/WorldEntity.cc

    r2563 r2565  
    9191        this->friction_       = 0.5;
    9292        this->bCollisionCallbackActive_ = false;
     93        this->bCollisionResponseActive_ = true;
    9394
    9495        this->registerVariables();
     
    139140
    140141        // Physics
    141         XMLPortParam(WorldEntity, "collisionType",  setCollisionTypeStr, getCollisionTypeStr, xmlelement, mode);
    142         XMLPortParam(WorldEntity, "mass",           setMass,             getMass,             xmlelement, mode);
    143         XMLPortParam(WorldEntity, "restitution",    setRestitution,      getRestitution,      xmlelement, mode);
    144         XMLPortParam(WorldEntity, "angularFactor",  setAngularFactor,    getAngularFactor,    xmlelement, mode);
    145         XMLPortParam(WorldEntity, "linearDamping",  setLinearDamping,    getLinearDamping,    xmlelement, mode);
    146         XMLPortParam(WorldEntity, "angularDamping", setAngularDamping,   getAngularDamping,   xmlelement, mode);
    147         XMLPortParam(WorldEntity, "friction",       setFriction,         getFriction,         xmlelement, mode);
     142        XMLPortParam(WorldEntity, "collisionType",     setCollisionTypeStr,  getCollisionTypeStr,  xmlelement, mode);
     143        XMLPortParam(WorldEntity, "collisionResponse", setCollisionResponse, hasCollisionResponse, xmlelement, mode);
     144        XMLPortParam(WorldEntity, "mass",              setMass,              getMass,              xmlelement, mode);
     145        XMLPortParam(WorldEntity, "restitution",       setRestitution,       getRestitution,       xmlelement, mode);
     146        XMLPortParam(WorldEntity, "angularFactor",     setAngularFactor,     getAngularFactor,     xmlelement, mode);
     147        XMLPortParam(WorldEntity, "linearDamping",     setLinearDamping,     getLinearDamping,     xmlelement, mode);
     148        XMLPortParam(WorldEntity, "angularDamping",    setAngularDamping,    getAngularDamping,    xmlelement, mode);
     149        XMLPortParam(WorldEntity, "friction",          setFriction,          getFriction,          xmlelement, mode);
    148150
    149151        // Other attached WorldEntities
     
    171173        registerVariable(this->bCollisionCallbackActive_,
    172174                                                variableDirection::toclient, new NetworkCallback<WorldEntity>(this, &WorldEntity::collisionCallbackActivityChanged));
     175        registerVariable(this->bCollisionResponseActive_,
     176                                                variableDirection::toclient, new NetworkCallback<WorldEntity>(this, &WorldEntity::collisionResponseActivityChanged));
    173177        registerVariable((int&)this->collisionTypeSynchronised_,
    174178                                                variableDirection::toclient, new NetworkCallback<WorldEntity>(this, &WorldEntity::collisionTypeChanged));
     
    253257    }
    254258
    255     //! Function is called to set the right flags in Bullet (if there is physics at all)
     259    //! Function sets whether Bullet should issue a callback on collisions
    256260    void WorldEntity::collisionCallbackActivityChanged()
    257261    {
    258262        if (this->hasPhysics())
    259263        {
    260             if (bCollisionCallbackActive_)
     264            if (this->bCollisionCallbackActive_)
    261265                this->physicalBody_->setCollisionFlags(this->physicalBody_->getCollisionFlags() |
    262266                    btCollisionObject::CF_CUSTOM_MATERIAL_CALLBACK);
     
    264268                this->physicalBody_->setCollisionFlags(this->physicalBody_->getCollisionFlags() &
    265269                    ~btCollisionObject::CF_CUSTOM_MATERIAL_CALLBACK);
     270        }
     271    }
     272
     273    //! Function sets whether Bullet should react itself to a collision
     274    void WorldEntity::collisionResponseActivityChanged()
     275    {
     276        if (this->hasPhysics())
     277        {
     278            if (this->bCollisionResponseActive_)
     279                this->physicalBody_->setCollisionFlags(this->physicalBody_->getCollisionFlags() &
     280                    ~btCollisionObject::CF_NO_CONTACT_RESPONSE);
     281            else
     282                this->physicalBody_->setCollisionFlags(this->physicalBody_->getCollisionFlags() |
     283                    btCollisionObject::CF_NO_CONTACT_RESPONSE);
    266284        }
    267285    }
     
    759777        internalSetPhysicsProps();
    760778        collisionCallbackActivityChanged();
     779        collisionResponseActivityChanged();
    761780        if (bReactivatePhysics)
    762781            activatePhysics();
  • code/branches/presentation/src/orxonox/objects/worldentities/WorldEntity.h

    r2562 r2565  
    343343            inline void disableCollisionCallback()
    344344                { this->bCollisionCallbackActive_ = false; this->collisionCallbackActivityChanged(); }
    345             //! Tells whether there could be a collision response via collidesAgainst(.)
     345            //! Tells whether there could be a collision callback via collidesAgainst(.)
    346346            inline bool isCollisionCallbackActive() const
    347347                { return this->bCollisionCallbackActive_; }
     348
     349            //! Enables or disables collision response (default is of course on)
     350            inline void setCollisionResponse(bool value)
     351                { this->bCollisionResponseActive_ = value; this->collisionResponseActivityChanged(); }
     352            //! Tells whether there could be a collision response
     353            inline bool hasCollisionResponse()
     354                { return this->bCollisionResponseActive_; }
    348355
    349356        protected:
     
    373380            void physicsActivityChanged();
    374381            void collisionCallbackActivityChanged();
     382            void collisionResponseActivityChanged();
    375383            //! Network callback workaround to call a function when the value changes.
    376384            inline void massChanged()
     
    408416            btScalar                     childrenMass_;                  //!< Sum of all the children's masses
    409417            bool                         bCollisionCallbackActive_;      //!< @see enableCollisionCallback
     418            bool                         bCollisionResponseActive_;      //!< Tells whether the object should respond to collisions
    410419    };
    411420
Note: See TracChangeset for help on using the changeset viewer.