Lecture 10: Input, Interaction & callbacks. CITS 3003 Graphics & Animation

Similar documents
Objectives. Topic 8: Input, Interaction, & Introduction to callbacks. Input Devices. Project Sketchpad. Introduce the basic input devices

Project Sketchpad. Ivan Sutherland (MIT 1963) established the basic interactive paradigm that characterizes interactive computer graphics:

Input and Interaction

Lecture 11: Callbacks. CITS 3003 Graphics & Animation

CS 432 Interactive Computer Graphics

Introduce the basic input devices Input, Interaction and Animation

Input, Interaction and Animation Week 2

Lecture 4. Interaction / Graphical Devices. CS 354 Computer Graphics Sunday, January 20, 13

Input and Interaction. CS 537 Interactive Computer Graphics Prof. David E. Breen Department of Computer Science

Comp 410/510 Computer Graphics Spring Input & Interaction

Input and Interaction. Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico

Input and Interaction

Computer Graphics Lecture 2

Lecture 3 Advanced Computer Graphics (CS & SE )

Computer Graphics. Bing-Yu Chen National Taiwan University

Lecture 2 CISC440/640 Spring Department of Computer and Information Science

Input and Interaction

Introduction to Computer Graphics with OpenGL/GLUT

CSC Graphics Programming. Budditha Hettige Department of Statistics and Computer Science

API Background. Prof. George Wolberg Dept. of Computer Science City College of New York

VR-programming tools (procedural) More VRML later in this course! (declarative)

Input and Interaction. 1. Interaction. Chapter 3. Introduction: - We now turn to the development of interactive graphics programs.

RECITATION - 1. Ceng477 Fall

CS 432 Interactive Computer Graphics

GLUT. What is OpenGL? Introduction to OpenGL and GLUT

Programming using OpenGL: A first Introduction

Input and Interaction. Angel and Shreiner: Interactive Computer Graphics 7E Addison-Wesley 2015

CS Computer Graphics: Intro to OpenGL

CS Computer Graphics: Intro to OpenGL

GL_COLOR_BUFFER_BIT, GL_PROJECTION, GL_MODELVIEW

Lecture 12: Mid-term test solution & project. CITS 3003 Graphics & Animation

Lecture 2 Sections 3.6, 3.7. Fri, Aug 28, 2009

Computer Viewing. CITS3003 Graphics & Animation. E. Angel and D. Shreiner: Interactive Computer Graphics 6E Addison-Wesley

Input and Interaction. Input and Interaction

CS 543 Lecture 1 (Part II): Intro to OpenGL and GLUT (Part I) Emmanuel Agu

Programming with OpenGL Part 1: Background

Introduction to OpenGL. CSCI 4229/5229 Computer Graphics Fall 2012

// double buffering and RGB glutinitdisplaymode(glut_double GLUT_RGBA); // your own initializations

OpenGL refresher. Advanced Computer Graphics 2012

ERKELEY DAVIS IRVINE LOS ANGELES RIVERSIDE SAN DIEGO SAN FRANCISCO EECS 104. Fundamentals of Computer Graphics. OpenGL

Early History of APIs. PHIGS and X. SGI and GL. Programming with OpenGL Part 1: Background. Objectives

1 (Practice 1) Introduction to OpenGL

Computer Graphics (CS 543) Lecture 1 (Part 2): Introduction to OpenGL/GLUT (Part 1)

Computer Graphics 1 Computer Graphics 1

Computer Graphics (CS 4731) OpenGL/GLUT(Part 1)

User Interaction. User Interaction. Input devices. Input devices. Input devices GUIs and GUI design Event-driven programming 3D interaction

Lecture 5 Vertex and Fragment Shaders-1. CITS3003 Graphics & Animation

OpenGL and X, Column 1: An OpenGL Toolkit

CS Computer Graphics: OpenGL, Continued

CS Computer Graphics: OpenGL, Continued

VTU EDUSAT PROGRAMME. Computer Graphics & Visualization

Lecture 4 of 41. Lab 1a: OpenGL Basics

CHAPTER 1 Graphics Systems and Models 3

OpenGL/GLUT Intro. Week 1, Fri Jan 12

Lecture 15: Shading-I. CITS3003 Graphics & Animation

1 Preview. Dr. Scott Gordon Computer Science Dept. CSUS. Virtual Cameras, Viewing Transformations: CSc-155 Advanced Computer Graphics

Computer Graphics (CS 543) Lecture 2b: 2D Graphics Systems (Drawing Polylines, tiling, & Aspect Ratio)

An Overview GLUT GLSL GLEW

