*/
@Override
public void preStep(float invDT) {
Matrix2f rot1 = new Matrix2f(body1.getRotation());
Matrix2f rot2 = new Matrix2f(body2.getRotation());
Vector2f r1 = MathUtil.mul(rot1, anchor1);
Vector2f r2 = MathUtil.mul(rot2, anchor2);
Vector2f p1 = new Vector2f(body1.getPosition());
p1.add(r1);
Vector2f p2 = new Vector2f(body2.getPosition());
p2.add(r2);
Vector2f dp = new Vector2f(p2);
dp.sub(p1);
float length = dp.length();
// dp.scale(1.0f/length);
Vector2f V = new Vector2f((float) Math.cos(originalAngle
+ body1.getRotation()), (float) Math.sin(originalAngle
+ body1.getRotation()));
Vector2f ndp = new Vector2f(dp);
ndp.normalise();
float torq = (float) Math.asin(MathUtil.cross(ndp, V))
* compressConstant / invDT;
float P = torq / length;
Vector2f n = new Vector2f(ndp.y, -ndp.x);
Vector2f impulse = new Vector2f(n);
impulse.scale(P);
if (!body1.isStatic()) {
Vector2f accum1 = new Vector2f(impulse);
accum1.scale(body1.getInvMass());
body1.adjustVelocity(accum1);
body1.adjustAngularVelocity((body1.getInvI() * MathUtil.cross(dp,
impulse)));
}
if (!body2.isStatic()) {
Vector2f accum2 = new Vector2f(impulse);
accum2.scale(-body2.getInvMass());
body2.adjustVelocity(accum2);
body2.adjustAngularVelocity(-(body2.getInvI() * MathUtil.cross(r2,
impulse)));
}
}