Thanks, you gave me a good hint, actually btSoftBody::translate was used incorrectly by me (my calculations were a bit offset). Anyway even with this fixed using links didn't work. I spend all day and night trying to fix this, but eventually I found a thread in the forum stating that you could use appendAnchor with a "dummy" rigid-body to link between two soft bodys. I did so, and it works way better than using links! However, it still isn't perfect, but I quess using/debugging anchors is a lot easier, so lets go.. this is what it looks like now:
Well, its not perfect, but way to go.. It still makes me wonder why the anchor stretches? I have set kAHR to 1.0, I even tried hard-coding the kAHR-value to 1.0. Could there be any reason for this? Here is my code:
Code: Select all
void CSoftPhysic::CreateLink(int ClothID, int RopeID, int RopeNode)
{
//get soft bodys
btSoftBody* sb1 = m_Cloths[ClothID].GetSoftBody();
btSoftBody* sb2 = m_Ropes[RopeID].GetSoftBody();
//translate patch to rope
btVector3 pos = btVector3(m_Cloths[ClothID].GetPosition().x, m_Cloths[ClothID].GetPosition().y, m_Cloths[ClothID].GetPosition().z);
btVector3 dist = sb2->m_nodes[RopeNode].m_x - pos;
sb1->translate(dist);
//create dummy rigid body1
m_GroundShape = new btSphereShape(0.01f);
btDefaultMotionState* groundMotionState = new btDefaultMotionState(btTransform(btQuaternion(0,0,0,1),btVector3(0,0,0)));
btRigidBody::btRigidBodyConstructionInfo groundRigidBodyCI(0,groundMotionState,m_GroundShape,btVector3(0,0,0));
btRigidBody* GroundRigidBody = new btRigidBody(groundRigidBodyCI);
GroundRigidBody->setMassProps(10, btVector3(0.0, 0.0, 0.0));
//translate rb1 to rope
pos = GroundRigidBody->getWorldTransform().getOrigin();
dist = sb2->m_nodes[RopeNode+1].m_x - pos;
GroundRigidBody->translate(dist);
//append anchor between 1st node->rb->rope
sb1->appendAnchor(11, GroundRigidBody, btVector3(0, 0, 0), true);
sb2->appendAnchor(RopeNode+1, GroundRigidBody, btVector3(0, 0, 0), true);
//create second rb
btDefaultMotionState* groundMotionState2 = new btDefaultMotionState(btTransform(btQuaternion(0,0,0,1),btVector3(0,0,0)));
btRigidBody::btRigidBodyConstructionInfo groundRigidBodyCI2(0,groundMotionState2,m_GroundShape,btVector3(0,0,0));
btRigidBody* GroundRigidBody2 = new btRigidBody(groundRigidBodyCI2);
GroundRigidBody2->setMassProps(1, btVector3(0.0, 0.0, 0.0));
//translate rb to rope
pos = GroundRigidBody2->getWorldTransform().getOrigin();
dist = sb2->m_nodes[RopeNode].m_x - pos;
GroundRigidBody2->translate(dist);
//append anchor between 2nd patch node->rb2->rope
sb1->appendAnchor(sb1->m_nodes.size()-1, GroundRigidBody2, btVector3(0, 0, 0), true);
sb2->appendAnchor(RopeNode, GroundRigidBody2, btVector3(0, 0, 0), true);
}
Does anyone sees a mistake here? Well at least this time its not as bad, because, using a simple hack called every frame for every patch, I can make the flags at least seem to be fixed to the rope:
Code: Select all
btVector3 pos1 = psb->m_nodes[11].m_x;
btVector3 pos2 = m_Ropes[0].GetSoftBody()->m_nodes[i].m_x;
btVector3 dist = pos2 - pos1;
ii->SetPosition(dist.x(), 1+dist.y(), dist.z());
It's almost like I'm expecting it, but as you might be able to see the flags second node isn't always aligned to the rope. If the anchor wouldn stretch, neither this "hack" nor that issue would be needed. Any ideas?
However, there is a second issue that has nothing to do with the one above. Though the current state isn't perfect, its acceptable to work with. So comes my next problem: For now I'm using a 24 units long rope with 16 segments. The flags are fixed on each two following nodes: 0-1, 1-2, 2-3, .. with their own corners (node 11 and node size-1). However I want the flags to be fixed on all of upper nodes, not only on the upper corners. So I tried increasing the resolution of the rope (my flags resolution is 12*16, so that equals to 192 res for the rope):
As you can see, the rope stretches like crazy (ignore the bunch of flags on the right side of the rope, that will be fixed afterwards). What can I do to increase the resolution of the rope, while keeping the same length AND having it stretch similarly?