diff --git a/examples/DeformableDemo/DeformableSelfCollision.cpp b/examples/DeformableDemo/DeformableSelfCollision.cpp index 44da9d542..7b8fd9c3a 100644 --- a/examples/DeformableDemo/DeformableSelfCollision.cpp +++ b/examples/DeformableDemo/DeformableSelfCollision.cpp @@ -156,6 +156,7 @@ void DeformableSelfCollision::addCloth(btVector3 origin) psb->getCollisionShape()->setMargin(0.0075); psb->generateBendingConstraints(2); + psb->generateBendingConstraints(2); psb->setTotalMass(.5); psb->m_cfg.kKHR = 1; // collision hardness with kinematic objects psb->m_cfg.kCHR = 1; // collision hardness with rigid body diff --git a/src/BulletSoftBody/btSoftBodyHelpers.cpp b/src/BulletSoftBody/btSoftBodyHelpers.cpp index 9115e6333..9f64de77d 100644 --- a/src/BulletSoftBody/btSoftBodyHelpers.cpp +++ b/src/BulletSoftBody/btSoftBodyHelpers.cpp @@ -1510,9 +1510,9 @@ void btSoftBodyHelpers::getBarycentricWeights(const btVector3& a, const btVector btScalar d20 = btDot(v2, v0); btScalar d21 = btDot(v2, v1); btScalar invDenom = 1.0 / (d00 * d11 - d01 * d01); - bary[0] = (d11 * d20 - d01 * d21) * invDenom; - bary[1] = (d00 * d21 - d01 * d20) * invDenom; - bary[2] = 1.0 - bary[0] - bary[1]; + bary[1] = (d11 * d20 - d01 * d21) * invDenom; + bary[2] = (d00 * d21 - d01 * d20) * invDenom; + bary[0] = 1.0 - bary[1] - bary[2]; bary[3] = 0; } @@ -1575,7 +1575,7 @@ void btSoftBodyHelpers::extrapolateBarycentricWeights(btSoftBody* psb) btVector4 optimal_bary; btScalar min_bary_weight = -1e3; btAlignedObjectArray optimal_parents; - btScalar dist; + btScalar dist, optimal_dist; for (int j = 0; j < psb->m_faces.size(); ++j) { const btSoftBody::Face& f = psb->m_faces[j]; @@ -1597,6 +1597,7 @@ void btSoftBodyHelpers::extrapolateBarycentricWeights(btSoftBody* psb) parents.push_back(f.m_n[2]); optimal_parents = parents; optimal_bary = bary; + optimal_dist = dist; min_bary_weight = new_min_bary_weight; // stop searching if the projected p is inside the triangle at hand if (bary[0]>=0. && bary[1]>=0. && bary[2]>=0.) @@ -1607,6 +1608,6 @@ void btSoftBodyHelpers::extrapolateBarycentricWeights(btSoftBody* psb) } psb->m_renderNodesInterpolationWeights[i] = optimal_bary; psb->m_renderNodesParents[i] = optimal_parents; - psb->m_z[i] = dist; + psb->m_z[i] = optimal_dist; } } diff --git a/src/BulletSoftBody/btSoftBodyInternals.h b/src/BulletSoftBody/btSoftBodyInternals.h index 5a29fe3aa..e08f650b6 100644 --- a/src/BulletSoftBody/btSoftBodyInternals.h +++ b/src/BulletSoftBody/btSoftBodyInternals.h @@ -78,9 +78,9 @@ static SIMD_FORCE_INLINE bool proximityTest(const btVector3& x1, const btVector3 btScalar det = a11*a22 - a12*a12; if (det < SIMD_EPSILON) return false; - btScalar w1 = (b1*a22-b2*a12)/det; - btScalar w2 = (b2*a11-b1*a12)/det; - btScalar w3 = 1-w1-w2; + btScalar w2 = (b1*a22-b2*a12)/det; + btScalar w3 = (b2*a11-b1*a12)/det; + btScalar w1 = 1-w2-w3; btScalar delta = mrg / std::sqrt(0.5*std::abs(x13.cross(x23).safeNorm())); bary = btVector3(w1,w2,w3); for (int i = 0; i < 3; ++i)