computer graphics input and interaction

14
Computer Graphics Input and Interaction

Upload: wenda

Post on 05-Jan-2016

15 views

Category:

Documents


0 download

DESCRIPTION

Computer Graphics Input and Interaction. Physical Input Devices :. Keyboard Device - used to input characters. Pointing Device - used to indicate locations on the screen. Pointing Devices :. ABSOLUTE POSITIONS from 2D grids of sensors: data tablets, light pens, touch sensitive screens. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Computer Graphics Input and Interaction

Computer GraphicsInput and Interaction

Page 2: Computer Graphics Input and Interaction

Physical Input Devices:

Keyboard Device - used to input characters

Pointing Device - used to indicate locations on the screen

Page 3: Computer Graphics Input and Interaction

Pointing Devices:

• ABSOLUTE POSITIONS from 2D grids of sensors: data tablets, light pens, touch sensitive screens• RELATIVE POSITIONS from movement of the balls: mice & trackballs

• RELATIVE POSITIONS from velocities that are a function of position or pressure joysticks & spaceballs

Page 4: Computer Graphics Input and Interaction

Logical Devices: a view of input from inside the application program

• String - provides ASCII strings

• Locator - provides position in world coordinates

• Pick - returns identifier of an object

• Choice - allows selection from several options

• Dial - provides analog input

• Stroke - returns an array of locations

Page 5: Computer Graphics Input and Interaction

Logical Devices: a view of input from inside the application program

• Measure - what the device returns to the user program

• Trigger - physical input on the device used to signal the computer

Example: Keyboard Input

measure - the string of input characters

trigger - the return or enter key

Page 6: Computer Graphics Input and Interaction

Input Modes: a view of input from inside the application program

• Request mode - measure is not returned until device is triggered

• Sample mode - measure input is immediate when the appropriate function is called

• Event mode - device trigger generates an event, event is placed in an event queue, event may be processed directly or a callback function may be specified to handle the event

Page 7: Computer Graphics Input and Interaction

Using Pointing Devices: types of events

• Move event - generated when mouse is moved while a button is depressed

• Passive move event - generated when mouse is moved, but no button is depressed

• Mouse event - occurs when any mouse button is depressed or released

Page 8: Computer Graphics Input and Interaction

Using Pointing Devices: interacting with the mouse using GLUT

glutMouseFunc(myMouseCallback);

the mouse callback MUST HAVE THIS FORM

void myMouseCallback(int button,

int state,

int x, int y)where button will have a value from this list GLUT_LEFT_BUTTON, GLUT_MIDDLE_BUTTON, GLUT_RIGHT_BUTTON

and state will have a value from this list GLUT_DOWN, GLUT_UP

Page 9: Computer Graphics Input and Interaction

Using Pointing Devices:

Example: code to exit when LMB pressed

void myMouseCallback(int button,

int state, int x, int y){

if (button == GLUT_LEFT_BUTTON &&

state == GLUT_DOWN)

exit():

}

Page 10: Computer Graphics Input and Interaction

Using Pointing Devices:

Example: draw square where LMB pressed,exit when LMB pressed

void myMouseCallback(int button,

int state, int x, int y){

if (button == GLUT_LEFT_BUTTON &&

state == GLUT_DOWN)

drawsquare(x, y);

if (button == GLUT_MIDDLE_BUTTON &&

state == GLUT_DOWN)

exit();

}

Page 11: Computer Graphics Input and Interaction

WINDOW EVENTS: Two useful CALLBACKS in response to window events

glutDisplayFunc(myDisplayCallback)Where myDisplayCallback() has no parameters. This function must handle all drawing (or object redefinition) commands.

glutReshapeFunc(myReshapeCallback)Callback has the form myReshapeCallback(int w, int h) with w and h representing the new window size in pixels

Page 12: Computer Graphics Input and Interaction

KEYBOARD EVENTS:

The keyboard callback is registered with glutKeyboardFunc(myKeyboardCallback)

Callback has the form

myKeyboardCallback (unsigned char key,

int x, int y)with key being the key depressed and (x,y) being the cursor position in window coordinates at the time the keyboard was triggered

Page 13: Computer Graphics Input and Interaction

MENU EVENTS:

We register a Menu Callback using

int glutCreateMenu(menuCallback)

Individual menu Entries (or options) are created by calls to

glutAddMenuEntry("entry text", const)the first argument is the text that will appear on the menu entry, and the second argument is a unique integer constant value to be passed to the menuCallback when this menu entry is selected at runtime

Page 14: Computer Graphics Input and Interaction

MENU EVENTS:

The callback function has the form

menuCallback (int id)

the id value passed to this callback comes from the second argument to glutAddMenuEntry()

finally, the menu is attached to a mouse button using glutAttachMenu(GLUT_RIGHT_BUTTON)