Apple contribution for OSX SSE and iOS NEON optimizations unit tests, thanks to Jordan Hubbard, Ian Ollmann and Hristo Hristov.
For OSX: cd build ./premake_osx xcode4 for iOS: cd build ./ios_build.sh ./ios_run.sh Also integrated the branches/StackAllocation to make it easier to multi-thread collision detection in the near future. It avoids changing the btCollisionObject while performing collision detection. As this is a large patch, some stuff might be temporarily broken, I'll keep an eye out on issues.
This commit is contained in:
@@ -130,9 +130,9 @@ void btDefaultSoftBodySolver::processCollision( btSoftBody* softBody, btSoftBody
|
||||
}
|
||||
|
||||
// For the default solver just leave the soft body to do its collision processing
|
||||
void btDefaultSoftBodySolver::processCollision( btSoftBody *softBody, btCollisionObject* collisionObject )
|
||||
void btDefaultSoftBodySolver::processCollision( btSoftBody *softBody, const btCollisionObjectWrapper* collisionObjectWrap )
|
||||
{
|
||||
softBody->defaultCollisionHandler( collisionObject );
|
||||
softBody->defaultCollisionHandler( collisionObjectWrap );
|
||||
} // btDefaultSoftBodySolver::processCollision
|
||||
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ subject to the following restrictions:
|
||||
|
||||
#include "BulletSoftBody/btSoftBodySolvers.h"
|
||||
#include "btSoftBodySolverVertexBuffer.h"
|
||||
|
||||
struct btCollisionObjectWrapper;
|
||||
|
||||
class btDefaultSoftBodySolver : public btSoftBodySolver
|
||||
{
|
||||
@@ -54,7 +54,7 @@ public:
|
||||
|
||||
virtual void copySoftBodyToVertexBuffer( const btSoftBody *const softBody, btVertexBufferDescriptor *vertexBuffer );
|
||||
|
||||
virtual void processCollision( btSoftBody *, btCollisionObject* );
|
||||
virtual void processCollision( btSoftBody *, const btCollisionObjectWrapper* );
|
||||
|
||||
virtual void processCollision( btSoftBody*, btSoftBody* );
|
||||
|
||||
|
||||
@@ -105,7 +105,7 @@ void btSoftBody::initDefaults()
|
||||
/* Collision shape */
|
||||
///for now, create a collision shape internally
|
||||
m_collisionShape = new btSoftBodyCollisionShape(this);
|
||||
m_collisionShape->setMargin(0.25);
|
||||
m_collisionShape->setMargin(0.25f);
|
||||
|
||||
m_initialWorldTransform.setIdentity();
|
||||
|
||||
@@ -1388,12 +1388,12 @@ void btSoftBody::refine(ImplicitFn* ifn,btScalar accurary,bool cut)
|
||||
m=mc*f;
|
||||
}
|
||||
else
|
||||
{ a.m_im/=0.5;m=1/a.m_im; }
|
||||
{ a.m_im/=0.5f;m=1/a.m_im; }
|
||||
}
|
||||
else
|
||||
{
|
||||
if(b.m_im>0)
|
||||
{ b.m_im/=0.5;m=1/b.m_im; }
|
||||
{ b.m_im/=0.5f;m=1/b.m_im; }
|
||||
else
|
||||
m=0;
|
||||
}
|
||||
@@ -1473,7 +1473,7 @@ void btSoftBody::refine(ImplicitFn* ifn,btScalar accurary,bool cut)
|
||||
{
|
||||
const btVector3 v=m_nodes[i].m_v;
|
||||
btScalar m=getMass(i);
|
||||
if(m>0) { m*=0.5;m_nodes[i].m_im/=0.5; }
|
||||
if(m>0) { m*=0.5f;m_nodes[i].m_im/=0.5f; }
|
||||
appendNode(x,m);
|
||||
cnodes[i]=m_nodes.size()-1;
|
||||
m_nodes[cnodes[i]].m_v=v;
|
||||
@@ -2171,15 +2171,18 @@ btVector3 btSoftBody::evaluateCom() const
|
||||
}
|
||||
|
||||
//
|
||||
bool btSoftBody::checkContact( btCollisionObject* colObj,
|
||||
bool btSoftBody::checkContact( const btCollisionObjectWrapper* colObjWrap,
|
||||
const btVector3& x,
|
||||
btScalar margin,
|
||||
btSoftBody::sCti& cti) const
|
||||
{
|
||||
btVector3 nrm;
|
||||
btCollisionShape *shp = colObj->getCollisionShape();
|
||||
btRigidBody *tmpRigid = btRigidBody::upcast(colObj);
|
||||
const btTransform &wtr = tmpRigid ? tmpRigid->getWorldTransform() : colObj->getWorldTransform();
|
||||
const btCollisionShape *shp = colObjWrap->getCollisionShape();
|
||||
const btRigidBody *tmpRigid = btRigidBody::upcast(colObjWrap->getCollisionObject());
|
||||
//const btTransform &wtr = tmpRigid ? tmpRigid->getWorldTransform() : colObjWrap->getWorldTransform();
|
||||
const btTransform &wtr = colObjWrap->getWorldTransform();
|
||||
//todo: check which transform is needed here
|
||||
|
||||
btScalar dst =
|
||||
m_worldInfo->m_sparsesdf.Evaluate(
|
||||
wtr.invXform(x),
|
||||
@@ -2188,7 +2191,7 @@ bool btSoftBody::checkContact( btCollisionObject* colObj,
|
||||
margin);
|
||||
if(dst<0)
|
||||
{
|
||||
cti.m_colObj = colObj;
|
||||
cti.m_colObj = colObjWrap->getCollisionObject();
|
||||
cti.m_normal = wtr.getBasis()*nrm;
|
||||
cti.m_offset = -btDot( cti.m_normal, x - cti.m_normal * dst );
|
||||
return(true);
|
||||
@@ -2910,7 +2913,7 @@ void btSoftBody::PSolve_RContacts(btSoftBody* psb, btScalar kst, btScalar ti)
|
||||
{
|
||||
const RContact& c = psb->m_rcontacts[i];
|
||||
const sCti& cti = c.m_cti;
|
||||
btRigidBody* tmpRigid = btRigidBody::upcast(cti.m_colObj);
|
||||
btRigidBody* tmpRigid = (btRigidBody*)btRigidBody::upcast(cti.m_colObj);
|
||||
|
||||
const btVector3 va = tmpRigid ? tmpRigid->getVelocityInLocalPoint(c.m_c1)*dt : btVector3(0,0,0);
|
||||
const btVector3 vb = c.m_node->m_x-c.m_node->m_q;
|
||||
@@ -3031,7 +3034,7 @@ btSoftBody::vsolver_t btSoftBody::getSolver(eVSolver::_ solver)
|
||||
}
|
||||
|
||||
//
|
||||
void btSoftBody::defaultCollisionHandler(btCollisionObject* pco)
|
||||
void btSoftBody::defaultCollisionHandler(const btCollisionObjectWrapper* pcoWrap)
|
||||
{
|
||||
|
||||
switch(m_cfg.collisions&fCollision::RVSmask)
|
||||
@@ -3039,22 +3042,22 @@ void btSoftBody::defaultCollisionHandler(btCollisionObject* pco)
|
||||
case fCollision::SDF_RS:
|
||||
{
|
||||
btSoftColliders::CollideSDF_RS docollide;
|
||||
btRigidBody* prb1=btRigidBody::upcast(pco);
|
||||
btTransform wtr=pco->getWorldTransform();
|
||||
btRigidBody* prb1=(btRigidBody*) btRigidBody::upcast(pcoWrap->getCollisionObject());
|
||||
btTransform wtr=pcoWrap->getWorldTransform();
|
||||
|
||||
const btTransform ctr=pco->getWorldTransform();
|
||||
const btTransform ctr=pcoWrap->getWorldTransform();
|
||||
const btScalar timemargin=(wtr.getOrigin()-ctr.getOrigin()).length();
|
||||
const btScalar basemargin=getCollisionShape()->getMargin();
|
||||
btVector3 mins;
|
||||
btVector3 maxs;
|
||||
ATTRIBUTE_ALIGNED16(btDbvtVolume) volume;
|
||||
pco->getCollisionShape()->getAabb( pco->getWorldTransform(),
|
||||
pcoWrap->getCollisionShape()->getAabb( pcoWrap->getWorldTransform(),
|
||||
mins,
|
||||
maxs);
|
||||
volume=btDbvtVolume::FromMM(mins,maxs);
|
||||
volume.Expand(btVector3(basemargin,basemargin,basemargin));
|
||||
docollide.psb = this;
|
||||
docollide.m_colObj1 = pco;
|
||||
docollide.m_colObj1Wrap = pcoWrap;
|
||||
docollide.m_rigidBody = prb1;
|
||||
|
||||
docollide.dynmargin = basemargin+timemargin;
|
||||
@@ -3065,7 +3068,7 @@ void btSoftBody::defaultCollisionHandler(btCollisionObject* pco)
|
||||
case fCollision::CL_RS:
|
||||
{
|
||||
btSoftColliders::CollideCL_RS collider;
|
||||
collider.Process(this,pco);
|
||||
collider.Process(this,pcoWrap);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -69,7 +69,7 @@ struct btSoftBodyWorldInfo
|
||||
class btSoftBody : public btCollisionObject
|
||||
{
|
||||
public:
|
||||
btAlignedObjectArray<class btCollisionObject*> m_collisionDisabledObjects;
|
||||
btAlignedObjectArray<const class btCollisionObject*> m_collisionDisabledObjects;
|
||||
|
||||
// The solver object that handles this soft body
|
||||
btSoftBodySolver *m_softBodySolver;
|
||||
@@ -182,7 +182,7 @@ public:
|
||||
/* sCti is Softbody contact info */
|
||||
struct sCti
|
||||
{
|
||||
btCollisionObject* m_colObj; /* Rigid body */
|
||||
const btCollisionObject* m_colObj; /* Rigid body */
|
||||
btVector3 m_normal; /* Outward normal */
|
||||
btScalar m_offset; /* Offset from origin */
|
||||
};
|
||||
@@ -374,13 +374,13 @@ public:
|
||||
{
|
||||
Cluster* m_soft;
|
||||
btRigidBody* m_rigid;
|
||||
btCollisionObject* m_collisionObject;
|
||||
const btCollisionObject* m_collisionObject;
|
||||
|
||||
Body() : m_soft(0),m_rigid(0),m_collisionObject(0) {}
|
||||
Body(Cluster* p) : m_soft(p),m_rigid(0),m_collisionObject(0) {}
|
||||
Body(btCollisionObject* colObj) : m_soft(0),m_collisionObject(colObj)
|
||||
Body(const btCollisionObject* colObj) : m_soft(0),m_collisionObject(colObj)
|
||||
{
|
||||
m_rigid = btRigidBody::upcast(m_collisionObject);
|
||||
m_rigid = (btRigidBody*)btRigidBody::upcast(m_collisionObject);
|
||||
}
|
||||
|
||||
void activate() const
|
||||
@@ -867,7 +867,7 @@ public:
|
||||
/* integrateMotion */
|
||||
void integrateMotion();
|
||||
/* defaultCollisionHandlers */
|
||||
void defaultCollisionHandler(btCollisionObject* pco);
|
||||
void defaultCollisionHandler(const btCollisionObjectWrapper* pcoWrap);
|
||||
void defaultCollisionHandler(btSoftBody* psb);
|
||||
|
||||
|
||||
@@ -949,7 +949,7 @@ public:
|
||||
btScalar& mint,eFeature::_& feature,int& index,bool bcountonly) const;
|
||||
void initializeFaceTree();
|
||||
btVector3 evaluateCom() const;
|
||||
bool checkContact(btCollisionObject* colObj,const btVector3& x,btScalar margin,btSoftBody::sCti& cti) const;
|
||||
bool checkContact(const btCollisionObjectWrapper* colObjWrap,const btVector3& x,btScalar margin,btSoftBody::sCti& cti) const;
|
||||
void updateNormals();
|
||||
void updateBounds();
|
||||
void updatePose();
|
||||
|
||||
@@ -25,7 +25,7 @@ subject to the following restrictions:
|
||||
#include "BulletCollision/CollisionShapes/btSphereShape.h"
|
||||
#include "BulletCollision/CollisionShapes/btTetrahedronShape.h"
|
||||
#include "BulletCollision/CollisionShapes/btConvexHullShape.h"
|
||||
|
||||
#include "BulletCollision/CollisionDispatch/btCollisionObjectWrapper.h"
|
||||
|
||||
|
||||
#include "LinearMath/btIDebugDraw.h"
|
||||
@@ -34,10 +34,10 @@ subject to the following restrictions:
|
||||
|
||||
#define BT_SOFTBODY_TRIANGLE_EXTRUSION btScalar(0.06)//make this configurable
|
||||
|
||||
btSoftBodyConcaveCollisionAlgorithm::btSoftBodyConcaveCollisionAlgorithm( const btCollisionAlgorithmConstructionInfo& ci, btCollisionObject* body0,btCollisionObject* body1,bool isSwapped)
|
||||
btSoftBodyConcaveCollisionAlgorithm::btSoftBodyConcaveCollisionAlgorithm( const btCollisionAlgorithmConstructionInfo& ci, const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap,bool isSwapped)
|
||||
: btCollisionAlgorithm(ci),
|
||||
m_isSwapped(isSwapped),
|
||||
m_btSoftBodyTriangleCallback(ci.m_dispatcher1,body0,body1,isSwapped)
|
||||
m_btSoftBodyTriangleCallback(ci.m_dispatcher1,body0Wrap,body1Wrap,isSwapped)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -49,12 +49,12 @@ btSoftBodyConcaveCollisionAlgorithm::~btSoftBodyConcaveCollisionAlgorithm()
|
||||
|
||||
|
||||
|
||||
btSoftBodyTriangleCallback::btSoftBodyTriangleCallback(btDispatcher* dispatcher,btCollisionObject* body0,btCollisionObject* body1,bool isSwapped):
|
||||
btSoftBodyTriangleCallback::btSoftBodyTriangleCallback(btDispatcher* dispatcher,const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap,bool isSwapped):
|
||||
m_dispatcher(dispatcher),
|
||||
m_dispatchInfoPtr(0)
|
||||
{
|
||||
m_softBody = (btSoftBody*) (isSwapped? body1:body0);
|
||||
m_triBody = isSwapped? body0:body1;
|
||||
m_softBody = (isSwapped? (btSoftBody*)body1Wrap->getCollisionObject():(btSoftBody*)body0Wrap->getCollisionObject());
|
||||
m_triBody = isSwapped? body0Wrap->getCollisionObject():body1Wrap->getCollisionObject();
|
||||
|
||||
//
|
||||
// create the manifold from the dispatcher 'manifold pool'
|
||||
@@ -90,7 +90,7 @@ void btSoftBodyTriangleCallback::processTriangle(btVector3* triangle,int partId,
|
||||
{
|
||||
//just for debugging purposes
|
||||
//printf("triangle %d",m_triangleCount++);
|
||||
btCollisionObject* ob = static_cast<btCollisionObject*>(m_triBody);
|
||||
|
||||
btCollisionAlgorithmConstructionInfo ci;
|
||||
ci.m_dispatcher1 = m_dispatcher;
|
||||
|
||||
@@ -98,7 +98,7 @@ void btSoftBodyTriangleCallback::processTriangle(btVector3* triangle,int partId,
|
||||
if (m_dispatchInfoPtr && m_dispatchInfoPtr->m_debugDraw && (m_dispatchInfoPtr->m_debugDraw->getDebugMode() &btIDebugDraw::DBG_DrawWireframe))
|
||||
{
|
||||
btVector3 color(1,1,0);
|
||||
btTransform& tr = ob->getWorldTransform();
|
||||
const btTransform& tr = m_triBody->getWorldTransform();
|
||||
m_dispatchInfoPtr->m_debugDraw->drawLine(tr(triangle[0]),tr(triangle[1]),color);
|
||||
m_dispatchInfoPtr->m_debugDraw->drawLine(tr(triangle[1]),tr(triangle[2]),color);
|
||||
m_dispatchInfoPtr->m_debugDraw->drawLine(tr(triangle[2]),tr(triangle[0]),color);
|
||||
@@ -115,18 +115,18 @@ void btSoftBodyTriangleCallback::processTriangle(btVector3* triangle,int partId,
|
||||
btAssert(tm);
|
||||
|
||||
//copy over user pointers to temporary shape
|
||||
tm->setUserPointer(ob->getRootCollisionShape()->getUserPointer());
|
||||
tm->setUserPointer(m_triBody->getCollisionShape()->getUserPointer());
|
||||
|
||||
btCollisionShape* tmpShape = ob->getCollisionShape();
|
||||
ob->internalSetTemporaryCollisionShape( tm );
|
||||
btCollisionObjectWrapper softBody(0,m_softBody->getCollisionShape(),m_softBody,m_softBody->getWorldTransform());
|
||||
//btCollisionObjectWrapper triBody(0,tm, ob, btTransform::getIdentity());//ob->getWorldTransform());//??
|
||||
btCollisionObjectWrapper triBody(0,tm, m_triBody, m_triBody->getWorldTransform());
|
||||
|
||||
btCollisionAlgorithm* colAlgo = ci.m_dispatcher1->findAlgorithm(&softBody,&triBody,0);//m_manifoldPtr);
|
||||
|
||||
btCollisionAlgorithm* colAlgo = ci.m_dispatcher1->findAlgorithm(m_softBody,m_triBody,0);//m_manifoldPtr);
|
||||
|
||||
colAlgo->processCollision(m_softBody,m_triBody,*m_dispatchInfoPtr,m_resultOut);
|
||||
colAlgo->processCollision(&softBody,&triBody,*m_dispatchInfoPtr,m_resultOut);
|
||||
colAlgo->~btCollisionAlgorithm();
|
||||
ci.m_dispatcher1->freeCollisionAlgorithm(colAlgo);
|
||||
ob->internalSetTemporaryCollisionShape( tmpShape);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -158,24 +158,18 @@ void btSoftBodyTriangleCallback::processTriangle(btVector3* triangle,int partId,
|
||||
// tm.setMargin(m_collisionMarginTriangle);
|
||||
|
||||
//copy over user pointers to temporary shape
|
||||
tm->setUserPointer(ob->getRootCollisionShape()->getUserPointer());
|
||||
tm->setUserPointer(m_triBody->getCollisionShape()->getUserPointer());
|
||||
|
||||
btCollisionShape* tmpShape = ob->getCollisionShape();
|
||||
ob->internalSetTemporaryCollisionShape( tm );
|
||||
|
||||
btCollisionObjectWrapper softBody(0,m_softBody->getCollisionShape(),m_softBody,m_softBody->getWorldTransform());
|
||||
btCollisionObjectWrapper triBody(0,tm, m_triBody, m_triBody->getWorldTransform());//btTransform::getIdentity());//??
|
||||
|
||||
btCollisionAlgorithm* colAlgo = ci.m_dispatcher1->findAlgorithm(&softBody,&triBody,0);//m_manifoldPtr);
|
||||
|
||||
btCollisionAlgorithm* colAlgo = ci.m_dispatcher1->findAlgorithm(m_softBody,m_triBody,0);//m_manifoldPtr);
|
||||
///this should use the btDispatcher, so the actual registered algorithm is used
|
||||
// btConvexConvexAlgorithm cvxcvxalgo(m_manifoldPtr,ci,m_convexBody,m_triBody);
|
||||
|
||||
//m_resultOut->setShapeIdentifiersB(partId,triangleIndex);
|
||||
// cvxcvxalgo.processCollision(m_convexBody,m_triBody,*m_dispatchInfoPtr,m_resultOut);
|
||||
colAlgo->processCollision(m_softBody,m_triBody,*m_dispatchInfoPtr,m_resultOut);
|
||||
colAlgo->processCollision(&softBody,&triBody,*m_dispatchInfoPtr,m_resultOut);
|
||||
colAlgo->~btCollisionAlgorithm();
|
||||
ci.m_dispatcher1->freeCollisionAlgorithm(colAlgo);
|
||||
|
||||
|
||||
ob->internalSetTemporaryCollisionShape( tmpShape );
|
||||
triIndex.m_childShape = tm;
|
||||
m_shapeCache.insert(triKey,triIndex);
|
||||
|
||||
@@ -187,7 +181,7 @@ void btSoftBodyTriangleCallback::processTriangle(btVector3* triangle,int partId,
|
||||
|
||||
|
||||
|
||||
void btSoftBodyTriangleCallback::setTimeStepAndCounters(btScalar collisionMarginTriangle,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut)
|
||||
void btSoftBodyTriangleCallback::setTimeStepAndCounters(btScalar collisionMarginTriangle,const btCollisionObjectWrapper* triBodyWrap, const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut)
|
||||
{
|
||||
m_dispatchInfoPtr = &dispatchInfo;
|
||||
m_collisionMarginTriangle = collisionMarginTriangle+btScalar(BT_SOFTBODY_TRIANGLE_EXTRUSION);
|
||||
@@ -204,7 +198,7 @@ void btSoftBodyTriangleCallback::setTimeStepAndCounters(btScalar collisionMargin
|
||||
softTransform.setOrigin(softBodyCenter);
|
||||
|
||||
btTransform convexInTriangleSpace;
|
||||
convexInTriangleSpace = m_triBody->getWorldTransform().inverse() * softTransform;
|
||||
convexInTriangleSpace = triBodyWrap->getWorldTransform().inverse() * softTransform;
|
||||
btTransformAabb(halfExtents,m_collisionMarginTriangle,convexInTriangleSpace,m_aabbMin,m_aabbMax);
|
||||
}
|
||||
|
||||
@@ -214,33 +208,28 @@ void btSoftBodyConcaveCollisionAlgorithm::clearCache()
|
||||
|
||||
}
|
||||
|
||||
void btSoftBodyConcaveCollisionAlgorithm::processCollision (btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut)
|
||||
void btSoftBodyConcaveCollisionAlgorithm::processCollision (const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut)
|
||||
{
|
||||
|
||||
|
||||
//btCollisionObject* convexBody = m_isSwapped ? body1 : body0;
|
||||
btCollisionObject* triBody = m_isSwapped ? body0 : body1;
|
||||
const btCollisionObjectWrapper* triBody = m_isSwapped ? body0Wrap : body1Wrap;
|
||||
|
||||
if (triBody->getCollisionShape()->isConcave())
|
||||
{
|
||||
|
||||
|
||||
btCollisionObject* triOb = triBody;
|
||||
btConcaveShape* concaveShape = static_cast<btConcaveShape*>( triOb->getCollisionShape());
|
||||
const btCollisionObject* triOb = triBody->getCollisionObject();
|
||||
const btConcaveShape* concaveShape = static_cast<const btConcaveShape*>( triOb->getCollisionShape());
|
||||
|
||||
// if (convexBody->getCollisionShape()->isConvex())
|
||||
{
|
||||
btScalar collisionMarginTriangle = concaveShape->getMargin();
|
||||
|
||||
// resultOut->setPersistentManifold(m_btSoftBodyTriangleCallback.m_manifoldPtr);
|
||||
m_btSoftBodyTriangleCallback.setTimeStepAndCounters(collisionMarginTriangle,dispatchInfo,resultOut);
|
||||
|
||||
//Disable persistency. previously, some older algorithm calculated all contacts in one go, so you can clear it here.
|
||||
//m_dispatcher->clearManifold(m_btSoftBodyTriangleCallback.m_manifoldPtr);
|
||||
|
||||
// m_btSoftBodyTriangleCallback.m_manifoldPtr->setBodies(convexBody,triBody);
|
||||
|
||||
m_btSoftBodyTriangleCallback.setTimeStepAndCounters(collisionMarginTriangle,triBody,dispatchInfo,resultOut);
|
||||
|
||||
|
||||
concaveShape->processAllTriangles( &m_btSoftBodyTriangleCallback,m_btSoftBodyTriangleCallback.getAabbMin(),m_btSoftBodyTriangleCallback.getAabbMax());
|
||||
|
||||
// resultOut->refreshContactPoints();
|
||||
|
||||
@@ -45,7 +45,9 @@ struct btTriIndex
|
||||
int getTriangleIndex() const
|
||||
{
|
||||
// Get only the lower bits where the triangle index is stored
|
||||
return (m_PartIdTriangleIndex&~((~0)<<(31-MAX_NUM_PARTS_IN_BITS)));
|
||||
unsigned int x = 0;
|
||||
unsigned int y = (~(x&0))<<(31-MAX_NUM_PARTS_IN_BITS);
|
||||
return (m_PartIdTriangleIndex&~(y));
|
||||
}
|
||||
int getPartId() const
|
||||
{
|
||||
@@ -63,7 +65,7 @@ struct btTriIndex
|
||||
class btSoftBodyTriangleCallback : public btTriangleCallback
|
||||
{
|
||||
btSoftBody* m_softBody;
|
||||
btCollisionObject* m_triBody;
|
||||
const btCollisionObject* m_triBody;
|
||||
|
||||
btVector3 m_aabbMin;
|
||||
btVector3 m_aabbMax ;
|
||||
@@ -81,9 +83,9 @@ public:
|
||||
|
||||
// btPersistentManifold* m_manifoldPtr;
|
||||
|
||||
btSoftBodyTriangleCallback(btDispatcher* dispatcher,btCollisionObject* body0,btCollisionObject* body1,bool isSwapped);
|
||||
btSoftBodyTriangleCallback(btDispatcher* dispatcher,const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap,bool isSwapped);
|
||||
|
||||
void setTimeStepAndCounters(btScalar collisionMarginTriangle,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut);
|
||||
void setTimeStepAndCounters(btScalar collisionMarginTriangle,const btCollisionObjectWrapper* triObjWrap,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut);
|
||||
|
||||
virtual ~btSoftBodyTriangleCallback();
|
||||
|
||||
@@ -115,11 +117,11 @@ class btSoftBodyConcaveCollisionAlgorithm : public btCollisionAlgorithm
|
||||
|
||||
public:
|
||||
|
||||
btSoftBodyConcaveCollisionAlgorithm( const btCollisionAlgorithmConstructionInfo& ci,btCollisionObject* body0,btCollisionObject* body1,bool isSwapped);
|
||||
btSoftBodyConcaveCollisionAlgorithm( const btCollisionAlgorithmConstructionInfo& ci,const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap,bool isSwapped);
|
||||
|
||||
virtual ~btSoftBodyConcaveCollisionAlgorithm();
|
||||
|
||||
virtual void processCollision (btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut);
|
||||
virtual void processCollision (const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut);
|
||||
|
||||
btScalar calculateTimeOfImpact(btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut);
|
||||
|
||||
@@ -132,19 +134,19 @@ public:
|
||||
|
||||
struct CreateFunc :public btCollisionAlgorithmCreateFunc
|
||||
{
|
||||
virtual btCollisionAlgorithm* CreateCollisionAlgorithm(btCollisionAlgorithmConstructionInfo& ci, btCollisionObject* body0,btCollisionObject* body1)
|
||||
virtual btCollisionAlgorithm* CreateCollisionAlgorithm(btCollisionAlgorithmConstructionInfo& ci, const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap)
|
||||
{
|
||||
void* mem = ci.m_dispatcher1->allocateCollisionAlgorithm(sizeof(btSoftBodyConcaveCollisionAlgorithm));
|
||||
return new(mem) btSoftBodyConcaveCollisionAlgorithm(ci,body0,body1,false);
|
||||
return new(mem) btSoftBodyConcaveCollisionAlgorithm(ci,body0Wrap,body1Wrap,false);
|
||||
}
|
||||
};
|
||||
|
||||
struct SwappedCreateFunc :public btCollisionAlgorithmCreateFunc
|
||||
{
|
||||
virtual btCollisionAlgorithm* CreateCollisionAlgorithm(btCollisionAlgorithmConstructionInfo& ci, btCollisionObject* body0,btCollisionObject* body1)
|
||||
virtual btCollisionAlgorithm* CreateCollisionAlgorithm(btCollisionAlgorithmConstructionInfo& ci, const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap)
|
||||
{
|
||||
void* mem = ci.m_dispatcher1->allocateCollisionAlgorithm(sizeof(btSoftBodyConcaveCollisionAlgorithm));
|
||||
return new(mem) btSoftBodyConcaveCollisionAlgorithm(ci,body0,body1,true);
|
||||
return new(mem) btSoftBodyConcaveCollisionAlgorithm(ci,body0Wrap,body1Wrap,true);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -1,217 +1,217 @@
|
||||
/*
|
||||
Bullet Continuous Collision Detection and Physics Library
|
||||
Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
|
||||
|
||||
This software is provided 'as-is', without any express or implied warranty.
|
||||
In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it freely,
|
||||
subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#ifndef BT_SOFTBODY_FLOAT_DATA
|
||||
#define BT_SOFTBODY_FLOAT_DATA
|
||||
|
||||
#include "BulletCollision/CollisionDispatch/btCollisionObject.h"
|
||||
|
||||
|
||||
|
||||
struct SoftBodyMaterialData
|
||||
{
|
||||
float m_linearStiffness;
|
||||
float m_angularStiffness;
|
||||
float m_volumeStiffness;
|
||||
int m_flags;
|
||||
};
|
||||
|
||||
struct SoftBodyNodeData
|
||||
{
|
||||
SoftBodyMaterialData *m_material;
|
||||
btVector3FloatData m_position;
|
||||
btVector3FloatData m_previousPosition;
|
||||
btVector3FloatData m_velocity;
|
||||
btVector3FloatData m_accumulatedForce;
|
||||
btVector3FloatData m_normal;
|
||||
float m_inverseMass;
|
||||
float m_area;
|
||||
int m_attach;
|
||||
int m_pad;
|
||||
};
|
||||
|
||||
struct SoftBodyLinkData
|
||||
{
|
||||
SoftBodyMaterialData *m_material;
|
||||
int m_nodeIndices[2]; // Node pointers
|
||||
float m_restLength; // Rest length
|
||||
int m_bbending; // Bending link
|
||||
};
|
||||
|
||||
struct SoftBodyFaceData
|
||||
{
|
||||
btVector3FloatData m_normal; // Normal
|
||||
SoftBodyMaterialData *m_material;
|
||||
int m_nodeIndices[3]; // Node pointers
|
||||
float m_restArea; // Rest area
|
||||
};
|
||||
|
||||
struct SoftBodyTetraData
|
||||
{
|
||||
btVector3FloatData m_c0[4]; // gradients
|
||||
SoftBodyMaterialData *m_material;
|
||||
int m_nodeIndices[4]; // Node pointers
|
||||
float m_restVolume; // Rest volume
|
||||
float m_c1; // (4*kVST)/(im0+im1+im2+im3)
|
||||
float m_c2; // m_c1/sum(|g0..3|^2)
|
||||
int m_pad;
|
||||
};
|
||||
|
||||
struct SoftRigidAnchorData
|
||||
{
|
||||
btMatrix3x3FloatData m_c0; // Impulse matrix
|
||||
btVector3FloatData m_c1; // Relative anchor
|
||||
btVector3FloatData m_localFrame; // Anchor position in body space
|
||||
btRigidBodyData *m_rigidBody;
|
||||
int m_nodeIndex; // Node pointer
|
||||
float m_c2; // ima*dt
|
||||
};
|
||||
|
||||
|
||||
|
||||
struct SoftBodyConfigData
|
||||
{
|
||||
int m_aeroModel; // Aerodynamic model (default: V_Point)
|
||||
float m_baumgarte; // Velocities correction factor (Baumgarte)
|
||||
float m_damping; // Damping coefficient [0,1]
|
||||
float m_drag; // Drag coefficient [0,+inf]
|
||||
float m_lift; // Lift coefficient [0,+inf]
|
||||
float m_pressure; // Pressure coefficient [-inf,+inf]
|
||||
float m_volume; // Volume conversation coefficient [0,+inf]
|
||||
float m_dynamicFriction; // Dynamic friction coefficient [0,1]
|
||||
float m_poseMatch; // Pose matching coefficient [0,1]
|
||||
float m_rigidContactHardness; // Rigid contacts hardness [0,1]
|
||||
float m_kineticContactHardness; // Kinetic contacts hardness [0,1]
|
||||
float m_softContactHardness; // Soft contacts hardness [0,1]
|
||||
float m_anchorHardness; // Anchors hardness [0,1]
|
||||
float m_softRigidClusterHardness; // Soft vs rigid hardness [0,1] (cluster only)
|
||||
float m_softKineticClusterHardness; // Soft vs kinetic hardness [0,1] (cluster only)
|
||||
float m_softSoftClusterHardness; // Soft vs soft hardness [0,1] (cluster only)
|
||||
float m_softRigidClusterImpulseSplit; // Soft vs rigid impulse split [0,1] (cluster only)
|
||||
float m_softKineticClusterImpulseSplit; // Soft vs rigid impulse split [0,1] (cluster only)
|
||||
float m_softSoftClusterImpulseSplit; // Soft vs rigid impulse split [0,1] (cluster only)
|
||||
float m_maxVolume; // Maximum volume ratio for pose
|
||||
float m_timeScale; // Time scale
|
||||
int m_velocityIterations; // Velocities solver iterations
|
||||
int m_positionIterations; // Positions solver iterations
|
||||
int m_driftIterations; // Drift solver iterations
|
||||
int m_clusterIterations; // Cluster solver iterations
|
||||
int m_collisionFlags; // Collisions flags
|
||||
};
|
||||
|
||||
struct SoftBodyPoseData
|
||||
{
|
||||
btMatrix3x3FloatData m_rot; // Rotation
|
||||
btMatrix3x3FloatData m_scale; // Scale
|
||||
btMatrix3x3FloatData m_aqq; // Base scaling
|
||||
btVector3FloatData m_com; // COM
|
||||
|
||||
btVector3FloatData *m_positions; // Reference positions
|
||||
float *m_weights; // Weights
|
||||
int m_numPositions;
|
||||
int m_numWeigts;
|
||||
|
||||
int m_bvolume; // Is valid
|
||||
int m_bframe; // Is frame
|
||||
float m_restVolume; // Rest volume
|
||||
int m_pad;
|
||||
};
|
||||
|
||||
struct SoftBodyClusterData
|
||||
{
|
||||
btTransformFloatData m_framexform;
|
||||
btMatrix3x3FloatData m_locii;
|
||||
btMatrix3x3FloatData m_invwi;
|
||||
btVector3FloatData m_com;
|
||||
btVector3FloatData m_vimpulses[2];
|
||||
btVector3FloatData m_dimpulses[2];
|
||||
btVector3FloatData m_lv;
|
||||
btVector3FloatData m_av;
|
||||
|
||||
btVector3FloatData *m_framerefs;
|
||||
int *m_nodeIndices;
|
||||
float *m_masses;
|
||||
|
||||
int m_numFrameRefs;
|
||||
int m_numNodes;
|
||||
int m_numMasses;
|
||||
|
||||
float m_idmass;
|
||||
float m_imass;
|
||||
int m_nvimpulses;
|
||||
int m_ndimpulses;
|
||||
float m_ndamping;
|
||||
float m_ldamping;
|
||||
float m_adamping;
|
||||
float m_matching;
|
||||
float m_maxSelfCollisionImpulse;
|
||||
float m_selfCollisionImpulseFactor;
|
||||
int m_containsAnchor;
|
||||
int m_collide;
|
||||
int m_clusterIndex;
|
||||
};
|
||||
|
||||
|
||||
enum btSoftJointBodyType
|
||||
{
|
||||
BT_JOINT_SOFT_BODY_CLUSTER=1,
|
||||
BT_JOINT_RIGID_BODY,
|
||||
BT_JOINT_COLLISION_OBJECT
|
||||
};
|
||||
|
||||
struct btSoftBodyJointData
|
||||
{
|
||||
void *m_bodyA;
|
||||
void *m_bodyB;
|
||||
btVector3FloatData m_refs[2];
|
||||
float m_cfm;
|
||||
float m_erp;
|
||||
float m_split;
|
||||
int m_delete;
|
||||
btVector3FloatData m_relPosition[2];//linear
|
||||
int m_bodyAtype;
|
||||
int m_bodyBtype;
|
||||
int m_jointType;
|
||||
int m_pad;
|
||||
};
|
||||
|
||||
///do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64
|
||||
struct btSoftBodyFloatData
|
||||
{
|
||||
btCollisionObjectFloatData m_collisionObjectData;
|
||||
|
||||
SoftBodyPoseData *m_pose;
|
||||
SoftBodyMaterialData **m_materials;
|
||||
SoftBodyNodeData *m_nodes;
|
||||
SoftBodyLinkData *m_links;
|
||||
SoftBodyFaceData *m_faces;
|
||||
SoftBodyTetraData *m_tetrahedra;
|
||||
SoftRigidAnchorData *m_anchors;
|
||||
SoftBodyClusterData *m_clusters;
|
||||
btSoftBodyJointData *m_joints;
|
||||
|
||||
int m_numMaterials;
|
||||
int m_numNodes;
|
||||
int m_numLinks;
|
||||
int m_numFaces;
|
||||
int m_numTetrahedra;
|
||||
int m_numAnchors;
|
||||
int m_numClusters;
|
||||
int m_numJoints;
|
||||
SoftBodyConfigData m_config;
|
||||
};
|
||||
|
||||
#endif //BT_SOFTBODY_FLOAT_DATA
|
||||
|
||||
/*
|
||||
Bullet Continuous Collision Detection and Physics Library
|
||||
Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
|
||||
|
||||
This software is provided 'as-is', without any express or implied warranty.
|
||||
In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it freely,
|
||||
subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#ifndef BT_SOFTBODY_FLOAT_DATA
|
||||
#define BT_SOFTBODY_FLOAT_DATA
|
||||
|
||||
#include "BulletCollision/CollisionDispatch/btCollisionObject.h"
|
||||
|
||||
|
||||
|
||||
struct SoftBodyMaterialData
|
||||
{
|
||||
float m_linearStiffness;
|
||||
float m_angularStiffness;
|
||||
float m_volumeStiffness;
|
||||
int m_flags;
|
||||
};
|
||||
|
||||
struct SoftBodyNodeData
|
||||
{
|
||||
SoftBodyMaterialData *m_material;
|
||||
btVector3FloatData m_position;
|
||||
btVector3FloatData m_previousPosition;
|
||||
btVector3FloatData m_velocity;
|
||||
btVector3FloatData m_accumulatedForce;
|
||||
btVector3FloatData m_normal;
|
||||
float m_inverseMass;
|
||||
float m_area;
|
||||
int m_attach;
|
||||
int m_pad;
|
||||
};
|
||||
|
||||
struct SoftBodyLinkData
|
||||
{
|
||||
SoftBodyMaterialData *m_material;
|
||||
int m_nodeIndices[2]; // Node pointers
|
||||
float m_restLength; // Rest length
|
||||
int m_bbending; // Bending link
|
||||
};
|
||||
|
||||
struct SoftBodyFaceData
|
||||
{
|
||||
btVector3FloatData m_normal; // Normal
|
||||
SoftBodyMaterialData *m_material;
|
||||
int m_nodeIndices[3]; // Node pointers
|
||||
float m_restArea; // Rest area
|
||||
};
|
||||
|
||||
struct SoftBodyTetraData
|
||||
{
|
||||
btVector3FloatData m_c0[4]; // gradients
|
||||
SoftBodyMaterialData *m_material;
|
||||
int m_nodeIndices[4]; // Node pointers
|
||||
float m_restVolume; // Rest volume
|
||||
float m_c1; // (4*kVST)/(im0+im1+im2+im3)
|
||||
float m_c2; // m_c1/sum(|g0..3|^2)
|
||||
int m_pad;
|
||||
};
|
||||
|
||||
struct SoftRigidAnchorData
|
||||
{
|
||||
btMatrix3x3FloatData m_c0; // Impulse matrix
|
||||
btVector3FloatData m_c1; // Relative anchor
|
||||
btVector3FloatData m_localFrame; // Anchor position in body space
|
||||
btRigidBodyData *m_rigidBody;
|
||||
int m_nodeIndex; // Node pointer
|
||||
float m_c2; // ima*dt
|
||||
};
|
||||
|
||||
|
||||
|
||||
struct SoftBodyConfigData
|
||||
{
|
||||
int m_aeroModel; // Aerodynamic model (default: V_Point)
|
||||
float m_baumgarte; // Velocities correction factor (Baumgarte)
|
||||
float m_damping; // Damping coefficient [0,1]
|
||||
float m_drag; // Drag coefficient [0,+inf]
|
||||
float m_lift; // Lift coefficient [0,+inf]
|
||||
float m_pressure; // Pressure coefficient [-inf,+inf]
|
||||
float m_volume; // Volume conversation coefficient [0,+inf]
|
||||
float m_dynamicFriction; // Dynamic friction coefficient [0,1]
|
||||
float m_poseMatch; // Pose matching coefficient [0,1]
|
||||
float m_rigidContactHardness; // Rigid contacts hardness [0,1]
|
||||
float m_kineticContactHardness; // Kinetic contacts hardness [0,1]
|
||||
float m_softContactHardness; // Soft contacts hardness [0,1]
|
||||
float m_anchorHardness; // Anchors hardness [0,1]
|
||||
float m_softRigidClusterHardness; // Soft vs rigid hardness [0,1] (cluster only)
|
||||
float m_softKineticClusterHardness; // Soft vs kinetic hardness [0,1] (cluster only)
|
||||
float m_softSoftClusterHardness; // Soft vs soft hardness [0,1] (cluster only)
|
||||
float m_softRigidClusterImpulseSplit; // Soft vs rigid impulse split [0,1] (cluster only)
|
||||
float m_softKineticClusterImpulseSplit; // Soft vs rigid impulse split [0,1] (cluster only)
|
||||
float m_softSoftClusterImpulseSplit; // Soft vs rigid impulse split [0,1] (cluster only)
|
||||
float m_maxVolume; // Maximum volume ratio for pose
|
||||
float m_timeScale; // Time scale
|
||||
int m_velocityIterations; // Velocities solver iterations
|
||||
int m_positionIterations; // Positions solver iterations
|
||||
int m_driftIterations; // Drift solver iterations
|
||||
int m_clusterIterations; // Cluster solver iterations
|
||||
int m_collisionFlags; // Collisions flags
|
||||
};
|
||||
|
||||
struct SoftBodyPoseData
|
||||
{
|
||||
btMatrix3x3FloatData m_rot; // Rotation
|
||||
btMatrix3x3FloatData m_scale; // Scale
|
||||
btMatrix3x3FloatData m_aqq; // Base scaling
|
||||
btVector3FloatData m_com; // COM
|
||||
|
||||
btVector3FloatData *m_positions; // Reference positions
|
||||
float *m_weights; // Weights
|
||||
int m_numPositions;
|
||||
int m_numWeigts;
|
||||
|
||||
int m_bvolume; // Is valid
|
||||
int m_bframe; // Is frame
|
||||
float m_restVolume; // Rest volume
|
||||
int m_pad;
|
||||
};
|
||||
|
||||
struct SoftBodyClusterData
|
||||
{
|
||||
btTransformFloatData m_framexform;
|
||||
btMatrix3x3FloatData m_locii;
|
||||
btMatrix3x3FloatData m_invwi;
|
||||
btVector3FloatData m_com;
|
||||
btVector3FloatData m_vimpulses[2];
|
||||
btVector3FloatData m_dimpulses[2];
|
||||
btVector3FloatData m_lv;
|
||||
btVector3FloatData m_av;
|
||||
|
||||
btVector3FloatData *m_framerefs;
|
||||
int *m_nodeIndices;
|
||||
float *m_masses;
|
||||
|
||||
int m_numFrameRefs;
|
||||
int m_numNodes;
|
||||
int m_numMasses;
|
||||
|
||||
float m_idmass;
|
||||
float m_imass;
|
||||
int m_nvimpulses;
|
||||
int m_ndimpulses;
|
||||
float m_ndamping;
|
||||
float m_ldamping;
|
||||
float m_adamping;
|
||||
float m_matching;
|
||||
float m_maxSelfCollisionImpulse;
|
||||
float m_selfCollisionImpulseFactor;
|
||||
int m_containsAnchor;
|
||||
int m_collide;
|
||||
int m_clusterIndex;
|
||||
};
|
||||
|
||||
|
||||
enum btSoftJointBodyType
|
||||
{
|
||||
BT_JOINT_SOFT_BODY_CLUSTER=1,
|
||||
BT_JOINT_RIGID_BODY,
|
||||
BT_JOINT_COLLISION_OBJECT
|
||||
};
|
||||
|
||||
struct btSoftBodyJointData
|
||||
{
|
||||
void *m_bodyA;
|
||||
void *m_bodyB;
|
||||
btVector3FloatData m_refs[2];
|
||||
float m_cfm;
|
||||
float m_erp;
|
||||
float m_split;
|
||||
int m_delete;
|
||||
btVector3FloatData m_relPosition[2];//linear
|
||||
int m_bodyAtype;
|
||||
int m_bodyBtype;
|
||||
int m_jointType;
|
||||
int m_pad;
|
||||
};
|
||||
|
||||
///do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64
|
||||
struct btSoftBodyFloatData
|
||||
{
|
||||
btCollisionObjectFloatData m_collisionObjectData;
|
||||
|
||||
SoftBodyPoseData *m_pose;
|
||||
SoftBodyMaterialData **m_materials;
|
||||
SoftBodyNodeData *m_nodes;
|
||||
SoftBodyLinkData *m_links;
|
||||
SoftBodyFaceData *m_faces;
|
||||
SoftBodyTetraData *m_tetrahedra;
|
||||
SoftRigidAnchorData *m_anchors;
|
||||
SoftBodyClusterData *m_clusters;
|
||||
btSoftBodyJointData *m_joints;
|
||||
|
||||
int m_numMaterials;
|
||||
int m_numNodes;
|
||||
int m_numLinks;
|
||||
int m_numFaces;
|
||||
int m_numTetrahedra;
|
||||
int m_numAnchors;
|
||||
int m_numClusters;
|
||||
int m_numJoints;
|
||||
SoftBodyConfigData m_config;
|
||||
};
|
||||
|
||||
#endif //BT_SOFTBODY_FLOAT_DATA
|
||||
|
||||
|
||||
@@ -666,7 +666,7 @@ struct btSoftColliders
|
||||
threshold =(btScalar)0;
|
||||
}
|
||||
bool SolveContact( const btGjkEpaSolver2::sResults& res,
|
||||
btSoftBody::Body ba,btSoftBody::Body bb,
|
||||
btSoftBody::Body ba,const btSoftBody::Body bb,
|
||||
btSoftBody::CJoint& joint)
|
||||
{
|
||||
if(res.distance<m_margin)
|
||||
@@ -717,30 +717,30 @@ struct btSoftColliders
|
||||
struct CollideCL_RS : ClusterBase
|
||||
{
|
||||
btSoftBody* psb;
|
||||
|
||||
btCollisionObject* m_colObj;
|
||||
const btCollisionObjectWrapper* m_colObjWrap;
|
||||
|
||||
void Process(const btDbvtNode* leaf)
|
||||
{
|
||||
btSoftBody::Cluster* cluster=(btSoftBody::Cluster*)leaf->data;
|
||||
btSoftClusterCollisionShape cshape(cluster);
|
||||
|
||||
const btConvexShape* rshape=(const btConvexShape*)m_colObj->getCollisionShape();
|
||||
const btConvexShape* rshape=(const btConvexShape*)m_colObjWrap->getCollisionShape();
|
||||
|
||||
///don't collide an anchored cluster with a static/kinematic object
|
||||
if(m_colObj->isStaticOrKinematicObject() && cluster->m_containsAnchor)
|
||||
if(m_colObjWrap->getCollisionObject()->isStaticOrKinematicObject() && cluster->m_containsAnchor)
|
||||
return;
|
||||
|
||||
btGjkEpaSolver2::sResults res;
|
||||
if(btGjkEpaSolver2::SignedDistance( &cshape,btTransform::getIdentity(),
|
||||
rshape,m_colObj->getWorldTransform(),
|
||||
rshape,m_colObjWrap->getWorldTransform(),
|
||||
btVector3(1,0,0),res))
|
||||
{
|
||||
btSoftBody::CJoint joint;
|
||||
if(SolveContact(res,cluster,m_colObj,joint))//prb,joint))
|
||||
if(SolveContact(res,cluster,m_colObjWrap->getCollisionObject(),joint))//prb,joint))
|
||||
{
|
||||
btSoftBody::CJoint* pj=new(btAlignedAlloc(sizeof(btSoftBody::CJoint),16)) btSoftBody::CJoint();
|
||||
*pj=joint;psb->m_joints.push_back(pj);
|
||||
if(m_colObj->isStaticOrKinematicObject())
|
||||
if(m_colObjWrap->getCollisionObject()->isStaticOrKinematicObject())
|
||||
{
|
||||
pj->m_erp *= psb->m_cfg.kSKHR_CL;
|
||||
pj->m_split *= psb->m_cfg.kSK_SPLT_CL;
|
||||
@@ -753,19 +753,19 @@ struct btSoftColliders
|
||||
}
|
||||
}
|
||||
}
|
||||
void Process(btSoftBody* ps,btCollisionObject* colOb)
|
||||
void Process(btSoftBody* ps,const btCollisionObjectWrapper* colObWrap)
|
||||
{
|
||||
psb = ps;
|
||||
m_colObj = colOb;
|
||||
m_colObjWrap = colObWrap;
|
||||
idt = ps->m_sst.isdt;
|
||||
m_margin = m_colObj->getCollisionShape()->getMargin()+psb->getCollisionShape()->getMargin();
|
||||
m_margin = m_colObjWrap->getCollisionShape()->getMargin()+psb->getCollisionShape()->getMargin();
|
||||
///Bullet rigid body uses multiply instead of minimum to determine combined friction. Some customization would be useful.
|
||||
friction = btMin(psb->m_cfg.kDF,m_colObj->getFriction());
|
||||
friction = btMin(psb->m_cfg.kDF,m_colObjWrap->getCollisionObject()->getFriction());
|
||||
btVector3 mins;
|
||||
btVector3 maxs;
|
||||
|
||||
ATTRIBUTE_ALIGNED16(btDbvtVolume) volume;
|
||||
colOb->getCollisionShape()->getAabb(colOb->getWorldTransform(),mins,maxs);
|
||||
colObWrap->getCollisionShape()->getAabb(colObWrap->getWorldTransform(),mins,maxs);
|
||||
volume=btDbvtVolume::FromMM(mins,maxs);
|
||||
volume.Expand(btVector3(1,1,1)*m_margin);
|
||||
ps->m_cdbvt.collideTV(ps->m_cdbvt.m_root,volume,*this);
|
||||
@@ -840,15 +840,16 @@ struct btSoftColliders
|
||||
{
|
||||
const btScalar m=n.m_im>0?dynmargin:stamargin;
|
||||
btSoftBody::RContact c;
|
||||
|
||||
if( (!n.m_battach)&&
|
||||
psb->checkContact(m_colObj1,n.m_x,m,c.m_cti))
|
||||
psb->checkContact(m_colObj1Wrap,n.m_x,m,c.m_cti))
|
||||
{
|
||||
const btScalar ima=n.m_im;
|
||||
const btScalar imb= m_rigidBody? m_rigidBody->getInvMass() : 0.f;
|
||||
const btScalar ms=ima+imb;
|
||||
if(ms>0)
|
||||
{
|
||||
const btTransform& wtr=m_rigidBody?m_rigidBody->getWorldTransform() : m_colObj1->getWorldTransform();
|
||||
const btTransform& wtr=m_rigidBody?m_rigidBody->getWorldTransform() : m_colObj1Wrap->getCollisionObject()->getWorldTransform();
|
||||
static const btMatrix3x3 iwiStatic(0,0,0,0,0,0,0,0,0);
|
||||
const btMatrix3x3& iwi=m_rigidBody?m_rigidBody->getInvInertiaTensorWorld() : iwiStatic;
|
||||
const btVector3 ra=n.m_x-wtr.getOrigin();
|
||||
@@ -857,13 +858,13 @@ struct btSoftColliders
|
||||
const btVector3 vr=vb-va;
|
||||
const btScalar dn=btDot(vr,c.m_cti.m_normal);
|
||||
const btVector3 fv=vr-c.m_cti.m_normal*dn;
|
||||
const btScalar fc=psb->m_cfg.kDF*m_colObj1->getFriction();
|
||||
const btScalar fc=psb->m_cfg.kDF*m_colObj1Wrap->getCollisionObject()->getFriction();
|
||||
c.m_node = &n;
|
||||
c.m_c0 = ImpulseMatrix(psb->m_sst.sdt,ima,imb,iwi,ra);
|
||||
c.m_c1 = ra;
|
||||
c.m_c2 = ima*psb->m_sst.sdt;
|
||||
c.m_c3 = fv.length2()<(btFabs(dn)*fc)?0:1-fc;
|
||||
c.m_c4 = m_colObj1->isStaticOrKinematicObject()?psb->m_cfg.kKHR:psb->m_cfg.kCHR;
|
||||
c.m_c4 = m_colObj1Wrap->getCollisionObject()->isStaticOrKinematicObject()?psb->m_cfg.kKHR:psb->m_cfg.kCHR;
|
||||
psb->m_rcontacts.push_back(c);
|
||||
if (m_rigidBody)
|
||||
m_rigidBody->activate();
|
||||
@@ -871,7 +872,7 @@ struct btSoftColliders
|
||||
}
|
||||
}
|
||||
btSoftBody* psb;
|
||||
btCollisionObject* m_colObj1;
|
||||
const btCollisionObjectWrapper* m_colObj1Wrap;
|
||||
btRigidBody* m_rigidBody;
|
||||
btScalar dynmargin;
|
||||
btScalar stamargin;
|
||||
|
||||
@@ -1,165 +1,165 @@
|
||||
/*
|
||||
Bullet Continuous Collision Detection and Physics Library
|
||||
Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
|
||||
|
||||
This software is provided 'as-is', without any express or implied warranty.
|
||||
In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it freely,
|
||||
subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#ifndef BT_SOFT_BODY_SOLVER_VERTEX_BUFFER_H
|
||||
#define BT_SOFT_BODY_SOLVER_VERTEX_BUFFER_H
|
||||
|
||||
|
||||
class btVertexBufferDescriptor
|
||||
{
|
||||
public:
|
||||
enum BufferTypes
|
||||
{
|
||||
CPU_BUFFER,
|
||||
DX11_BUFFER,
|
||||
OPENGL_BUFFER
|
||||
};
|
||||
|
||||
protected:
|
||||
|
||||
bool m_hasVertexPositions;
|
||||
bool m_hasNormals;
|
||||
|
||||
int m_vertexOffset;
|
||||
int m_vertexStride;
|
||||
|
||||
int m_normalOffset;
|
||||
int m_normalStride;
|
||||
|
||||
public:
|
||||
btVertexBufferDescriptor()
|
||||
{
|
||||
m_hasVertexPositions = false;
|
||||
m_hasNormals = false;
|
||||
m_vertexOffset = 0;
|
||||
m_vertexStride = 0;
|
||||
m_normalOffset = 0;
|
||||
m_normalStride = 0;
|
||||
}
|
||||
|
||||
virtual ~btVertexBufferDescriptor()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
virtual bool hasVertexPositions() const
|
||||
{
|
||||
return m_hasVertexPositions;
|
||||
}
|
||||
|
||||
virtual bool hasNormals() const
|
||||
{
|
||||
return m_hasNormals;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the type of the vertex buffer descriptor.
|
||||
*/
|
||||
virtual BufferTypes getBufferType() const = 0;
|
||||
|
||||
/**
|
||||
* Return the vertex offset in floats from the base pointer.
|
||||
*/
|
||||
virtual int getVertexOffset() const
|
||||
{
|
||||
return m_vertexOffset;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the vertex stride in number of floats between vertices.
|
||||
*/
|
||||
virtual int getVertexStride() const
|
||||
{
|
||||
return m_vertexStride;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the vertex offset in floats from the base pointer.
|
||||
*/
|
||||
virtual int getNormalOffset() const
|
||||
{
|
||||
return m_normalOffset;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the vertex stride in number of floats between vertices.
|
||||
*/
|
||||
virtual int getNormalStride() const
|
||||
{
|
||||
return m_normalStride;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class btCPUVertexBufferDescriptor : public btVertexBufferDescriptor
|
||||
{
|
||||
protected:
|
||||
float *m_basePointer;
|
||||
|
||||
public:
|
||||
/**
|
||||
* vertexBasePointer is pointer to beginning of the buffer.
|
||||
* vertexOffset is the offset in floats to the first vertex.
|
||||
* vertexStride is the stride in floats between vertices.
|
||||
*/
|
||||
btCPUVertexBufferDescriptor( float *basePointer, int vertexOffset, int vertexStride )
|
||||
{
|
||||
m_basePointer = basePointer;
|
||||
m_vertexOffset = vertexOffset;
|
||||
m_vertexStride = vertexStride;
|
||||
m_hasVertexPositions = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* vertexBasePointer is pointer to beginning of the buffer.
|
||||
* vertexOffset is the offset in floats to the first vertex.
|
||||
* vertexStride is the stride in floats between vertices.
|
||||
*/
|
||||
btCPUVertexBufferDescriptor( float *basePointer, int vertexOffset, int vertexStride, int normalOffset, int normalStride )
|
||||
{
|
||||
m_basePointer = basePointer;
|
||||
|
||||
m_vertexOffset = vertexOffset;
|
||||
m_vertexStride = vertexStride;
|
||||
m_hasVertexPositions = true;
|
||||
|
||||
m_normalOffset = normalOffset;
|
||||
m_normalStride = normalStride;
|
||||
m_hasNormals = true;
|
||||
}
|
||||
|
||||
virtual ~btCPUVertexBufferDescriptor()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the type of the vertex buffer descriptor.
|
||||
*/
|
||||
virtual BufferTypes getBufferType() const
|
||||
{
|
||||
return CPU_BUFFER;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the base pointer in memory to the first vertex.
|
||||
*/
|
||||
virtual float *getBasePointer() const
|
||||
{
|
||||
return m_basePointer;
|
||||
}
|
||||
};
|
||||
|
||||
#endif // #ifndef BT_SOFT_BODY_SOLVER_VERTEX_BUFFER_H
|
||||
/*
|
||||
Bullet Continuous Collision Detection and Physics Library
|
||||
Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
|
||||
|
||||
This software is provided 'as-is', without any express or implied warranty.
|
||||
In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it freely,
|
||||
subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#ifndef BT_SOFT_BODY_SOLVER_VERTEX_BUFFER_H
|
||||
#define BT_SOFT_BODY_SOLVER_VERTEX_BUFFER_H
|
||||
|
||||
|
||||
class btVertexBufferDescriptor
|
||||
{
|
||||
public:
|
||||
enum BufferTypes
|
||||
{
|
||||
CPU_BUFFER,
|
||||
DX11_BUFFER,
|
||||
OPENGL_BUFFER
|
||||
};
|
||||
|
||||
protected:
|
||||
|
||||
bool m_hasVertexPositions;
|
||||
bool m_hasNormals;
|
||||
|
||||
int m_vertexOffset;
|
||||
int m_vertexStride;
|
||||
|
||||
int m_normalOffset;
|
||||
int m_normalStride;
|
||||
|
||||
public:
|
||||
btVertexBufferDescriptor()
|
||||
{
|
||||
m_hasVertexPositions = false;
|
||||
m_hasNormals = false;
|
||||
m_vertexOffset = 0;
|
||||
m_vertexStride = 0;
|
||||
m_normalOffset = 0;
|
||||
m_normalStride = 0;
|
||||
}
|
||||
|
||||
virtual ~btVertexBufferDescriptor()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
virtual bool hasVertexPositions() const
|
||||
{
|
||||
return m_hasVertexPositions;
|
||||
}
|
||||
|
||||
virtual bool hasNormals() const
|
||||
{
|
||||
return m_hasNormals;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the type of the vertex buffer descriptor.
|
||||
*/
|
||||
virtual BufferTypes getBufferType() const = 0;
|
||||
|
||||
/**
|
||||
* Return the vertex offset in floats from the base pointer.
|
||||
*/
|
||||
virtual int getVertexOffset() const
|
||||
{
|
||||
return m_vertexOffset;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the vertex stride in number of floats between vertices.
|
||||
*/
|
||||
virtual int getVertexStride() const
|
||||
{
|
||||
return m_vertexStride;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the vertex offset in floats from the base pointer.
|
||||
*/
|
||||
virtual int getNormalOffset() const
|
||||
{
|
||||
return m_normalOffset;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the vertex stride in number of floats between vertices.
|
||||
*/
|
||||
virtual int getNormalStride() const
|
||||
{
|
||||
return m_normalStride;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class btCPUVertexBufferDescriptor : public btVertexBufferDescriptor
|
||||
{
|
||||
protected:
|
||||
float *m_basePointer;
|
||||
|
||||
public:
|
||||
/**
|
||||
* vertexBasePointer is pointer to beginning of the buffer.
|
||||
* vertexOffset is the offset in floats to the first vertex.
|
||||
* vertexStride is the stride in floats between vertices.
|
||||
*/
|
||||
btCPUVertexBufferDescriptor( float *basePointer, int vertexOffset, int vertexStride )
|
||||
{
|
||||
m_basePointer = basePointer;
|
||||
m_vertexOffset = vertexOffset;
|
||||
m_vertexStride = vertexStride;
|
||||
m_hasVertexPositions = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* vertexBasePointer is pointer to beginning of the buffer.
|
||||
* vertexOffset is the offset in floats to the first vertex.
|
||||
* vertexStride is the stride in floats between vertices.
|
||||
*/
|
||||
btCPUVertexBufferDescriptor( float *basePointer, int vertexOffset, int vertexStride, int normalOffset, int normalStride )
|
||||
{
|
||||
m_basePointer = basePointer;
|
||||
|
||||
m_vertexOffset = vertexOffset;
|
||||
m_vertexStride = vertexStride;
|
||||
m_hasVertexPositions = true;
|
||||
|
||||
m_normalOffset = normalOffset;
|
||||
m_normalStride = normalStride;
|
||||
m_hasNormals = true;
|
||||
}
|
||||
|
||||
virtual ~btCPUVertexBufferDescriptor()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the type of the vertex buffer descriptor.
|
||||
*/
|
||||
virtual BufferTypes getBufferType() const
|
||||
{
|
||||
return CPU_BUFFER;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the base pointer in memory to the first vertex.
|
||||
*/
|
||||
virtual float *getBasePointer() const
|
||||
{
|
||||
return m_basePointer;
|
||||
}
|
||||
};
|
||||
|
||||
#endif // #ifndef BT_SOFT_BODY_SOLVER_VERTEX_BUFFER_H
|
||||
|
||||
@@ -1,154 +1,154 @@
|
||||
/*
|
||||
Bullet Continuous Collision Detection and Physics Library
|
||||
Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
|
||||
|
||||
This software is provided 'as-is', without any express or implied warranty.
|
||||
In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it freely,
|
||||
subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#ifndef BT_SOFT_BODY_SOLVERS_H
|
||||
#define BT_SOFT_BODY_SOLVERS_H
|
||||
|
||||
#include "BulletCollision/CollisionShapes/btTriangleIndexVertexArray.h"
|
||||
|
||||
|
||||
class btSoftBodyTriangleData;
|
||||
class btSoftBodyLinkData;
|
||||
class btSoftBodyVertexData;
|
||||
class btVertexBufferDescriptor;
|
||||
class btCollisionObject;
|
||||
class btSoftBody;
|
||||
|
||||
|
||||
class btSoftBodySolver
|
||||
{
|
||||
public:
|
||||
enum SolverTypes
|
||||
{
|
||||
DEFAULT_SOLVER,
|
||||
CPU_SOLVER,
|
||||
CL_SOLVER,
|
||||
CL_SIMD_SOLVER,
|
||||
DX_SOLVER,
|
||||
DX_SIMD_SOLVER
|
||||
};
|
||||
|
||||
|
||||
protected:
|
||||
int m_numberOfPositionIterations;
|
||||
int m_numberOfVelocityIterations;
|
||||
// Simulation timescale
|
||||
float m_timeScale;
|
||||
|
||||
public:
|
||||
btSoftBodySolver() :
|
||||
m_numberOfPositionIterations( 10 ),
|
||||
m_timeScale( 1 )
|
||||
{
|
||||
m_numberOfVelocityIterations = 0;
|
||||
m_numberOfPositionIterations = 5;
|
||||
}
|
||||
|
||||
virtual ~btSoftBodySolver()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the type of the solver.
|
||||
*/
|
||||
virtual SolverTypes getSolverType() const = 0;
|
||||
|
||||
|
||||
/** Ensure that this solver is initialized. */
|
||||
virtual bool checkInitialized() = 0;
|
||||
|
||||
/** Optimize soft bodies in this solver. */
|
||||
virtual void optimize( btAlignedObjectArray< btSoftBody * > &softBodies , bool forceUpdate=false) = 0;
|
||||
|
||||
/** Copy necessary data back to the original soft body source objects. */
|
||||
virtual void copyBackToSoftBodies(bool bMove = true) = 0;
|
||||
|
||||
/** Predict motion of soft bodies into next timestep */
|
||||
virtual void predictMotion( float solverdt ) = 0;
|
||||
|
||||
/** Solve constraints for a set of soft bodies */
|
||||
virtual void solveConstraints( float solverdt ) = 0;
|
||||
|
||||
/** Perform necessary per-step updates of soft bodies such as recomputing normals and bounding boxes */
|
||||
virtual void updateSoftBodies() = 0;
|
||||
|
||||
/** Process a collision between one of the world's soft bodies and another collision object */
|
||||
virtual void processCollision( btSoftBody *, btCollisionObject* ) = 0;
|
||||
|
||||
/** Process a collision between two soft bodies */
|
||||
virtual void processCollision( btSoftBody*, btSoftBody* ) = 0;
|
||||
|
||||
/** Set the number of velocity constraint solver iterations this solver uses. */
|
||||
virtual void setNumberOfPositionIterations( int iterations )
|
||||
{
|
||||
m_numberOfPositionIterations = iterations;
|
||||
}
|
||||
|
||||
/** Get the number of velocity constraint solver iterations this solver uses. */
|
||||
virtual int getNumberOfPositionIterations()
|
||||
{
|
||||
return m_numberOfPositionIterations;
|
||||
}
|
||||
|
||||
/** Set the number of velocity constraint solver iterations this solver uses. */
|
||||
virtual void setNumberOfVelocityIterations( int iterations )
|
||||
{
|
||||
m_numberOfVelocityIterations = iterations;
|
||||
}
|
||||
|
||||
/** Get the number of velocity constraint solver iterations this solver uses. */
|
||||
virtual int getNumberOfVelocityIterations()
|
||||
{
|
||||
return m_numberOfVelocityIterations;
|
||||
}
|
||||
|
||||
/** Return the timescale that the simulation is using */
|
||||
float getTimeScale()
|
||||
{
|
||||
return m_timeScale;
|
||||
}
|
||||
|
||||
#if 0
|
||||
/**
|
||||
* Add a collision object to be used by the indicated softbody.
|
||||
*/
|
||||
virtual void addCollisionObjectForSoftBody( int clothIdentifier, btCollisionObject *collisionObject ) = 0;
|
||||
#endif
|
||||
};
|
||||
|
||||
/**
|
||||
* Class to manage movement of data from a solver to a given target.
|
||||
* This version is abstract. Subclasses will have custom pairings for different combinations.
|
||||
*/
|
||||
class btSoftBodySolverOutput
|
||||
{
|
||||
protected:
|
||||
|
||||
public:
|
||||
btSoftBodySolverOutput()
|
||||
{
|
||||
}
|
||||
|
||||
virtual ~btSoftBodySolverOutput()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/** Output current computed vertex data to the vertex buffers for all cloths in the solver. */
|
||||
virtual void copySoftBodyToVertexBuffer( const btSoftBody * const softBody, btVertexBufferDescriptor *vertexBuffer ) = 0;
|
||||
};
|
||||
|
||||
|
||||
#endif // #ifndef BT_SOFT_BODY_SOLVERS_H
|
||||
/*
|
||||
Bullet Continuous Collision Detection and Physics Library
|
||||
Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
|
||||
|
||||
This software is provided 'as-is', without any express or implied warranty.
|
||||
In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it freely,
|
||||
subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#ifndef BT_SOFT_BODY_SOLVERS_H
|
||||
#define BT_SOFT_BODY_SOLVERS_H
|
||||
|
||||
#include "BulletCollision/CollisionShapes/btTriangleIndexVertexArray.h"
|
||||
|
||||
|
||||
class btSoftBodyTriangleData;
|
||||
class btSoftBodyLinkData;
|
||||
class btSoftBodyVertexData;
|
||||
class btVertexBufferDescriptor;
|
||||
class btCollisionObject;
|
||||
class btSoftBody;
|
||||
|
||||
|
||||
class btSoftBodySolver
|
||||
{
|
||||
public:
|
||||
enum SolverTypes
|
||||
{
|
||||
DEFAULT_SOLVER,
|
||||
CPU_SOLVER,
|
||||
CL_SOLVER,
|
||||
CL_SIMD_SOLVER,
|
||||
DX_SOLVER,
|
||||
DX_SIMD_SOLVER
|
||||
};
|
||||
|
||||
|
||||
protected:
|
||||
int m_numberOfPositionIterations;
|
||||
int m_numberOfVelocityIterations;
|
||||
// Simulation timescale
|
||||
float m_timeScale;
|
||||
|
||||
public:
|
||||
btSoftBodySolver() :
|
||||
m_numberOfPositionIterations( 10 ),
|
||||
m_timeScale( 1 )
|
||||
{
|
||||
m_numberOfVelocityIterations = 0;
|
||||
m_numberOfPositionIterations = 5;
|
||||
}
|
||||
|
||||
virtual ~btSoftBodySolver()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the type of the solver.
|
||||
*/
|
||||
virtual SolverTypes getSolverType() const = 0;
|
||||
|
||||
|
||||
/** Ensure that this solver is initialized. */
|
||||
virtual bool checkInitialized() = 0;
|
||||
|
||||
/** Optimize soft bodies in this solver. */
|
||||
virtual void optimize( btAlignedObjectArray< btSoftBody * > &softBodies , bool forceUpdate=false) = 0;
|
||||
|
||||
/** Copy necessary data back to the original soft body source objects. */
|
||||
virtual void copyBackToSoftBodies(bool bMove = true) = 0;
|
||||
|
||||
/** Predict motion of soft bodies into next timestep */
|
||||
virtual void predictMotion( float solverdt ) = 0;
|
||||
|
||||
/** Solve constraints for a set of soft bodies */
|
||||
virtual void solveConstraints( float solverdt ) = 0;
|
||||
|
||||
/** Perform necessary per-step updates of soft bodies such as recomputing normals and bounding boxes */
|
||||
virtual void updateSoftBodies() = 0;
|
||||
|
||||
/** Process a collision between one of the world's soft bodies and another collision object */
|
||||
virtual void processCollision( btSoftBody *, const struct btCollisionObjectWrapper* ) = 0;
|
||||
|
||||
/** Process a collision between two soft bodies */
|
||||
virtual void processCollision( btSoftBody*, btSoftBody* ) = 0;
|
||||
|
||||
/** Set the number of velocity constraint solver iterations this solver uses. */
|
||||
virtual void setNumberOfPositionIterations( int iterations )
|
||||
{
|
||||
m_numberOfPositionIterations = iterations;
|
||||
}
|
||||
|
||||
/** Get the number of velocity constraint solver iterations this solver uses. */
|
||||
virtual int getNumberOfPositionIterations()
|
||||
{
|
||||
return m_numberOfPositionIterations;
|
||||
}
|
||||
|
||||
/** Set the number of velocity constraint solver iterations this solver uses. */
|
||||
virtual void setNumberOfVelocityIterations( int iterations )
|
||||
{
|
||||
m_numberOfVelocityIterations = iterations;
|
||||
}
|
||||
|
||||
/** Get the number of velocity constraint solver iterations this solver uses. */
|
||||
virtual int getNumberOfVelocityIterations()
|
||||
{
|
||||
return m_numberOfVelocityIterations;
|
||||
}
|
||||
|
||||
/** Return the timescale that the simulation is using */
|
||||
float getTimeScale()
|
||||
{
|
||||
return m_timeScale;
|
||||
}
|
||||
|
||||
#if 0
|
||||
/**
|
||||
* Add a collision object to be used by the indicated softbody.
|
||||
*/
|
||||
virtual void addCollisionObjectForSoftBody( int clothIdentifier, btCollisionObject *collisionObject ) = 0;
|
||||
#endif
|
||||
};
|
||||
|
||||
/**
|
||||
* Class to manage movement of data from a solver to a given target.
|
||||
* This version is abstract. Subclasses will have custom pairings for different combinations.
|
||||
*/
|
||||
class btSoftBodySolverOutput
|
||||
{
|
||||
protected:
|
||||
|
||||
public:
|
||||
btSoftBodySolverOutput()
|
||||
{
|
||||
}
|
||||
|
||||
virtual ~btSoftBodySolverOutput()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/** Output current computed vertex data to the vertex buffers for all cloths in the solver. */
|
||||
virtual void copySoftBodyToVertexBuffer( const btSoftBody * const softBody, btVertexBufferDescriptor *vertexBuffer ) = 0;
|
||||
};
|
||||
|
||||
|
||||
#endif // #ifndef BT_SOFT_BODY_SOLVERS_H
|
||||
|
||||
@@ -20,13 +20,14 @@ subject to the following restrictions:
|
||||
#include "BulletCollision/CollisionDispatch/btCollisionObject.h"
|
||||
#include "btSoftBody.h"
|
||||
#include "BulletSoftBody/btSoftBodySolvers.h"
|
||||
#include "BulletCollision/CollisionDispatch/btCollisionObjectWrapper.h"
|
||||
|
||||
///TODO: include all the shapes that the softbody can collide with
|
||||
///alternatively, implement special case collision algorithms (just like for rigid collision shapes)
|
||||
|
||||
//#include <stdio.h>
|
||||
|
||||
btSoftRigidCollisionAlgorithm::btSoftRigidCollisionAlgorithm(btPersistentManifold* /*mf*/,const btCollisionAlgorithmConstructionInfo& ci,btCollisionObject* /*col0*/,btCollisionObject* /*col1*/, bool isSwapped)
|
||||
btSoftRigidCollisionAlgorithm::btSoftRigidCollisionAlgorithm(btPersistentManifold* /*mf*/,const btCollisionAlgorithmConstructionInfo& ci,const btCollisionObjectWrapper* ,const btCollisionObjectWrapper* , bool isSwapped)
|
||||
: btCollisionAlgorithm(ci),
|
||||
//m_ownManifold(false),
|
||||
//m_manifoldPtr(mf),
|
||||
@@ -52,18 +53,19 @@ btSoftRigidCollisionAlgorithm::~btSoftRigidCollisionAlgorithm()
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
void btSoftRigidCollisionAlgorithm::processCollision (btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut)
|
||||
void btSoftRigidCollisionAlgorithm::processCollision (const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut)
|
||||
{
|
||||
(void)dispatchInfo;
|
||||
(void)resultOut;
|
||||
//printf("btSoftRigidCollisionAlgorithm\n");
|
||||
|
||||
btSoftBody* softBody = m_isSwapped? (btSoftBody*)body1 : (btSoftBody*)body0;
|
||||
btCollisionObject* rigidCollisionObject = m_isSwapped? body0 : body1;
|
||||
const btCollisionObjectWrapper* softWrap = m_isSwapped?body1Wrap:body0Wrap;
|
||||
const btCollisionObjectWrapper* rigidWrap = m_isSwapped?body0Wrap:body1Wrap;
|
||||
btSoftBody* softBody = m_isSwapped? (btSoftBody*)body1Wrap->getCollisionObject() : (btSoftBody*)body0Wrap->getCollisionObject();
|
||||
const btCollisionObjectWrapper* rigidCollisionObjectWrap = m_isSwapped? body0Wrap : body1Wrap;
|
||||
|
||||
if (softBody->m_collisionDisabledObjects.findLinearSearch(rigidCollisionObject)==softBody->m_collisionDisabledObjects.size())
|
||||
if (softBody->m_collisionDisabledObjects.findLinearSearch(rigidCollisionObjectWrap->getCollisionObject())==softBody->m_collisionDisabledObjects.size())
|
||||
{
|
||||
softBody->getSoftBodySolver()->processCollision(softBody, rigidCollisionObject);
|
||||
softBody->getSoftBodySolver()->processCollision(softBody, rigidCollisionObjectWrap);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -39,11 +39,11 @@ class btSoftRigidCollisionAlgorithm : public btCollisionAlgorithm
|
||||
|
||||
public:
|
||||
|
||||
btSoftRigidCollisionAlgorithm(btPersistentManifold* mf,const btCollisionAlgorithmConstructionInfo& ci,btCollisionObject* col0,btCollisionObject* col1, bool isSwapped);
|
||||
btSoftRigidCollisionAlgorithm(btPersistentManifold* mf,const btCollisionAlgorithmConstructionInfo& ci,const btCollisionObjectWrapper* col0,const btCollisionObjectWrapper* col1Wrap, bool isSwapped);
|
||||
|
||||
virtual ~btSoftRigidCollisionAlgorithm();
|
||||
|
||||
virtual void processCollision (btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut);
|
||||
virtual void processCollision (const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut);
|
||||
|
||||
virtual btScalar calculateTimeOfImpact(btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut);
|
||||
|
||||
@@ -55,15 +55,15 @@ public:
|
||||
|
||||
struct CreateFunc :public btCollisionAlgorithmCreateFunc
|
||||
{
|
||||
virtual btCollisionAlgorithm* CreateCollisionAlgorithm(btCollisionAlgorithmConstructionInfo& ci, btCollisionObject* body0,btCollisionObject* body1)
|
||||
virtual btCollisionAlgorithm* CreateCollisionAlgorithm(btCollisionAlgorithmConstructionInfo& ci, const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap)
|
||||
{
|
||||
void* mem = ci.m_dispatcher1->allocateCollisionAlgorithm(sizeof(btSoftRigidCollisionAlgorithm));
|
||||
if (!m_swapped)
|
||||
{
|
||||
return new(mem) btSoftRigidCollisionAlgorithm(0,ci,body0,body1,false);
|
||||
return new(mem) btSoftRigidCollisionAlgorithm(0,ci,body0Wrap,body1Wrap,false);
|
||||
} else
|
||||
{
|
||||
return new(mem) btSoftRigidCollisionAlgorithm(0,ci,body0,body1,true);
|
||||
return new(mem) btSoftRigidCollisionAlgorithm(0,ci,body0Wrap,body1Wrap,true);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -19,10 +19,11 @@ subject to the following restrictions:
|
||||
#include "BulletCollision/CollisionDispatch/btCollisionObject.h"
|
||||
#include "BulletSoftBody/btSoftBodySolvers.h"
|
||||
#include "btSoftBody.h"
|
||||
#include "BulletCollision/CollisionDispatch/btCollisionObjectWrapper.h"
|
||||
|
||||
#define USE_PERSISTENT_CONTACTS 1
|
||||
|
||||
btSoftSoftCollisionAlgorithm::btSoftSoftCollisionAlgorithm(btPersistentManifold* /*mf*/,const btCollisionAlgorithmConstructionInfo& ci,btCollisionObject* /*obj0*/,btCollisionObject* /*obj1*/)
|
||||
btSoftSoftCollisionAlgorithm::btSoftSoftCollisionAlgorithm(btPersistentManifold* /*mf*/,const btCollisionAlgorithmConstructionInfo& ci,const btCollisionObjectWrapper* /*obj0*/,const btCollisionObjectWrapper* /*obj1*/)
|
||||
: btCollisionAlgorithm(ci)
|
||||
//m_ownManifold(false),
|
||||
//m_manifoldPtr(mf)
|
||||
@@ -33,10 +34,10 @@ btSoftSoftCollisionAlgorithm::~btSoftSoftCollisionAlgorithm()
|
||||
{
|
||||
}
|
||||
|
||||
void btSoftSoftCollisionAlgorithm::processCollision (btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& /*dispatchInfo*/,btManifoldResult* /*resultOut*/)
|
||||
void btSoftSoftCollisionAlgorithm::processCollision (const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap,const btDispatcherInfo& /*dispatchInfo*/,btManifoldResult* /*resultOut*/)
|
||||
{
|
||||
btSoftBody* soft0 = (btSoftBody*)body0;
|
||||
btSoftBody* soft1 = (btSoftBody*)body1;
|
||||
btSoftBody* soft0 = (btSoftBody*)body0Wrap->getCollisionObject();
|
||||
btSoftBody* soft1 = (btSoftBody*)body1Wrap->getCollisionObject();
|
||||
soft0->getSoftBodySolver()->processCollision(soft0, soft1);
|
||||
}
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ public:
|
||||
btSoftSoftCollisionAlgorithm(const btCollisionAlgorithmConstructionInfo& ci)
|
||||
: btCollisionAlgorithm(ci) {}
|
||||
|
||||
virtual void processCollision (btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut);
|
||||
virtual void processCollision (const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut);
|
||||
|
||||
virtual btScalar calculateTimeOfImpact(btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut);
|
||||
|
||||
@@ -48,17 +48,17 @@ public:
|
||||
manifoldArray.push_back(m_manifoldPtr);
|
||||
}
|
||||
|
||||
btSoftSoftCollisionAlgorithm(btPersistentManifold* mf,const btCollisionAlgorithmConstructionInfo& ci,btCollisionObject* body0,btCollisionObject* body1);
|
||||
btSoftSoftCollisionAlgorithm(btPersistentManifold* mf,const btCollisionAlgorithmConstructionInfo& ci,const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap);
|
||||
|
||||
virtual ~btSoftSoftCollisionAlgorithm();
|
||||
|
||||
struct CreateFunc :public btCollisionAlgorithmCreateFunc
|
||||
{
|
||||
virtual btCollisionAlgorithm* CreateCollisionAlgorithm(btCollisionAlgorithmConstructionInfo& ci, btCollisionObject* body0,btCollisionObject* body1)
|
||||
virtual btCollisionAlgorithm* CreateCollisionAlgorithm(btCollisionAlgorithmConstructionInfo& ci, const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap)
|
||||
{
|
||||
int bbsize = sizeof(btSoftSoftCollisionAlgorithm);
|
||||
void* ptr = ci.m_dispatcher1->allocateCollisionAlgorithm(bbsize);
|
||||
return new(ptr) btSoftSoftCollisionAlgorithm(0,ci,body0,body1);
|
||||
return new(ptr) btSoftSoftCollisionAlgorithm(0,ci,body0Wrap,body1Wrap);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -58,7 +58,7 @@ struct btSparseSdf
|
||||
int c[3];
|
||||
int puid;
|
||||
unsigned hash;
|
||||
btCollisionShape* pclient;
|
||||
const btCollisionShape* pclient;
|
||||
Cell* next;
|
||||
};
|
||||
//
|
||||
@@ -152,7 +152,7 @@ struct btSparseSdf
|
||||
}
|
||||
//
|
||||
btScalar Evaluate( const btVector3& x,
|
||||
btCollisionShape* shape,
|
||||
const btCollisionShape* shape,
|
||||
btVector3& normal,
|
||||
btScalar margin)
|
||||
{
|
||||
@@ -248,14 +248,14 @@ struct btSparseSdf
|
||||
}
|
||||
//
|
||||
static inline btScalar DistanceToShape(const btVector3& x,
|
||||
btCollisionShape* shape)
|
||||
const btCollisionShape* shape)
|
||||
{
|
||||
btTransform unit;
|
||||
unit.setIdentity();
|
||||
if(shape->isConvex())
|
||||
{
|
||||
btGjkEpaSolver2::sResults res;
|
||||
btConvexShape* csh=static_cast<btConvexShape*>(shape);
|
||||
const btConvexShape* csh=static_cast<const btConvexShape*>(shape);
|
||||
return(btGjkEpaSolver2::SignedDistance(x,0,csh,unit,res));
|
||||
}
|
||||
return(0);
|
||||
@@ -282,7 +282,7 @@ struct btSparseSdf
|
||||
|
||||
|
||||
//
|
||||
static inline unsigned int Hash(int x,int y,int z,btCollisionShape* shape)
|
||||
static inline unsigned int Hash(int x,int y,int z,const btCollisionShape* shape)
|
||||
{
|
||||
struct btS
|
||||
{
|
||||
@@ -292,7 +292,7 @@ struct btSparseSdf
|
||||
|
||||
btS myset;
|
||||
|
||||
myset.x=x;myset.y=y;myset.z=z;myset.p=shape;
|
||||
myset.x=x;myset.y=y;myset.z=z;myset.p=(void*)shape;
|
||||
const void* ptr = &myset;
|
||||
|
||||
unsigned int result = HsiehHash<sizeof(btS)/4> (ptr);
|
||||
|
||||
Reference in New Issue
Block a user