220 likes | 565 Views
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.
E N D
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 • RELATIVE POSITIONSfrom movement of the balls: mice & trackballs • RELATIVE POSITIONSfrom velocities that are a function of position or pressure joysticks & spaceballs
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
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
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
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
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
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(): }
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(); }
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
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
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
MENU EVENTS: The callback function has the form menuCallback (int id) the id value passed to this callback comes from the second argument toglutAddMenuEntry() finally, the menu is attached to a mouse button usingglutAttachMenu(GLUT_RIGHT_BUTTON)