CIS 41
Computer Graphics
Chapter 3 - Input and Interaction


Interaction

GLUT

Input Devices

Physical Devices

Physical Pointing Devices

Logical Devices

A Taxonomy of Logical Input Devices
  1. String Device that returns strings (sequences of characters) to the program
  2. Locator Provides a position
  3. Pick Returns the identifier of an object on the display
  4. Choice Allows the user to select from a set of choices
  5. Valuators Provides (analog) input to the program
  6. Stroke Returns an array of locations
Input Modes
Some terminology:

Input modes are distinguished by the relationship between the measure and trigger:

Client-Server Model

Display Processors

Immediate Mode

Retained-Mode

Display Lists in OpenGL

The Matrix Stacks

static void display(void) {
    glClear (GL_COLOR_BUFFER_BIT);
    glColor3f(0, 0, 1);
    glBegin(GL_POLYGON);
        glVertex2f(-.5, -.5);
        glVertex2f(.5, -.5);
        glVertex2f(.5, .5);
        glVertex2f(-.5, .5);
    glEnd();
    glRotatef(22, 0, 0, 1);
    glCallList(MY_SQUARE);
    glRotatef(22, 0, 0, 1);
    glBegin(GL_POLYGON);        // Will display in red
        glVertex2f(-.5, -.5);
        glVertex2f(.5, -.5);
        glVertex2f(.5, .5);
        glVertex2f(-.5, .5);
    glEnd();
    glFlush();
}

void init() {
    glClearColor(1.0, 1.0, 1.0, 1.0);
    glNewList(MY_SQUARE, GL_COMPILE);
        glPushAttrib(GL_ALL_ATTRIB_BITS);
        glPushMatrix();
        glBegin(GL_POLYGON);
            glColor3f(1, 0, 0);
            glVertex2f(-.5, -.5);
            glVertex2f(.5, -.5);
            glVertex2f(.5, .5);
            glVertex2f(-.5, .5);
        glEnd();
        glPopMatrix();
        glPopAttrib();
    glEndList();
}

Display Lists and Modelling

static void display(void) {
    glClear (GL_COLOR_BUFFER_BIT);
    glCallList(CAR_BODY);
    glFlush();
}

void init() {
    GLfloat c = (M_PI/180);

    glClearColor(1.0, 1.0, 1.0, 1.0);
    glNewList(WHEEL, GL_COMPILE);
        glPushAttrib(GL_ALL_ATTRIB_BITS);
        glPushMatrix();
        glColor3f(0, 0, 0);
        for (GLint i = 0; i <= 360;  i += 10) {
            glBegin(GL_TRIANGLES);
                glVertex2i(0, 0);
                glVertex2f(.1 *cos(c * i), .1*sin(c * i));
                glVertex2f(.1*cos(c * (i+10)), .1*sin(c * (i+10)));
            glEnd();
        }
        glPopMatrix();
        glPopAttrib();
    glEndList();

    glNewList(CAR_BODY, GL_COMPILE);
        glPushAttrib(GL_ALL_ATTRIB_BITS);
        glPushMatrix();
        glBegin(GL_POLYGON);
            glColor3f(1, 0, 0);
            glVertex2f(-.5, -.5);
            glVertex2f(.5, -.5);
            glVertex2f(.5, .5);
            glVertex2f(-.5, .5);
        glEnd();
        glTranslatef(.5, -.5, 0);
        glCallList(WHEEL);
        glTranslatef(-1, 0, 0);
        glCallList(WHEEL);
        glPopMatrix();
        glPopAttrib();
    glEndList();
}

Convenience Functions for List Maintenance and Invocation

Programming with Event-Driven Input

Working with the Mouse

Additional Callbacks

Callback-Related Coordinates

Window Management

Menus

c_menu = glutCreateMenu(color_menu);
glutAddMenuEntry("Black",0);
glutAddMenuEntry("Red",1);
glutAddMenuEntry("Green",2);
glutAddMenuEntry("Blue",3);
glutAddMenuEntry("Cyan",4);
glutAddMenuEntry("Magenta",5);
glutAddMenuEntry("Yellow",6);
glutAddMenuEntry("White",7);

glutCreateMenu(main_menu);
glutAddMenuEntry("new polygon", 1);
glutAddMenuEntry("end polygon", 2);
glutAddMenuEntry("delete polygon", 3);
glutAddMenuEntry("move polygon", 4);
glutAddMenuEntry("quit",5);
glutAddSubMenu("Colors", c_menu);
glutAttachMenu(GLUT_MIDDLE_BUTTON);

...

void color_menu(int index) {...}
void main_menu(int index) {...}
	 	

The square Program of the Text

Redisplaying the Squares on Redraw

Picking

Process of selecting an object (not simply a position) on the screen.

The Viewport

Picking via Selection in OpenGL - The pick Program

Breakdown of the Code

void processHits (GLint hits, GLuint buffer[]) {
   unsigned int i, j;
   GLuint names, *ptr;

   printf ("hits = %d\n", hits);
   ptr = (GLuint *) buffer;
   for (i = 0; i < hits; i++) { /*  for each hit  */
      names = *ptr;
      ptr+=3;
      for (j = 0; j < names; j++) { /*  for each name */
         if(*ptr==1) printf ("red rectangle\n");
         else printf ("blue rectangle\n");
         ptr++;
      }
      printf ("\n");
   }
}

The CAD Program

Working With Shape Objects

Animation

Double Buffering

What if image redraw is very time-consuming?

Timers

Logic Operations

Rubberbanding using XOR Logic Operation

Code for Chapter 3