From 2d1777c89999e428a32196f2ff72a9a3a3999ce4 Mon Sep 17 00:00:00 2001 From: "erwin.coumans" Date: Mon, 31 Aug 2009 04:35:06 +0000 Subject: [PATCH] Avoid collision detection/response between anchored (static) soft body cluster and a static/kinematic rigid body --- src/BulletSoftBody/btSoftBody.cpp | 12 +++++++++--- src/BulletSoftBody/btSoftBody.h | 4 +++- src/BulletSoftBody/btSoftBodyInternals.h | 5 +++++ 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/BulletSoftBody/btSoftBody.cpp b/src/BulletSoftBody/btSoftBody.cpp index 8775b7865..2c923210f 100644 --- a/src/BulletSoftBody/btSoftBody.cpp +++ b/src/BulletSoftBody/btSoftBody.cpp @@ -2116,11 +2116,17 @@ void btSoftBody::initializeClusters() c.m_masses.resize(c.m_nodes.size()); for(int j=0;jm_im>0?1/c.m_nodes[j]->m_im: BT_LARGE_FLOAT; - //c.m_masses[j] = c.m_nodes[j]->m_im>0?1/c.m_nodes[j]->m_im: 0.f; + if (c.m_nodes[j]->m_im==0) + { + c.m_containsAnchor = true; + c.m_masses[j] = BT_LARGE_FLOAT; + } else + { + c.m_masses[j] = btScalar(1.)/c.m_nodes[j]->m_im; + } c.m_imass += c.m_masses[j]; } - c.m_imass = 1/c.m_imass; + c.m_imass = btScalar(1.)/c.m_imass; c.m_com = btSoftBody::clusterCom(&c); c.m_lv = btVector3(0,0,0); c.m_av = btVector3(0,0,0); diff --git a/src/BulletSoftBody/btSoftBody.h b/src/BulletSoftBody/btSoftBody.h index 76df16160..d69e835f1 100644 --- a/src/BulletSoftBody/btSoftBody.h +++ b/src/BulletSoftBody/btSoftBody.h @@ -310,11 +310,13 @@ public: btScalar m_matching; btScalar m_maxSelfCollisionImpulse; btScalar m_selfCollisionImpulseFactor; + bool m_containsAnchor; bool m_collide; int m_clusterIndex; Cluster() : m_leaf(0),m_ndamping(0),m_ldamping(0),m_adamping(0),m_matching(0) ,m_maxSelfCollisionImpulse(100.f), - m_selfCollisionImpulseFactor(0.01f) + m_selfCollisionImpulseFactor(0.01f), + m_containsAnchor(false) {} }; /* Impulse */ diff --git a/src/BulletSoftBody/btSoftBodyInternals.h b/src/BulletSoftBody/btSoftBodyInternals.h index 31be2e533..2cb7744cb 100644 --- a/src/BulletSoftBody/btSoftBodyInternals.h +++ b/src/BulletSoftBody/btSoftBodyInternals.h @@ -726,6 +726,11 @@ struct btSoftColliders btSoftClusterCollisionShape cshape(cluster); const btConvexShape* rshape=(const btConvexShape*)m_colObj->getCollisionShape(); + + ///don't collide an anchored cluster with a static/kinematic object + if(m_colObj->isStaticOrKinematicObject() && cluster->m_containsAnchor) + return; + btGjkEpaSolver2::sResults res; if(btGjkEpaSolver2::SignedDistance( &cshape,btTransform::getIdentity(), rshape,m_colObj->getInterpolationWorldTransform(),