Improve damping formula in btRigidBody::applyDamping
Thanks to sparkprime, see http://code.google.com/p/bullet/issues/detail?id=74 Fixed btCompoundShape/btCapsuleShape/btGImpactShape for missing m_shapeType, and added an assert in DemoApplication::localCreateRigidBody for invalid shape types.
This commit is contained in:
@@ -773,6 +773,8 @@ void DemoApplication::mouseMotionFunc(int x,int y)
|
||||
|
||||
btRigidBody* DemoApplication::localCreateRigidBody(float mass, const btTransform& startTransform,btCollisionShape* shape)
|
||||
{
|
||||
btAssert(shape->getShapeType() != INVALID_SHAPE_PROXYTYPE);
|
||||
|
||||
//rigidbody is dynamic if and only if mass is non zero, otherwise static
|
||||
bool isDynamic = (mass != 0.f);
|
||||
|
||||
|
||||
@@ -105,6 +105,7 @@ protected:
|
||||
public:
|
||||
btGImpactShapeInterface()
|
||||
{
|
||||
m_shapeType = GIMPACT_SHAPE_PROXYTYPE;
|
||||
m_localAABB.invalidate();
|
||||
m_needs_update = true;
|
||||
localScaling.setValue(1.f,1.f,1.f);
|
||||
@@ -150,10 +151,7 @@ public:
|
||||
}
|
||||
|
||||
|
||||
virtual int getShapeType() const
|
||||
{
|
||||
return GIMPACT_SHAPE_PROXYTYPE;
|
||||
}
|
||||
|
||||
|
||||
/*!
|
||||
\post You must call updateBound() for update the box set.
|
||||
|
||||
@@ -21,6 +21,7 @@ subject to the following restrictions:
|
||||
|
||||
btCapsuleShape::btCapsuleShape(btScalar radius, btScalar height) : btConvexInternalShape ()
|
||||
{
|
||||
m_shapeType = CAPSULE_SHAPE_PROXYTYPE;
|
||||
m_upAxis = 1;
|
||||
m_implicitShapeDimensions.setValue(radius,0.5f*height,radius);
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ m_collisionMargin(btScalar(0.)),
|
||||
m_localScaling(btScalar(1.),btScalar(1.),btScalar(1.)),
|
||||
m_dynamicAabbTree(0)
|
||||
{
|
||||
m_shapeType = COMPOUND_SHAPE_PROXYTYPE;
|
||||
void* mem = btAlignedAlloc(sizeof(btDbvt),16);
|
||||
m_dynamicAabbTree = new(mem) btDbvt();
|
||||
btAssert(mem==m_dynamicAabbTree);
|
||||
|
||||
@@ -143,8 +143,17 @@ void btRigidBody::setDamping(btScalar lin_damping, btScalar ang_damping)
|
||||
///applyDamping damps the velocity, using the given m_linearDamping and m_angularDamping
|
||||
void btRigidBody::applyDamping(btScalar timeStep)
|
||||
{
|
||||
//On new damping: see discussion/issue report here: http://code.google.com/p/bullet/issues/detail?id=74
|
||||
//todo: do some performance comparisons (but other parts of the engine are probably bottleneck anyway
|
||||
|
||||
//#define USE_OLD_DAMPING_METHOD 1
|
||||
#ifdef USE_OLD_DAMPING_METHOD
|
||||
m_linearVelocity *= GEN_clamped((btScalar(1.) - timeStep * m_linearDamping), (btScalar)btScalar(0.0), (btScalar)btScalar(1.0));
|
||||
m_angularVelocity *= GEN_clamped((btScalar(1.) - timeStep * m_angularDamping), (btScalar)btScalar(0.0), (btScalar)btScalar(1.0));
|
||||
#else
|
||||
m_linearVelocity *= btPow(btScalar(1)-m_linearDamping, timeStep);
|
||||
m_angularVelocity *= btPow(btScalar(1)-m_angularDamping, timeStep);
|
||||
#endif
|
||||
|
||||
if (m_additionalDamping)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user