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

@@ -71,8 +71,8 @@ btSoftBody::btSoftBody(btSoftBody::btSoftBodyWorldInfo& worldInfo,int node_count
n.m_im = n.m_im>0?1/n.m_im:0;
}
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));
///register to the broadphase
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));
}
@@ -80,8 +80,8 @@ btSoftBody::btSoftBody(btSoftBody::btSoftBodyWorldInfo& worldInfo,int node_count
///destructor
btSoftBody::~btSoftBody()
{
//remove from broadphase
m_worldInfo.m_broadphase->destroyProxy(getBroadphaseHandle(),m_worldInfo.m_dispatcher);
//remove from broadphase
m_worldInfo.m_broadphase->destroyProxy(getBroadphaseHandle(),m_worldInfo.m_dispatcher);
///for now, delete the internal shape
delete m_softBodyCollisionShape;
@@ -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);
}
}
@@ -1228,30 +1231,53 @@ void btSoftBody::Step(btScalar dt)
}
//
bool btSoftBody::CheckContact( const btVector3& x,
btSoftBody::sCti& cti)
{
btScalar maxdepth=0;
btGjkEpaSolver2::sResults res;
for(int i=0,ni=m_overlappingRigidBodies.size();i<ni;++i)
{
btVector3 nrm;
btRigidBody* prb=btRigidBody::upcast(m_overlappingRigidBodies[i]);
btCollisionShape* shp=prb->getCollisionShape();
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;
btVector3 wit=x-nrm*dst;
if(dst<maxdepth)
{
maxdepth = dst;
cti.m_body = prb;
cti.m_normal = nrm;
cti.m_offset = -dot(cti.m_normal,wit);
}
}
return(maxdepth<0);
}
//
bool btSoftBody::CheckContact( const btVector3& x,
btSoftBody::sCti& cti)
{
btScalar maxdepth=0;
btGjkEpaSolver2::sResults res;
for(int i=0,ni=m_overlappingRigidBodies.size();i<ni;++i)
{
btVector3 nrm;
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;
btVector3 wit=x-nrm*dst;
if(dst<maxdepth)
{
maxdepth = dst;
cti.m_body = prb;
cti.m_normal = nrm;
cti.m_offset = -dot(cti.m_normal,wit);
}
}
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;
};
@@ -93,7 +94,7 @@ struct btSoftBody : public btCollisionObject
//??
}
//
//
bool CheckContact( const btVector3& x, btSoftBody::sCti& cti);
////
@@ -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);