InteractionHofstra University1 Graphics Programming Input and Interaction.

Slides:



Advertisements
Similar presentations
OpenGL CMSC340 3D Character Design & Animation. What is OpenGL? A low-level graphics library specification designed for use with the C and C++ provides…
Advertisements

CS 4731 Lecture 2: Intro to 2D, 3D, OpenGL and GLUT (Part I) Emmanuel Agu.
Chapter 3: Input and Interaction Instructor: Shih-Shinh Huang 1.
CSC461 Lecture 10: Widgets and Picking Objectives Introduce menus in GLUT Picking –Select objects from the display –Three methods Put things together.
OpenGL (I). What is OpenGL (OGL)? OGL is a 3D graphics & modeling library Can also use it to draw 2D objects.
CSC 461: Lecture 51 CSC461 Lecture 5: Simple OpenGL Program Objectives: Discuss a simple program Discuss a simple program Introduce the OpenGL program.
Objectives Learn to build arbitrary transformation matrices from simple transformations Learn to build arbitrary transformation matrices from simple transformations.
31/1/2006Based on: Angel (4th Edition) & Akeine-Möller & Haines (2nd Edition)1 CSC345: Advanced Graphics & Virtual Environments Lecture 3: Introduction.
InteractionHofstra University1 Graphics Programming Input and Interaction.
1 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 GLUT Callback Functions.
Based on slides created by Edward Angel
CSC461 Lecture 9: GLUT Callbacks Objectives Introduce double buffering for smooth animations Programming event input with GLUT.
CS 480/680 Computer Graphics Programming with Open GL Part 8: Working with Callbacks Dr. Frederick C Harris, Jr. Fall 2011.
Using Graphics Libraries Lecture 3 Mon, Sep 1, 2003.
Introduction to OpenGL and GLUT GLUT. What is OpenGL? An application programming interface (API) A (low-level) Graphics rendering API Generate high-quality.
1 Working with Callbacks Yuanfeng Zhou Shandong University.
COMPUTER GRAPHICS Hochiminh city University of Technology Faculty of Computer Science and Engineering CHAPTER 03: Input & Interaction.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Chapter 3: Input and Interaction.
More on Drawing in OpenGL: Examples CSC 2141 Introduction to Computer Graphics.
WORKING WITH CALLBACKS Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico Angel: Interactive.
Fundamentals of Computer Graphics Part 3 prof.ing.Václav Skala, CSc. University of West Bohemia Plzeň, Czech Republic ©2002 Prepared with Angel,E.: Interactive.
Interaction with Graphics System
Input and Interaction Chapter 3. CS 480/680Chapter 3 -- Input and Interaction2 n Introduction: -We now turn to the development of interactive graphics.
Introduction to Programming 3D Applications CE Lecture 15 Input and interaction in 3D Environments.
School of Computer Science University of Seoul. 1. Interaction 2. Input Devices 3. Clients and Servers 4. Display Lists 5. Programming Event-Driven Input.
Input and Interaction Chapter 3. CS 480/680 2Chapter 3 -- Input and Interaction Introduction: Introduction: We now turn to the development of interactive.
1Computer Graphics Input and Interaction Lecture 8 John Shearer Culture Lab – space 2
CAP 4703 Computer Graphic Methods Prof. Roy Levow Lecture 3.
Input and Interaction Lecture No. 4.
Lecture 3 OpenGL.
1 Input and Interaction. 2 Input Devices Physical input devices Keyboard devices and pointing devices Logical input devices.
Computer Graphics I, Fall 2010 Input and Interaction.
Write a Simple Program with OpenGL & GLUT. Books OpenGL Programming Guide (Red-book) OpenGL Reference Manual (Blue-book) OpenGL Super Bible
Introduction to GL Geb Thomas. Example Code int main(int argc, char **argv) { glutInit(&argc, argv); glutInitDisplayMode ( GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
CS 480/680 Computer Graphics Programming with Open GL Part 7: Input and Interaction Dr. Frederick C Harris, Jr. Fall 2011.
Introduction to OpenGL and GLUT. What’s OpenGL? An Application Programming Interface (API) A low-level graphics programming API – Contains over 250 functions.
Program 2 due 02/01  Be sure to document your program  program level doc  your name  what the program does  each function  describe the arguments.
1 Input and Interaction. 2 Objectives Introduce the basic input devices ­Physical Devices ­Logical Devices ­Input Modes Event-driven input Introduce double.
Computer Graphics I, Fall 2010 Working with Callbacks.
Input and Interaction Yuanfeng Zhou Shandong University Software College 1.
1 Graphics CSCI 343, Fall 2015 Lecture 6 Viewing, Animation, User Interface.
1 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 OpenGL Transformations.
University of New Mexico
Input and Interaction Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico.
GLUT functions glutInit allows application to get command line arguments and initializes system gluInitDisplayMode requests properties for the window.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
12/22/ :38 1 Comp 175C - Computer Graphics Dan Hebert Computer Graphics Comp 175 Chapter 3 Instructor: Dan Hebert.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Input and Interaction Ed Angel Professor of Computer Science, Electrical and Computer Engineering,
31/1/2006Based on: Angel (4th Edition) & Akeine-Möller & Haines (2nd Edition)1 CSC345: Advanced Graphics & Virtual Environments Lecture 2: Introduction.
Introduction to Graphics Programming. Graphics API.
1 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 Working with Callbacks.
CSC Graphics Programming Budditha Hettige Department of Statistics and Computer Science.
INTRODUCTION TO OPENGL
Computer Graphics (Fall 2003) COMS 4160, Lecture 5: OpenGL 1 Ravi Ramamoorthi Many slides courtesy Greg Humphreys.
Review GLUT Callback Functions
Computer Graphics - Chapter 3 Input and Interaction
Working with Callbacks
CS5500 Computer Graphics March 2, 2006.
CSC461 Lecture 8: Input Devices
גרפיקה ממוחשבת: מבוא ל-OpenGL
Input and Interaction Chapter 3.
Input and Interactions
Working with Callbacks
PROGRAM 8 newpaint.c E. Angel.
Isaac Gang University of Mary Hardin-Baylor
Fundamentals of Computer Graphics Part 3
Input and Interaction Ed Angel
University of New Mexico
Input and Interaction Ed Angel
Input and Interaction Ed Angel Professor Emeritus of Computer Science,
Presentation transcript:

InteractionHofstra University1 Graphics Programming Input and Interaction

InteractionHofstra University2 Interaction Early 60’s, Ivan Sutherland’s Project Sketchpad Basic Paradigm: User see an image, reacts with an interactive device, image changes in response to input,...

InteractionHofstra University3 Interaction OpenGL does not support interaction directly Increase portability – work in a variety of environments Windowing and input functions left out of API – emphasis on rendering Use toolkits, GLUT

InteractionHofstra University4 Physical Input Devices Pointing Device – indicates position on screen Keyboard Device – return character codes to a program

InteractionHofstra University5 Logical Input Devices Major Characteristics: What measurements the device returns to the program When the device returns those measurements

InteractionHofstra University6 Application Input Measure - what the device returns to the user program Trigger – signal send to the computer Three distinct modes defined by the relationship between the measure process and the trigger. Request Mode, Sample Mode, Event Mode

InteractionHofstra University7 Request Mode The measure of the device is not returned to the program until the device is triggered

InteractionHofstra University8 Sample Mode Measure is returned immediately after the function is called in the user program. No trigger needed Need to identify which device provides input Useful in apps where the program guides the user (e.g., simulators)

InteractionHofstra University9 Event Mode Can handle multiple inputs When device triggered an event is generated Identifier for device placed in the event queue Event queue process is independent of the application, asynchronous A callback function with a specific type of event

InteractionHofstra University10 Clients and Servers The building blocks of a distributed world are entities called servers that can perform tasks for clients. Graphics server provides input and output of graphical services OpenGL programs are clients of the graphics server X-Window system was one of the most successful

InteractionHofstra University11 Event-Driven Programming Callback functions determine how the application program responds to events Examples, each of the events below needs a callback function to handle it. Pointing Device Window Events Keyboard Events Display & Idle Callbacks Window Management

InteractionHofstra University12 Pointing Device Almost always a mouse Move event – when mouse is moved with button depressed; Passive Move Event – move without pressing button Mouse Event – mouse button is depressed or released glutMouseFunc (mouse);

InteractionHofstra University13 Pointing Device – Mouse Callback void mouse(int btn, int state, int x, int y) { if(btn==GLUT_RIGHT_BUTTON && state==GLUT_DOWN) exit(0); } Depressing the right Button terminates the program

InteractionHofstra University14 Pointing Device – Reshape Event int main(int argc, char** argv) { glutInit(&argc,argv); glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB); glutCreateWindow("square"); myinit (); glutReshapeFunc (myReshape); glutMouseFunc (mouse); glutMotionFunc(drawSquare); glutDisplayFunc(display); glutMainLoop(); } Called whenever the window is resized

InteractionHofstra University15 Window Events (Resizing – Dragging) Redraw all the objects? How do we handle aspect ratio? Change size of attributes and primitives?

InteractionHofstra University16 Square Program This program illustrates the use of the glut library for interfacing with a Window System The program opens a window, clears it to black,then draws a box at the location of the mouse each time the left button is clicked. The right button exits the program The program also reacts correctly when the window is moved or resized by clearing the new window to black

InteractionHofstra University17 Global Variables Size of window Viewport position and size Size of clipping window /* globals */ GLsizei wh = 500, ww = 500; /* initial window size */ GLfloat size = 3.0; /* half side length of square */

InteractionHofstra University18 Window Event - Reshape void myReshape(GLsizei w, GLsizei h) { /* adjust clipping box */ glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0.0, (GLdouble)w, 0.0, (GLdouble)h, -1.0, 1.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); /* adjust viewport and clear */ glViewport(0,0,w,h); glClearColor (0.0, 0.0, 0.0, 1.0); glClear(GL_COLOR_BUFFER_BIT); glFlush(); /* set global size for use by drawing routine */ ww = w; wh = h; } reshaping routine called whenever window is resized or moved