Objectives. Topic 4: OpenGL An Example Program. simple.cpp revisited. Defining Objects in OpenGL Programs. Build a complete OpenGL program

Lecture 9: Transformations. CITS3003 Graphics & Animation

LECTURE 02 OPENGL API

OPENGL TM AND X, COLUMN 1: AN OPENGL TOOLKIT

Computer graphic -- Programming with OpenGL 2

CS 4731 Lecture 3: Introduction to OpenGL and GLUT: Part II. Emmanuel Agu

Rendering. Part 1 An introduction to OpenGL

TEACHING PLAN FAKULTI TEKNOLOGI MAKLUMAT DAN KOMUNIKASI UNIVERSITI TEKNIKAL MALAYSIA MELAKA

Information Coding / Computer Graphics, ISY, LiTH. OpenGL! ! where it fits!! what it contains!! how you work with it 11(40)

CS 4204 Computer Graphics

Computer Graphics (CS 4731) OpenGL/GLUT (Part 2)

SOURCES AND URLS BIBLIOGRAPHY AND REFERENCES

Working with Callbacks

Teacher Assistant : Tamir Grossinger Reception hours: by - Building 37 / office -102 Assignments: 4 programing using

CMSC 427 Computer Graphics 1

Lecture 2 2D transformations Introduction to OpenGL

Computer Graphics Course 2005

COMPUTER GRAPHICS LAB # 3

Image Processing. Geometry Processing. Reading: (Not really covered in our text. See Sects 18.1, 18.2.) Overview: Display

Interactive Techniques

CP SC 4040/6040 Computer Graphics Images. Joshua Levine

Computer Graphics (CS 4731) Lecture 11: Implementing Transformations. Prof Emmanuel Agu. Computer Science Dept. Worcester Polytechnic Institute (WPI)

WebGL A quick introduction. J. Madeira V. 0.2 September 2017

Introduction to Virtual Environments - Spring Wernert/Arns. Lecture 4.2 Animation & Interaction

Drawing Primitives. OpenGL basics

Input (part 2: input models)

Computer Graphics CS 543 Lecture 5 (Part 2) Implementing Transformations

Manipal Institute of Technology Manipal University Manipal

Introduction to Computer Graphics. Overview. What is Computer Graphics?

Interactive Computer Graphics A TOP-DOWN APPROACH WITH SHADER-BASED OPENGL

Blue colour text questions Black colour text sample answers Red colour text further explanation or references for the sample answers

Objectives. Shading II. Distance Terms. The Phong Reflection Model

CS 380 Introduction to Computer Graphics. LAB (1) : OpenGL Tutorial Reference : Foundations of 3D Computer Graphics, Steven J.

INTRODUCTION. Computer Graphics

The Trackball First make sure your hand is in the correct position on the trackball.

An Introduction to. Graphics Programming

Introduction to OpenGL Week 1

Objectives. Image Formation Revisited. Physical Approaches. The Programmer s Interface. Practical Approach. Introduction to OpenGL Week 1

Computer Graphics. OpenGL

CS450/550. Pipeline Architecture. Adapted From: Angel and Shreiner: Interactive Computer Graphics6E Addison-Wesley 2012

Computer Graphics (CS 4731) Lecture 11: Implementing Transformations. Prof Emmanuel Agu. Computer Science Dept. Worcester Polytechnic Institute (WPI)

Advanced Computer Graphics (CS & SE )

Transcription:

Lecture 10: Input, Interaction & callbacks CITS 3003 Graphics & Animation Slides: E. Angel and D. Shreiner: Interactive Computer Graphics 6E Addison-Wesley 2012

Objectives Introduce the basic input devices Physical Devices Logical Devices Input Modes Event-driven input Programming event input with GLUT An introduction to callbacks 2

Project Sketchpad Ivan Sutherland (MIT 1963) established the basic interactive paradigm that characterizes interactive computer graphics: User sees an object on the display User points to (picks) the object with an input device (light pen, mouse, trackball) Object changes (moves, rotates, morphs) Repeat 3

Input Devices User inputs control the program through input devices Input devices can be viewed as o o Physical devices: described by their physical properties, e.g., mouse, keyboard, trackball, etc. Logical devices: characterized by how they influence the application program, e.g., what is returned to the program via the API An x, y position on the screen? An object identifier for a menu item chosen? Both are performed by the same physical device (the mouse, in this case) but what is returned to the program is different. 4

Physical Devices mouse trackball light pen data tablet joy stick space ball 5

Logical Input Devices Consider the C and C++ code o C++: cin >> x; o C: scanf( %d, &x); What is the input physical device? o Can t tell from the code o Could be keyboard, file, output from another program The code provides logical input o A number (an int) is returned to the program regardless of the physical device 6

