public override float SolveIteration()
{
float lambda;
Vector3 relativeVelocity;
Vector3.Subtract(ref connectionA.angularVelocity, ref connectionB.angularVelocity, out relativeVelocity);
//Transform the velocity to with the jacobian
Vector3.Dot(ref relativeVelocity, ref hingeAxis, out lambda);
//Add in the constraint space bias velocity
lambda = -lambda + biasVelocity - softness * accumulatedImpulse;
//Transform to an impulse
lambda *= velocityToImpulse;
//Clamp accumulated impulse (can't go negative)
float previousAccumulatedImpulse = accumulatedImpulse;
accumulatedImpulse = MathHelper.Max(accumulatedImpulse + lambda, 0);
lambda = accumulatedImpulse - previousAccumulatedImpulse;
//Apply the impulse
Vector3 impulse;
Vector3.Multiply(ref hingeAxis, lambda, out impulse);
if (connectionA.isDynamic)
{
connectionA.ApplyAngularImpulse(ref impulse);
}
if (connectionB.isDynamic)
{
Vector3.Negate(ref impulse, out impulse);
connectionB.ApplyAngularImpulse(ref impulse);
}
return (Math.Abs(lambda));
}