diff --git a/Demos/SoftDemo/SoftDemo.cpp b/Demos/SoftDemo/SoftDemo.cpp index aac2826b2..bc2223000 100644 --- a/Demos/SoftDemo/SoftDemo.cpp +++ b/Demos/SoftDemo/SoftDemo.cpp @@ -252,12 +252,6 @@ void SoftDemo::clientMoveAndDisplay() #endif - /* soft bodies collision detection */ - for(int ib=0;ibupdateAabb(dt); - } /* soft bodies simulation */ for(int ib=0;ibgetDispatchInfo().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)); diff --git a/src/BulletDynamics/SoftBody/btSoftBody.cpp b/src/BulletDynamics/SoftBody/btSoftBody.cpp index 2ade5cd57..e981d6d0f 100644 --- a/src/BulletDynamics/SoftBody/btSoftBody.cpp +++ b/src/BulletDynamics/SoftBody/btSoftBody.cpp @@ -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();igetCollisionShape(); - btConvexShape* csh=static_cast(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(dstgetCollisionShape(); + btAssert(shp->isConvex()); + btConvexShape* csh=static_cast(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(dst0) + { + 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(); + } + } +} diff --git a/src/BulletDynamics/SoftBody/btSoftBody.h b/src/BulletDynamics/SoftBody/btSoftBody.h index 6c980d675..f36d969ca 100644 --- a/src/BulletDynamics/SoftBody/btSoftBody.h +++ b/src/BulletDynamics/SoftBody/btSoftBody.h @@ -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);