Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Feb 28, 2015, 11:55:18 PM (10 years ago)
Author:
landauf
Message:

added bullet settings for CCD (continuous collision detection) to WorldEntity. initially I thought we need this to avoid the tunneling effect of projectiles at low FPS, but now it turns out that this gets also fixed if projectiles use dynamic physics. I still add the new settings to WorldEntity because we may still need them for very fast objects.

Location:
code/trunk/src/orxonox/worldentities
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/trunk/src/orxonox/worldentities/WorldEntity.cc

    r10274 r10288  
    9898        this->collisionType_             = None;
    9999        this->collisionTypeSynchronised_ = None;
    100         this->mass_           = 1.0f;
    101         this->childrenMass_   = 0;
     100        this->mass_                 = 1.0f;
     101        this->childrenMass_         = 0;
    102102        // Using bullet default values
    103         this->restitution_    = 0;
    104         this->angularFactor_  = 1;
    105         this->linearDamping_  = 0;
    106         this->angularDamping_ = 0;
    107         this->friction_       = 0.5;
     103        this->restitution_          = 0;
     104        this->angularFactor_        = 1;
     105        this->linearDamping_        = 0;
     106        this->angularDamping_       = 0;
     107        this->friction_             = 0.5;
     108        this->ccdMotionThreshold_   = 0.0;
     109        this->ccdSweptSphereRadius_ = 0.0;
    108110        this->bCollisionCallbackActive_ = false;
    109111        this->bCollisionResponseActive_ = true;
     
    198200        registerVariable(this->angularDamping_, VariableDirection::ToClient, new NetworkCallback<WorldEntity>(this, &WorldEntity::angularDampingChanged));
    199201        registerVariable(this->friction_,       VariableDirection::ToClient, new NetworkCallback<WorldEntity>(this, &WorldEntity::frictionChanged));
     202        registerVariable(this->ccdMotionThreshold_,
     203                                                VariableDirection::ToClient, new NetworkCallback<WorldEntity>(this, &WorldEntity::ccdMotionThresholdChanged));
     204        registerVariable(this->ccdSweptSphereRadius_,
     205                                                VariableDirection::ToClient, new NetworkCallback<WorldEntity>(this, &WorldEntity::ccdSweptSphereRadiusChanged));
    200206        registerVariable(this->bCollisionCallbackActive_,
    201207                                                VariableDirection::ToClient, new NetworkCallback<WorldEntity>(this, &WorldEntity::collisionCallbackActivityChanged));
     
    10031009            this->physicalBody_->setDamping(this->linearDamping_, this->angularDamping_);
    10041010            this->physicalBody_->setFriction(this->friction_);
     1011            this->physicalBody_->setCcdMotionThreshold(this->ccdMotionThreshold_);
     1012            this->physicalBody_->setCcdSweptSphereRadius(this->ccdSweptSphereRadius_);
    10051013        }
    10061014    }
  • code/trunk/src/orxonox/worldentities/WorldEntity.h

    r10216 r10288  
    355355                { return this->friction_; }
    356356
     357            /**
     358             * Sets the motion threshold for continuous collision detection (CCD). This should be activated if an object moves further in one tick than its own
     359             * size. This means that in one tick the object may be in front of a wall and in the next tick it will be behind the wall without ever triggering a
     360             * collision. CCD ensures that collisions are still detected. By default it is deactivated (threshold = 0) which is fine for slow or static
     361             * objects, but it should be set to a real value for fast moving objects (e.g. projectiles).
     362             *
     363             * A good value for the threshold is (diameter^2).
     364             *
     365             * @param ccdMotionThreshold CCD is enabled if the squared velocity of the object is > ccdMotionThreshold (default 0.0). 0.0 means deactivated.
     366             */
     367            inline void setCcdMotionThreshold(float ccdMotionThreshold)
     368                { this->ccdMotionThreshold_ = ccdMotionThreshold; internalSetPhysicsProps(); }
     369            //! Returns the currently used motion threshold for CCD (0 means CCD is deactivated).
     370            inline float getCcdMotionThreshold() const
     371                { return this->ccdMotionThreshold_; }
     372
     373            /**
     374             * Sets the radius of the sphere which is used for continuous collision detection (CCD). The sphere should be embedded inside the objects collision
     375             * shape, preferably smaller. @see setCcdMotionThreshold for more information about CCD.
     376             *
     377             * A good value for the radius is (diameter/5).
     378             *
     379             * @param ccdSweptSphereRadius The diameter of the sphere which is used for CCD (default 0.0).
     380             */
     381            inline void setCcdSweptSphereRadius(float ccdSweptSphereRadius)
     382                { this->ccdSweptSphereRadius_ = ccdSweptSphereRadius; internalSetPhysicsProps(); }
     383            //! Returns the currently used radius of the sphere for CCD.
     384            inline float getCcdSweptSphereRadius() const
     385                { return this->ccdSweptSphereRadius_; }
     386
    357387            void attachCollisionShape(CollisionShape* shape);
    358388            void detachCollisionShape(CollisionShape* shape);
     
    438468            inline void frictionChanged()
    439469                { this->setFriction(this->friction_); }
     470            //! Network callback workaround to call a function when the value changes.
     471            inline void ccdMotionThresholdChanged()
     472                { this->setCcdMotionThreshold(this->ccdMotionThreshold_); }
     473            //! Network callback workaround to call a function when the value changes.
     474            inline void ccdSweptSphereRadiusChanged()
     475                { this->setCcdSweptSphereRadius(this->ccdSweptSphereRadius_); }
    440476
    441477            CollisionType                collisionType_;                 //!< @see setCollisionType
     
    454490            btScalar                     friction_;                      //!< @see setFriction
    455491            btScalar                     childrenMass_;                  //!< Sum of all the children's masses
     492            btScalar                     ccdMotionThreshold_;            //!< @see setCcdMotionThreshold
     493            btScalar                     ccdSweptSphereRadius_;          //!< @see setCcdSweptSphereRadius
    456494            bool                         bCollisionCallbackActive_;      //!< @see enableCollisionCallback
    457495            bool                         bCollisionResponseActive_;      //!< Tells whether the object should respond to collisions
Note: See TracChangeset for help on using the changeset viewer.