fixed soft body collision against concave triangle meshes.
authorErwin Coumans <blender@erwincoumans.com>
Fri, 26 Sep 2008 21:49:26 +0000 (21:49 +0000)
committerErwin Coumans <blender@erwincoumans.com>
Fri, 26 Sep 2008 21:49:26 +0000 (21:49 +0000)
extern/bullet2/src/BulletSoftBody/btSoftBodyConcaveCollisionAlgorithm.cpp

index 5e3211ed73b8751b2877b50389760ff0fd455c4d..3bcfe492107a2adb6b86fcc3728be6b250dc826e 100644 (file)
@@ -32,7 +32,7 @@ subject to the following restrictions:
 #include "BulletCollision/NarrowPhaseCollision/btSubSimplexConvexCast.h"
 #include "BulletSoftBody/btSoftBody.h"
 
 #include "BulletCollision/NarrowPhaseCollision/btSubSimplexConvexCast.h"
 #include "BulletSoftBody/btSoftBody.h"
 
-#define BT_SOFTBODY_TRIANGLE_EXTRUSION btScalar(0.3)
+#define BT_SOFTBODY_TRIANGLE_EXTRUSION btScalar(0.06)//make this configurable
 
 btSoftBodyConcaveCollisionAlgorithm::btSoftBodyConcaveCollisionAlgorithm( const btCollisionAlgorithmConstructionInfo& ci, btCollisionObject* body0,btCollisionObject* body1,bool isSwapped)
 : btCollisionAlgorithm(ci),
 
 btSoftBodyConcaveCollisionAlgorithm::btSoftBodyConcaveCollisionAlgorithm( const btCollisionAlgorithmConstructionInfo& ci, btCollisionObject* body0,btCollisionObject* body1,bool isSwapped)
 : btCollisionAlgorithm(ci),
@@ -210,44 +210,22 @@ btCollisionObject* ob = static_cast<btCollisionObject*>(m_triBody);
 void   btSoftBodyTriangleCallback::setTimeStepAndCounters(btScalar collisionMarginTriangle,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut)
 {
        m_dispatchInfoPtr = &dispatchInfo;
 void   btSoftBodyTriangleCallback::setTimeStepAndCounters(btScalar collisionMarginTriangle,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut)
 {
        m_dispatchInfoPtr = &dispatchInfo;
-       m_collisionMarginTriangle = collisionMarginTriangle;
+       m_collisionMarginTriangle = collisionMarginTriangle+btScalar(BT_SOFTBODY_TRIANGLE_EXTRUSION);
        m_resultOut = resultOut;
 
        m_resultOut = resultOut;
 
-       //recalc aabbs
-//     btTransform softbodyInTriangleSpace;
-//     softbodyInTriangleSpace = m_triBody->getWorldTransform().inverse() * m_softBody->getWorldTransform();
-//     btCollisionShape* convexShape = static_cast<btCollisionShape*>(m_convexBody->getCollisionShape());
-       //CollisionShape* triangleShape = static_cast<btCollisionShape*>(triBody->m_collisionShape);
+       
        btVector3       aabbWorldSpaceMin,aabbWorldSpaceMax;
        m_softBody->getAabb(aabbWorldSpaceMin,aabbWorldSpaceMax);
        btVector3       aabbWorldSpaceMin,aabbWorldSpaceMax;
        m_softBody->getAabb(aabbWorldSpaceMin,aabbWorldSpaceMax);
-
        btVector3 halfExtents = (aabbWorldSpaceMax-aabbWorldSpaceMin)*btScalar(0.5);
        btVector3 softBodyCenter = (aabbWorldSpaceMax+aabbWorldSpaceMin)*btScalar(0.5);
 
        btVector3 halfExtents = (aabbWorldSpaceMax-aabbWorldSpaceMin)*btScalar(0.5);
        btVector3 softBodyCenter = (aabbWorldSpaceMax+aabbWorldSpaceMin)*btScalar(0.5);
 
-       btTransform     triInverse = m_triBody->getWorldTransform().inverse();
-
-       btMatrix3x3 abs_b = triInverse.getBasis().absolute();  
-       btPoint3 center = softBodyCenter + triInverse.getOrigin();
-
-       btVector3 extent = btVector3(abs_b[0].dot(halfExtents),
-                  abs_b[1].dot(halfExtents),
-                 abs_b[2].dot(halfExtents));
-//     extent += btVector3(getMargin(),getMargin(),getMargin());
-
-       m_aabbMin = center - extent;
-       m_aabbMax = center + extent;
-
-       btScalar extraMargin = collisionMarginTriangle+btScalar(BT_SOFTBODY_TRIANGLE_EXTRUSION);
-       btVector3 extra(extraMargin,extraMargin,extraMargin);
-
-       m_aabbMax += extra;
-       m_aabbMin -= extra;
-
-/*     btVector3 extra(2,2,2);
-       m_aabbMin = aabbWorldSpaceMin-extra;
-       m_aabbMax = aabbWorldSpaceMax+extra;
-*/
+       btTransform softTransform;
+       softTransform.setIdentity();
+       softTransform.setOrigin(softBodyCenter);
 
 
+       btTransform convexInTriangleSpace;
+       convexInTriangleSpace = m_triBody->getWorldTransform().inverse() * softTransform;
+       btTransformAabb(halfExtents,m_collisionMarginTriangle,convexInTriangleSpace,m_aabbMin,m_aabbMax);
 }
 
 void btSoftBodyConcaveCollisionAlgorithm::clearCache()
 }
 
 void btSoftBodyConcaveCollisionAlgorithm::clearCache()