Game Development Reference
quaternion. We don't want to do this if we don't have to (such as after every quater-
nion operation) because that's just a waste of time.
I have added a quaternion normalization step in the rigid-body update routine
just after the quaternion is updated by the velocity and before the transform matrix
is created. This ensures that the transform matrix has a valid rotation component.
I admit that this stability fix is a bit contrived. It seemed obvious to me when I
first wrote the integration routine that it was a good spot for the quaternion normal-
ization, and so I added it.
I have included it here more by way of illustration. The normal size of the quater-
nion is an assumption we made early on in the development of the engine. It is easily
forgotten and has returned to cause strange effects only after we have a completed
engine running for long periods of time. Problems may show up only during QA
(quality assurance) testing, and they can be very subtle. Checking and enforcing your
assumptions in a way that doesn't massacre performance is key to stabilizing and op-
timizing the engine.
I NTERPENETRATION ON S LOPES
The next issue is more significant. Figure 16.1 shows a block resting on a slope. The
slope could be an angled plane or the surface of another object. Gravity is acting in a
F IGURE 16.1
Objects drift down angled planes.