Game Development Reference

In-Depth Information

We can solve this problem to some extent by forcing small time periods for the

update, or we could use several smaller updates for each frame we render. Neither

approach buys us much, however. The kinds of spring stiffness needed to simulate

realistic collisions just aren't possible in the framework we have built so far.

Instead we will have to use alternative methods to simulate collisions and other

hard constraints.

6.3.2

F
AKING
S
TIFF
S
PRINGS

This section will implement a more advanced spring force generator which uses a

different method of calculating spring forces to help with stiff springs. It provides a

“cheat” for making stiff springs work. In the remaining chapters of this topic we will

look at more robust techniques for simulating constraints, collisions, and contacts.

You can safely skip this section: the mathematics are not explored in detail; there

are restrictions on where we can use fake stiff springs, and the formulation is not

always guaranteed to work. In particular, while they can fake the effect reasonably on

their own, when more than one is combined, or when a series of objects is connected

to them, the physical inaccuracies in the calculation can interact nastily and cause

serious problems. In the right situation, however, they can be a useful addition to

your library of force generators.

We can solve this problem to some extent by predicting how the force will change

over the time interval, and use that to generate an average force. This is sometimes

called an “implicit spring,” and a physics engine that can deal with varying forces in

this way is implicit, or semi-implicit. For reasons we'll see at the end of the chapter, we

can't do anything more than fake the correct behavior, so I have called this approach

“fake implicit force generation.”

In order to work out the force equation, we need to understand how a spring will

act if left to its own devices.

Harmonic Motion

A spring that had no friction or drag would oscillate forever. If we stretched such

a spring to a particular extension and then released it, its ends would accelerate to-

gether. It would pass its natural length and begin to compress. When its ends were

compressed to exactly the same degree as they were extended initially, it would begin

to accelerate apart. This would continue forever. This kind of motion is well known

to physicists; it is called “simple harmonic motion.” The position of one end of the

spring obeys the equation

p

χ
2
p

=−

[6.3]

where
k
is the spring constant,
m
is the mass of the object, and
χ
is defined, for

convenience in the following equations, to be

k

m

χ

=