Interaction

Plan

Functions useful for interactivity

glutKeyboardFunc(void (*func)(unsigned char, int, int));
glutKeyboardUpFunc(void (*func)(unsigned char, int, int));
glutSpecialFunc(void (*func)(unsigned char, int, int));
glutSpecialUpFunc(void (*func)(unsigned char, int, int));
glutMouseFunc(void (*func)(int, int, int, int));
glutMotionFunc( void (*func)(int, int));
glutPassiveMotionFunc( void (*func)(int, int));
int glutGetModifiers(void);

Topics

Demos

Exercise

Build a program that allows you to rotate the teddy bear around the y axis using the arrow keys, where it starts rotating right when you press the right arrow down and stops when you release the right arrow, and similarly, it rotates left when you press the left arrow button and stops when you release.

Here is a starting point

Here is a solution to the lab

For extra credit, use "control+right" to rotate right, and "control+left" to rotate left. To solve this, you have to understand about masks and integer representation. The result of glutGetModifiers() is an integer that only has three useful bits in it, one for each modifier key. Suppose you care about the "ALT" key. The magic constant, called a "mask," GLUT_ACTIVE_ATL corresponds to the bit that tells whether the ALT key is down. The following expression is the bitwise AND of the mask with the integer, and so it is zero (false) iff the ALT key is up and non-zero (true) iff the ALT key is down:

glutGetModifiers() & GLUT_ACTIVE_ALT

Here is a solution for extra credit


Or, design a GUI for an airplane or flight simulator.

Written by Scott D. Anderson
scott.anderson@acm.org
Creative Commons License
This work is licensed under a Creative Commons License.

Valid HTML 4.01!