问题描述:

I have two cubs in a bullet softbody simulation (example of how I make such a cube below). How can I constrain them so that is it like the two cubes were 'glued' together on a face?

const btVector3 c[]={

btVector3(-1,-1,-1),

btVector3(+1,-1,-1),

btVector3(-1,+1,-1),

btVector3(+1,+1,-1),

btVector3(-1,-1,+1),

btVector3(+1,-1,+1),

btVector3(-1,+1,+1),

btVector3(+1,+1,+1)

};

btSoftBody* psb=btSoftBodyHelpers::CreateFromConvexHull(pdemo->m_softBodyWorldInfo,c,8, true);

I found this thread where the OP asks about a "one-way vertex-to-vertex joint". I'm looking for a similar (but two-way) joint.

网友答案:

What kind of interaction do you want between the two objects? Different approaches will likely lead to different results. Also keep in mind that you're going to need a very high iteration number and small time step for the solver to be able to always keep the objects glued.

I suggest you build a single, heterogeneous, soft body by using different masses for the nodes and stiffness values for the links.

const btVector3 c[] = 
{
    btVector3(+1,-1,-1),
    btVector3(+1,+1,-1),
    btVector3(+1,-1,+1),
    btVector3(+1,+1,+1),
    btVector3(-1,-1,-1),
    btVector3(-1,-1,+1),
    btVector3(-1,+1,+1),
    btVector3(-1,+1,-1),
    btVector3(+2,-1,-1), // "Other" cube starts here
    btVector3(+2,+1,-1),
    btVector3(+2,-1,+1),
    btVector3(+2,+1,+1)
};

// Masses, should be tuned depending on gravity/timestep
const btScalar m[] = 
{
    0.1f,
    0.1f,
    0.1f,
    0.1f,
    0.1f,
    0.1f,
    0.1f,
    0.1f,
    0.1f,
    0.1f,
    0.1f,
    0.1f
};

btSoftBody* psb = new btSoftBody(pdemo->m_softBodyWorldInfo,12,c,m);

// VERY stiff material
btSoftBody::Material aMat;
aMat.m_kLST = 1; // Linear stiffness coefficient [0,1]
aMat.m_kAST = 0; // Area/Angular stiffness coefficient [0,1]
aMat.m_kVST = 1; // Volume stiffness coefficient [0,1]

// Softer material
btSoftBody::Material bMat;
bMat.m_kLST = 0.5f; // Linear stiffness coefficient [0,1]
bMat.m_kAST = 0; // Area/Angular stiffness coefficient [0,1]
bMat.m_kVST = 0.5f; // Volume stiffness coefficient [0,1]

for(int i=0; i < 12; ++i)
{
    for(int j = i + 1; j < 12; ++j)
    {
        // If either node has x==+2, use softer material
        psb->appendLink(i,j, (i > 7 || j > 7) ? &bMat : &aMat, false);
    }
}   

This should get you started. Good luck!

相关阅读:
Top