How to control cloth elasticity?

User avatar
LangFox
Posts: 4
Joined: Tue Dec 29, 2009 2:07 pm

How to control cloth elasticity?

Post by LangFox »

cloth.jpg
Hi, all

I'm trying to present cloth. What I have done is:
1, Use btSoftBodyHelpers::CreateFromTriMesh to create a softbody and add it to the SoftRigidDynamicsWorld.
2, Fix the first two nodes by setMass(index, 0).
3, On every frame, updating the fixed nodes' position when moving.

Code: Select all

m_SoftBody->m_nodes[index].m_x = btVector3(newPos.x, newPos.y, newPos.z);
4, Add force to softbody which faces the character.

For now, it works. But the cloth is extended like some kind of elasticity. I have tried the parameters in m_cfg, but none could remove it. Any idea?
You do not have the required permissions to view the files attached to this post.
kickvb
Posts: 6
Joined: Wed Dec 09, 2009 5:05 pm

Re: How to control cloth elasticity?

Post by kickvb »

It would probably be better if you attach your cloth to a kinematic body instead of making it static and updating its position every frame. Static/dynamic objects don't like being re-positioned, kinematic objects are intended for that purpose.
User avatar
LangFox
Posts: 4
Joined: Tue Dec 29, 2009 2:07 pm

Re: How to control cloth elasticity?

Post by LangFox »

OK, I think you are right. Then how to attach softbody to kinematic body? I tried this:

Code: Select all

btTransform startTransform;
startTransform.setFromOpenGLMatrix(glm::address(transform));
btDefaultMotionState* myMotionState = new btDefaultMotionState(startTransform);
btRigidBody::btRigidBodyConstructionInfo cInfo(mass, myMotionState, NULL, localInertia);
btRigidBody* body = new btRigidBody(cInfo);
body->setCollisionFlags( body->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT); 
body->setActivationState(DISABLE_DEACTIVATION);
m_SoftRigidDynamicsWorld()->addRigidBody(body);
m_SoftBody->appendAnchor(index, body);
But the cloth just hangs on its origin position, not the anchor's position.
User avatar
LangFox
Posts: 4
Joined: Tue Dec 29, 2009 2:07 pm

Re: How to control cloth elasticity?

Post by LangFox »

ok, I found the reason: cInfo must have a collision shape.
Now the cloth can hang on anchors.
Thanks.