some more fixes for btSoftBody:

+ use btBroadphaseProxy::AllFilter to collide with static and dynamic rigidbodies in broadphase
+ enlarge aabb for softbody in broadphase, otherwise misses collisions (deformation is not updated in-time?)
This commit is contained in:
erwin.coumans
2008-04-06 08:22:46 +00:00
parent a3c8bb172a
commit ed3e909282
3 changed files with 66 additions and 47 deletions

View File

@@ -252,12 +252,6 @@ void SoftDemo::clientMoveAndDisplay()
#endif
/* soft bodies collision detection */
for(int ib=0;ib<m_softbodies.size();++ib)
{
btSoftBody* psb=m_softbodies[ib];
// psb->updateAabb(dt);
}
/* soft bodies simulation */
for(int ib=0;ib<m_softbodies.size();++ib)
@@ -769,7 +763,7 @@ static void Init_TorusMatch(SoftDemo* pdemo)
}
static unsigned current_demo=0;
static unsigned current_demo=1;
void SoftDemo::clientResetScene()
{
@@ -818,6 +812,7 @@ void SoftDemo::clientResetScene()
m_softBodyWorldInfo.water_density = 0;
m_softBodyWorldInfo.water_offset = 0;
m_softBodyWorldInfo.water_normal = btVector3(0,0,0);
m_softBodyWorldInfo.m_gravity.setValue(0,-10,0);
m_autocam = false;
@@ -921,6 +916,8 @@ void SoftDemo::initPhysics()
m_dynamicsWorld->getDispatchInfo().m_enableSPU = true;
m_dynamicsWorld->setGravity(btVector3(0,-10,0));
m_softBodyWorldInfo.m_gravity.setValue(0,-10,0);
@@ -929,7 +926,7 @@ void SoftDemo::initPhysics()
btTransform tr;
tr.setIdentity();
tr.setOrigin(btVector3(0,-20,0));
tr.setOrigin(btVector3(0,-12,0));

View File

@@ -72,7 +72,7 @@ btSoftBody::btSoftBody(btSoftBody::btSoftBodyWorldInfo& worldInfo,int node_count
}
updateTransform();
///register to the broadphase
setBroadphaseHandle( m_worldInfo.m_broadphase->createProxy(m_bounds[0],m_bounds[1],SOFTBODY_SHAPE_PROXYTYPE,this,1,1,m_worldInfo.m_dispatcher,0));
setBroadphaseHandle( m_worldInfo.m_broadphase->createProxy(m_bounds[0],m_bounds[1],SOFTBODY_SHAPE_PROXYTYPE,this,btBroadphaseProxy::DefaultFilter,btBroadphaseProxy::AllFilter,m_worldInfo.m_dispatcher,0));
}
@@ -124,7 +124,10 @@ void btSoftBody::updateBounds()
if (getBroadphaseHandle())
{
m_worldInfo.m_broadphase->setAabb(getBroadphaseHandle(),m_bounds[0],m_bounds[1],m_worldInfo.m_dispatcher);
///todo: figure out how much larger the aabb needs to be, based on motion?
btVector3 aabbMin = m_bounds[0]-btVector3(1,1,1);
btVector3 aabbMax = m_bounds[1]+btVector3(1,1,1);
m_worldInfo.m_broadphase->setAabb(getBroadphaseHandle(),aabbMin,aabbMax,m_worldInfo.m_dispatcher);
}
}
@@ -1240,7 +1243,9 @@ bool btSoftBody::CheckContact( const btVector3& x,
btRigidBody* prb=btRigidBody::upcast(m_overlappingRigidBodies[i]);
btCollisionShape* shp=prb->getCollisionShape();
btAssert(shp->isConvex());
btConvexShape* csh=static_cast<btConvexShape*>(shp);
const btTransform& wtr=prb->getWorldTransform();
btScalar dst=m_worldInfo.m_sparsesdf.Evaluate(wtr.invXform(x),csh,nrm);
nrm=wtr.getBasis()*nrm;
@@ -1255,3 +1260,24 @@ bool btSoftBody::CheckContact( const btVector3& x,
}
return(maxdepth<0);
}
//
void btSoftBody::EvaluateMedium( const btVector3& x,
btSoftBody::sMedium& medium)
{
medium.m_velocity = btVector3(0,0,0);
medium.m_pressure = 0;
medium.m_density = m_worldInfo.air_density;
if(m_worldInfo.water_density>0)
{
const btScalar depth=-(dot(x,m_worldInfo.water_normal)+m_worldInfo.water_offset);
if(depth>0)
{
medium.m_density = m_worldInfo.water_density;
medium.m_pressure = depth *
m_worldInfo.water_density *
m_worldInfo.m_gravity.length();
}
}
}

View File

@@ -61,6 +61,7 @@ struct btSoftBody : public btCollisionObject
btVector3 water_normal;
btBroadphaseInterface* m_broadphase;
btCollisionDispatcher* m_dispatcher;
btVector3 m_gravity;
btSparseSdf<3> m_sparsesdf;
};
@@ -109,12 +110,7 @@ struct btSoftBody : public btCollisionObject
btScalar m_density; /* Density */
};
virtual void EvaluateMedium( const btVector3& /*position*/, sMedium& medium)
{
medium.m_velocity=btVector3(0,0,0);
medium.m_pressure=0;
medium.m_density=0;
}
virtual void EvaluateMedium( const btVector3& /*position*/, sMedium& medium);