InteractionHofstra University19 Pointing Device – Motion Callback void drawSquare(int x, int y) { y=wh-y; glColor3ub( (char) rand()%256, (char) rand()%256, (char) rand()%256); glBegin(GL_POLYGON); glVertex2f(x+size, y+size); glVertex2f(x-size, y+size); glVertex2f(x-size, y-size); glVertex2f(x+size, y-size); glEnd(); glFlush(); } Called by glutMotionFunc(drawSquare); if button held down Origin is top left of window system

InteractionHofstra University20 Keyboard Events void keyboard(unsigned char key, int x, int y) { if (key=='q' || key=='Q') exit(0); } glutKeyboardFunc(keyboard);

InteractionHofstra University21 Window Management id=glutCreateWindow(“second window”); glutSetWindow(id);

InteractionHofstra University22 Menus Pop-up menus Common Steps: Define the entries Link the menu to a mouse button Define callback function

InteractionHofstra University23 Menus glutCreateMenu(demo_menu); glutAddMenuEntry(“quit”, 1); glutAddMenuEntry(“increase square size”, 2); glutAddMenuEntry(“decrease square size”, 3); glutAttachMenu(GLUT_RIGHT_BUTTON); identifier passed to callback

InteractionHofstra University24 Menus void demo_menu(int id) { if (id==1) exit (0); else if (id==2) size = 2* size; else if (size > 1) size = size/2; glutPostRedisplay( ); } requests redraw through the glutDisplayFunc (redrawn w/o menu)

