Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 15, 2008, 4:33:50 PM (15 years ago)
Author:
rgrieder
Message:

Added callback for collisions. Every WorldEntity that collides against another will be called with the following function:
virtual bool collidesAgainst(WorldEntity* otherObject, btManifoldPoint& contactPoint);
btManifoldPoint is from Bullet and tells you more about the contact point, like position.

Per default, the callback is disabled. Enable it with this→enableCollisionCallback(), for instance in your derived class constructor.
Note that if you activate the callback for e.g. SpaceShips, but not for MovableEntities, then collidesAgainst will only be called in the SpaceShip. This could be changed however, just ask me.

File:
1 edited

Legend:

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

    r2465 r2466  
    8585        this->angularDamping_ = 0;
    8686        this->friction_       = 0.5;
     87        this->bCollisionCallbackActive_ = false;
    8788
    8889        this->registerVariables();
     
    144145        registerVariable(this->getScale3D(),    variableDirection::toclient, new NetworkCallback<WorldEntity>(this, &WorldEntity::scaleChanged));
    145146
    146         registerVariable((int&)this->collisionTypeSynchronised_,
    147                                                 variableDirection::toclient, new NetworkCallback<WorldEntity>(this, &WorldEntity::collisionTypeChanged));
     147        // Physics stuff
    148148        registerVariable(this->mass_,           variableDirection::toclient, new NetworkCallback<WorldEntity>(this, &WorldEntity::massChanged));
    149149        registerVariable(this->restitution_,    variableDirection::toclient, new NetworkCallback<WorldEntity>(this, &WorldEntity::restitutionChanged));
     
    152152        registerVariable(this->angularDamping_, variableDirection::toclient, new NetworkCallback<WorldEntity>(this, &WorldEntity::angularDampingChanged));
    153153        registerVariable(this->friction_,       variableDirection::toclient, new NetworkCallback<WorldEntity>(this, &WorldEntity::frictionChanged));
     154        registerVariable(this->bCollisionCallbackActive_,
     155                                                variableDirection::toclient, new NetworkCallback<WorldEntity>(this, &WorldEntity::collisionCallbackActivityChanged));
     156        registerVariable((int&)this->collisionTypeSynchronised_,
     157                                                variableDirection::toclient, new NetworkCallback<WorldEntity>(this, &WorldEntity::collisionTypeChanged));
    154158        registerVariable(this->bPhysicsActiveSynchronised_,
    155159                                                variableDirection::toclient, new NetworkCallback<WorldEntity>(this, &WorldEntity::physicsActivityChanged));
    156160
     161        // Attach to parent if necessary
    157162        registerVariable(this->parentID_,       variableDirection::toclient, new NetworkCallback<WorldEntity>(this, &WorldEntity::parentChanged));
    158163    }
     
    192197        else
    193198            this->deactivatePhysics();
     199    }
     200
     201    void WorldEntity::collisionCallbackActivityChanged()
     202    {
     203        if (this->hasPhysics())
     204        {
     205            if (bCollisionCallbackActive_)
     206                this->physicalBody_->setCollisionFlags(this->physicalBody_->getCollisionFlags() |
     207                    btCollisionObject::CF_CUSTOM_MATERIAL_CALLBACK);
     208            else
     209                this->physicalBody_->setCollisionFlags(this->physicalBody_->getCollisionFlags() &
     210                    !btCollisionObject::CF_CUSTOM_MATERIAL_CALLBACK);
     211        }
    194212    }
    195213
     
    525543        recalculateMassProps();
    526544        resetPhysicsProps();
     545        collisionCallbackActivityChanged();
    527546        activatePhysics();
    528547    }
Note: See TracChangeset for help on using the changeset viewer.