I've implemented a soft-body in box2d and so far I am impressed with how easy it was; however, because of how distance joints work, I can't figure out how to make it less bouncy without basically turning it into liquid.
The soft-body is similar to what is described in http://panoramix.ift.uni.wroc.pl/~maq/s ... ftbody.pdf, but using distance joints and the volume calculation function is different.
Will I have to manually check for a collision and adjust the velocity?
Also, I've attached all the joint code, but the only code that is in question is:
The soft-body is similar to what is described in http://panoramix.ift.uni.wroc.pl/~maq/s ... ftbody.pdf, but using distance joints and the volume calculation function is different.
Will I have to manually check for a collision and adjust the velocity?
Also, I've attached all the joint code, but the only code that is in question is:
Code:
virtual void SolveVelocityConstraints(const b2TimeStep &step) {
b2DistanceJoint::SolveVelocityConstraints(step);
... // make sure area calculation is up to date
b2Body* b1 = m_bodyA;
b2Body* b2 = m_bodyB;
const float Pressure = m_Parameters->m_Pressure;
const float area = m_Parameters->m_Area;
// get distance between masses and the length
const b2Vec2 d = GetAnchorA() - GetAnchorB();
const float length = d.Length();
// calculate pressure value
const float pressurev = length * Pressure / area;
// calculate the normal of the spring
b2Vec2 normal( d.y / length, -d.x / length );
// calculate momentum
const float Mx = (normal.x * pressurev) * step.dt;
const float My = (normal.y * pressurev) * step.dt;
// apply pressure to connected bodies
const float invMass1 = b1->m_invMass;
b1->m_linearVelocity.x += invMass1 * Mx;
b1->m_linearVelocity.y += invMass1 * My;
const float invMass2 = b2->m_invMass;
b2->m_linearVelocity.x += invMass2 * Mx;
b2->m_linearVelocity.y += invMass2 * My;
}
b2DistanceJoint::SolveVelocityConstraints(step);
... // make sure area calculation is up to date
b2Body* b1 = m_bodyA;
b2Body* b2 = m_bodyB;
const float Pressure = m_Parameters->m_Pressure;
const float area = m_Parameters->m_Area;
// get distance between masses and the length
const b2Vec2 d = GetAnchorA() - GetAnchorB();
const float length = d.Length();
// calculate pressure value
const float pressurev = length * Pressure / area;
// calculate the normal of the spring
b2Vec2 normal( d.y / length, -d.x / length );
// calculate momentum
const float Mx = (normal.x * pressurev) * step.dt;
const float My = (normal.y * pressurev) * step.dt;
// apply pressure to connected bodies
const float invMass1 = b1->m_invMass;
b1->m_linearVelocity.x += invMass1 * Mx;
b1->m_linearVelocity.y += invMass1 * My;
const float invMass2 = b2->m_invMass;
b2->m_linearVelocity.x += invMass2 * Mx;
b2->m_linearVelocity.y += invMass2 * My;
}