I'm trying to implement a frictional constraint using position based dynamics, but it is only half working. I am using the formulation in the paper "Unified Particle Physics for Real-Time Applications".
Here is my implementation:
Particle *np = particle->nbs[j].neighbour;
vec3 r = particle->x - np->x;
float r_length = glm::length(r);
float distDiff = r_length - restDistance;
if(distDiff >= 0 ) continue;
//Frictional Constraint
vec3 n = r/r_length;
vec3 xxi = particle->x - xi[particle->getIndex()];
vec3 xxj = np->x - xi[np->getIndex()];
vec3 tangentialDisplacement = (xxi - xxj) - glm::dot(xxi - xxj, n) * n;
float td_length = glm::length(tangentialDisplacement);
float genMass = ( imass / (imass + imass) );
if(td_length < (staticFriciton * distDiff)){
particle->x += genMass * tangentialDisplacement;
np->x += -genMass * tangentialDisplacement;
}else{
float upper = kineticFriction * distDiff;
particle->x += genMass * tangentialDisplacement * std::min(upper/td_length, 1.f);
np->x += -genMass * tangentialDisplacement * std::min(upper/td_length, 1.f);
}
↧