Game Development Reference
In-Depth Information
// Calculate the resulting acceleration and therefore the force
Vector3 accel = (target - position) * (1.0f / duration*duration) -
particle->getVelocity() * duration;
particle->addForce(accel * particle->getMass());
}
The force generator looks like the anchored regular spring generator we created ear-
lier in the chapter, with one critical difference: it no longer has a natural spring length.
This, and the fact that we have used an anchored generator rather than a spring ca-
pable of attaching two objects, is a result of some of the mathematics used here. The
consequence is that we must always have a rest length of zero.
Zero Rest Lengths
If a spring has a zero rest length, then any displacement of one end of the spring results
in extension of the spring. If we fix one end of the spring, then there will always be a
force in the direction of the anchored end.
For a spring where both ends of the spring are allowed to move, the direction of
the force is much more difficult to determine. The previous formulae assume that the
force can be expressed in terms of the location of the object only. If we didn't anchor
the spring, then we would have to include the motion of the other end of the spring
in the equation, which would make it insoluble.
A similar problem occurs if we anchor one end but use a non-zero rest length. In
one dimension a non-zero rest length is equivalent to moving the equilibrium point
along a bit, as shown in figure 6.6. The same is true in three dimensions, but because
the spring is allowed to swivel freely, this equilibrium point is now in motion with the
same problems as for a non-anchored spring.
So the equations only work well for keeping an object at a predetermined, fixed
location. Just as for the previous anchored springs, we can move this location manu-
allyfromframetoframe,aslongaswedon'texpecttheforcegeneratortocopewith
the motion in its prediction.
F IGURE 6.6
The rest length and the equilibrium position.
Search Nedrilad ::




Custom Search