InteractionHofstra University25 Hierarchical Menus

InteractionHofstra University26 Hierarchical Menus sub_menu = glutCreateMenu(size_menu); glutAddMenuEntry(“increase square size”, 2); glutAddMenuEntry(“decrease square size”, 3); glutCreateMenu(top_menu); glutAddMenuENtry(“quit”, 1); glutAddSubMenu(“Resize”, sub_menu); glutAttachMenu(GLUT_RIGHT_BUTTON);

InteractionHofstra University27 Picking Picking – identify an object on the display Don’t return an x,y position NOT an easy process Two methods: selection and bounding rectangles.

InteractionHofstra University28 Selection Adjusting the clipping region and viewport to keep track of which primitives in a small clipping region are rendered into a region near the cursor. Primitives are entered into a hit list to be examined by the user program later on.

InteractionHofstra University29 Rotating Cube Program We want to create animation We continuously keep changing the value of

InteractionHofstra University30 Idle Function void spinCube() { /* Idle callback, spin cube 2 degrees about selected axis */ theta[axis] += 2.0; if( theta[axis] > ) theta[axis] -= 360.0; /* display(); */ glutPostRedisplay(); } glutIdleFunc(spinCube); The idle function works while we do nothing We reexecute the display through this function

InteractionHofstra University31 Double Buffering A complex display may not be drawn in a single refresh cycle Double Buffering solves the problem Assume two frame buffers: front buffer and back buffer Swap these from the application program invoking a display callback

InteractionHofstra University32 Double Buffering void display(void) { /* display callback, clear frame buffer and z buffer, rotate cube and draw, swap buffers */ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);... glRotatef(theta[2], 0.0, 0.0, 1.0); colorcube(); glFlush(); glutSwapBuffers(); } glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB |GLUT_DEPTH); Updating back buffer and swapping

InteractionHofstra University33 Good Interactive Programs Smooth display Interactive devices on display Variety of methods to input data Easy-to-use interface Feedback to user Tolerance Human consideration (HCI)