Tom Kelliher, CS 320
Feb. 14, 2001
Read 3.4, 3.6--7.
Project lab.
Display lists, menus, picking.
Physical devices: Keyboard, mouse, trackball, data tablet, light pen, touch screen, joy stick.
How do mice, light pens work?
Pointing device necessary to interact with graphics.
What about 3-D interaction? (Space ball, data gloves)
Terminology:
Interaction modes:
Measure not returned until trigger.
Advantages/disadvantages.
Measure returned any time.
Advantages/disadvantages.
Queue of (trigger, measure) pairs. Asynchronous.
Advantages/disadvantages.
OpenGL, callbacks, and glutMainLoop().
glutMouseFunc(pointerToMouseCallbackFunction)
void MouseCallbackFunction(int button, int action, int x, int y)
GLUT_LEFT_BUTTON, etc.
GLUT_UP, GLUT_DOWN.
x and y are window-relative coordinates.
// ...
glutMouseFunc(mouse);
// ...
void mouse(int btn, int action, int x, int y)
{
if (btn == GLUT_LEFT_BUTTON && action == GLUT_DOWN)
{
myInit(rows, cols, 1);
visit(1, 1);
glutPostRedisplay();
}
else if (btn == GLUT_RIGHT_BUTTON && action == GLUT_UP)
exit(0);
}
glutMotionFunc(pointerToMotionFunction)
void MotionFunction(int x, int y)
glutKeyboardFunc(pointerToKeyboardFunction)
void KeyboardFunction(unsigned char key, int x, int y)
key is ASCII of key depressed.
glutSpecialFunc() for non-ASCII keys.
#define ESC 0x1b
// ...
glutKeyboardFunc(keyboard);
// ...
void keyboard(unsigned char key, int x, int y)
{
switch (key)
{
case 'w':
case 'W':
printf("The Clinton people took all these keys.\n");
break;
case ESC:
exit(0);
break;
case '!':
globalThermonuclearWar();
// Not reached.
break;
// ...
others:
fatal("Un-recognized key.\n");
break;
}
}
glutDisplayFunc(pointerToDisplayFunction)
void DisplayFunction(void)
glutPostRedisplay().
glutReshapeFunc(pointerToReshapeFunction)
void ReshapeFunction(GLsizei w, GLsizei h)
As previously discussed, have to reconcile clipping region aspect ratio to window aspect ratio.