[Orxonox-commit 5628] r10288 - code/trunk/src/orxonox/worldentities
landauf at orxonox.net
landauf at orxonox.net
Sat Feb 28 23:55:18 CET 2015
Author: landauf
Date: 2015-02-28 23:55:18 +0100 (Sat, 28 Feb 2015)
New Revision: 10288
Modified:
code/trunk/src/orxonox/worldentities/WorldEntity.cc
code/trunk/src/orxonox/worldentities/WorldEntity.h
Log:
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.
Modified: code/trunk/src/orxonox/worldentities/WorldEntity.cc
===================================================================
--- code/trunk/src/orxonox/worldentities/WorldEntity.cc 2015-02-28 22:50:41 UTC (rev 10287)
+++ code/trunk/src/orxonox/worldentities/WorldEntity.cc 2015-02-28 22:55:18 UTC (rev 10288)
@@ -97,14 +97,16 @@
this->collisionShape_->setWorldEntityOwner(this);
this->collisionType_ = None;
this->collisionTypeSynchronised_ = None;
- this->mass_ = 1.0f;
- this->childrenMass_ = 0;
+ this->mass_ = 1.0f;
+ this->childrenMass_ = 0;
// Using bullet default values
- this->restitution_ = 0;
- this->angularFactor_ = 1;
- this->linearDamping_ = 0;
- this->angularDamping_ = 0;
- this->friction_ = 0.5;
+ this->restitution_ = 0;
+ this->angularFactor_ = 1;
+ this->linearDamping_ = 0;
+ this->angularDamping_ = 0;
+ this->friction_ = 0.5;
+ this->ccdMotionThreshold_ = 0.0;
+ this->ccdSweptSphereRadius_ = 0.0;
this->bCollisionCallbackActive_ = false;
this->bCollisionResponseActive_ = true;
@@ -197,6 +199,10 @@
registerVariable(this->linearDamping_, VariableDirection::ToClient, new NetworkCallback<WorldEntity>(this, &WorldEntity::linearDampingChanged));
registerVariable(this->angularDamping_, VariableDirection::ToClient, new NetworkCallback<WorldEntity>(this, &WorldEntity::angularDampingChanged));
registerVariable(this->friction_, VariableDirection::ToClient, new NetworkCallback<WorldEntity>(this, &WorldEntity::frictionChanged));
+ registerVariable(this->ccdMotionThreshold_,
+ VariableDirection::ToClient, new NetworkCallback<WorldEntity>(this, &WorldEntity::ccdMotionThresholdChanged));
+ registerVariable(this->ccdSweptSphereRadius_,
+ VariableDirection::ToClient, new NetworkCallback<WorldEntity>(this, &WorldEntity::ccdSweptSphereRadiusChanged));
registerVariable(this->bCollisionCallbackActive_,
VariableDirection::ToClient, new NetworkCallback<WorldEntity>(this, &WorldEntity::collisionCallbackActivityChanged));
registerVariable(this->bCollisionResponseActive_,
@@ -1002,6 +1008,8 @@
this->physicalBody_->setAngularFactor(this->angularFactor_);
this->physicalBody_->setDamping(this->linearDamping_, this->angularDamping_);
this->physicalBody_->setFriction(this->friction_);
+ this->physicalBody_->setCcdMotionThreshold(this->ccdMotionThreshold_);
+ this->physicalBody_->setCcdSweptSphereRadius(this->ccdSweptSphereRadius_);
}
}
}
Modified: code/trunk/src/orxonox/worldentities/WorldEntity.h
===================================================================
--- code/trunk/src/orxonox/worldentities/WorldEntity.h 2015-02-28 22:50:41 UTC (rev 10287)
+++ code/trunk/src/orxonox/worldentities/WorldEntity.h 2015-02-28 22:55:18 UTC (rev 10288)
@@ -354,6 +354,36 @@
inline float getFriction() const
{ return this->friction_; }
+ /**
+ * Sets the motion threshold for continuous collision detection (CCD). This should be activated if an object moves further in one tick than its own
+ * 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
+ * collision. CCD ensures that collisions are still detected. By default it is deactivated (threshold = 0) which is fine for slow or static
+ * objects, but it should be set to a real value for fast moving objects (e.g. projectiles).
+ *
+ * A good value for the threshold is (diameter^2).
+ *
+ * @param ccdMotionThreshold CCD is enabled if the squared velocity of the object is > ccdMotionThreshold (default 0.0). 0.0 means deactivated.
+ */
+ inline void setCcdMotionThreshold(float ccdMotionThreshold)
+ { this->ccdMotionThreshold_ = ccdMotionThreshold; internalSetPhysicsProps(); }
+ //! Returns the currently used motion threshold for CCD (0 means CCD is deactivated).
+ inline float getCcdMotionThreshold() const
+ { return this->ccdMotionThreshold_; }
+
+ /**
+ * Sets the radius of the sphere which is used for continuous collision detection (CCD). The sphere should be embedded inside the objects collision
+ * shape, preferably smaller. @see setCcdMotionThreshold for more information about CCD.
+ *
+ * A good value for the radius is (diameter/5).
+ *
+ * @param ccdSweptSphereRadius The diameter of the sphere which is used for CCD (default 0.0).
+ */
+ inline void setCcdSweptSphereRadius(float ccdSweptSphereRadius)
+ { this->ccdSweptSphereRadius_ = ccdSweptSphereRadius; internalSetPhysicsProps(); }
+ //! Returns the currently used radius of the sphere for CCD.
+ inline float getCcdSweptSphereRadius() const
+ { return this->ccdSweptSphereRadius_; }
+
void attachCollisionShape(CollisionShape* shape);
void detachCollisionShape(CollisionShape* shape);
CollisionShape* getAttachedCollisionShape(unsigned int index);
@@ -437,6 +467,12 @@
//! Network callback workaround to call a function when the value changes.
inline void frictionChanged()
{ this->setFriction(this->friction_); }
+ //! Network callback workaround to call a function when the value changes.
+ inline void ccdMotionThresholdChanged()
+ { this->setCcdMotionThreshold(this->ccdMotionThreshold_); }
+ //! Network callback workaround to call a function when the value changes.
+ inline void ccdSweptSphereRadiusChanged()
+ { this->setCcdSweptSphereRadius(this->ccdSweptSphereRadius_); }
CollisionType collisionType_; //!< @see setCollisionType
CollisionType collisionTypeSynchronised_; //!< Network synchronised variable for collisionType_
@@ -453,6 +489,8 @@
btScalar angularDamping_; //!< @see setAngularDamping
btScalar friction_; //!< @see setFriction
btScalar childrenMass_; //!< Sum of all the children's masses
+ btScalar ccdMotionThreshold_; //!< @see setCcdMotionThreshold
+ btScalar ccdSweptSphereRadius_; //!< @see setCcdSweptSphereRadius
bool bCollisionCallbackActive_; //!< @see enableCollisionCallback
bool bCollisionResponseActive_; //!< Tells whether the object should respond to collisions
};
More information about the Orxonox-commit
mailing list