Logical Input Devices (cont.) Older APIs (GKS, PHIGS, not OpenGL) defined six specific types of logical input: Locator: return a position, e.g., clicked at by a mouse pointer Choice: return one of n discrete items, e.g., a menu item String: return strings of characters, e.g., via key presses Stroke: return array of positions Valuator: return floating point number Pick: return ID of an object OpenGL and GLUT provide functions to handle all these 7

Incremental (Relative) Devices Devices such as the data tablet return a position directly to the operating system Devices such as the mouse, trackball, and joy stick return incremental inputs (or velocities) to the operating system o Must integrate these inputs to obtain an absolute position Rotation of cylinders in mouse Roll of trackball Difficult to obtain absolute position Can get variable sensitivity 8

Input Modes Input devices contain a trigger which can be used to send a signal to the operating system o Button on mouse o Pressing or releasing a key When triggered, input devices return information (their measure) to the system o Mouse returns position information o Keyboard returns ASCII code 9

Input Modes (cont.) Input modes concern how and when input is obtained There are two types of input modes: o Request mode o Event mode 10

Request Mode For request mode input, the input value is provided to program only when user triggers the device A typical example is keyboard input: o The application program request a keyboard input from the user o The user can type, erase (backspace), correct. The application program hangs there until the enter (return) key (the trigger) is depressed 11

Event Mode Request mode is not suitable for programs that need to interact with the user. Most systems have more than one input device, each of which can be triggered at an arbitrary time by a user 12

Event Mode (cont.) In event mode input, the program specifies a number of input events that are of interest. The program gets into an event handling loop to deal with the events when they occur Each trigger generates an event whose measure is put in an event queue which can be examined by the user program 13

Event Types in event mode input Window event: resize, expose, iconify Mouse event: click one or more buttons Motion event: this refers to the mouse move event (when the cursor is inside the window of the application program) Keyboard: press or release a key Idle: non-event o Define what should be done if no other event is in the event queue 14

Callbacks We can program to handle event mode input We can define a callback function for each type of event that the graphics system recognizes This user-supplied function is executed when the event occurs GLUT example: glutmousefunc(mymouse) mouse callback function 15

GLUT callbacks GLUT recognizes a subset of the events recognized by any particular window system (Windows, X, Macintosh) o o o o o o o o glutdisplayfunc glutcreatemenu glutmousefunc glutreshapefunc glutkeyboardfunc glutidlefunc glutmotionfunc glutpassivemotionfunc 16

% usage glutmousefunc void glutmousefunc(void (*func)(int button, int state, int x, int y)); Example: glutmousefunc(mymousefun); % defined in the main() % the function definition void mymousefun(int button, int state, int x, int y) { % this is where you write code for what you want to do % when a mouse event happens } 17

GLUT Event Loop Recall that the last line in main.c for a program using GLUT must be glutmainloop(); which puts the program in an infinite event loop In each pass through the event loop, GLUT 1. looks at the events in the queue 2. for each event in the queue, GLUT executes the appropriate callback function if one is defined 3. if no callback is defined for the event, the event is ignored 18

The display callback The display callback is executed whenever GLUT determines that the window should be refreshed, for example o When the window is first opened o When the window is reshaped o When a window is exposed o When the user program decides it wants to change the display In main() o glutdisplayfunc(mydisplay) identifies the function to be executed o Every GLUT program must have a display callback 19

Posting redisplays Many events may invoke the display callback function o Can lead to multiple executions of the display callback on a single pass through the event loop We can avoid this problem by instead using glutpostredisplay(); which sets a flag. GLUT checks to see if the flag is set at the end of the event loop If set then the display callback function is executed 20

Mid-Semester Test When Tuesday 10 April during the lecture 12:00-12:45PM Where In ENCM [G04] i.e. where Tuesday lectures are held What is included Everything from Lecture 1 to Lecture 10 What to bring to the test A pen to write with (no pencils, no books, no notes) See unit website for sample test from 2016 http://teaching.csse.uwa.edu.au/units/cits3003/index.php?fna me=lectures

Further Reading Interactive Computer Graphics A Top-Down Approach with Shader-Based OpenGL by Edward Angel and Dave Shreiner, 6 th Ed, 2012 Sec. 1.2.4-1.2.7 Input Devices, Physical Input Devices, Logical Devices, Input Modes Sec. 2.1 The Sierpinski Gasket; immediate mode graphics vs retained mode graphics C++ code in the Chapter02 to Chapter04 folders 22