
226 Chapter 10 Laws of Motion for Rigid Bodies
// Calculate the vector of the spring.
Vector3 force = lws - ows;
// Calculate the magnitude of the force.
real magnitude = force.magnitude();
magnitude = real_abs(magnitude - restLength);
magnitude *= springConstant;
// Calculate the final force and apply it.
force.normalize();
force *= -magnitude;
body->addForceAtPoint(force, lws);
}
Torque Generators
We c ould follow the lead of the force generators and create a set of torque generators.
They fit into the same force generator structure that we’v e used so far: calling the rigid
body’s
addTorque method. You can use this to constantly drive a rotating object, ...