hide random home http://www.sgi.com/tech/openGL/mjk.xlib/subsubsection3_2_5_3.html (Silicon Surf Promotional CD, 01/1995)



Next: 2.5.4 Quitting Up: 2.5 Event Dispatching Previous: 2.5.2 Window Resizing

2.5.3 Handling Input

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.


mjk@asd.sgi.com
Wed Oct 19 18:11:46 PDT 1994