The example program allows the user to rotate the dinosaur while moving the mouse by holding down the first mouse button. We record the current angle of rotation whenever a mouse button state changes. As the mouse moves while the first mouse button is held down, the angle is recalculated. A recalcModelView flag is set indicating the scene should be redrawn with the new angle.
When there is a lull in events, the model-view matrix is recalculated and then the needRedraw flag is set, forcing a redraw. The recalcModelView flag is cleared. As discussed earlier, recalculating the model-view is done by popping off the current top matrix using glPopMatrix and pushing on a new matrix. This new matrix is composed with a rotation matrix using glRotatef to reflect the new absolute angle of rotation. An alternative approach would be to multiply the current matrix by a rotation matrix reflecting the change in angle of rotation. But such a relative approach to rotation can lead to inaccurate rotations due to accumulated floating point round-off errors.