Game Development Reference
In-Depth Information
magnitude = springConstant * (restLength - magnitude);
// Calculate the final force and apply it.
force.normalize();
force *= -magnitude;
}
I have added a factory function to this class as well to allow us to easily connect two
objects with a bungee.
This implementation assumes that the elastic connects to two objects. In exactly
the same way as for the simple spring generator, we could create a version of the code
that connects an object to a fixed anchor point in space. The modifications we would
need are exactly the same as we saw earlier, so I will not write them out in longhand
again. There is a sample implementation of an anchored bungee generator on the CD.
6.2.4
AB UOYANCY F ORCE G ENERATOR
A buoyancy force is what keeps an object afloat. Archimedes first worked out that the
buoyancy force is equal to the weight of the water that an object displaces.
The first part of figure 6.3 shows a block submerged in the water. The block has a
mass of 0.5 kg. Pure water has a density of 1000 kg/m 3 ; in other words, a cubic meter
of water has a mass of about one metric ton. The block in the figure has a volume of
0.001 m 3 , so it is displacing the same amount of water. The mass of this water would
therefore be 1 kg.
Weight isn't the same as mass in physics. Mass is the property of an object that
makes it resist acceleration. The mass of an object will always be the same. We i g h t is
the force that gravity exerts on an object. As we have already seen, force is given by
the equation
f
=
mg
F IGURE 6.3
A buoyant block submerged and partially submerged.