Input and Interaction

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

CS 432 Interactive Computer Graphics

Working with Callbacks

Comp 410/510 Computer Graphics Spring Input & Interaction

Lecture 11: Callbacks. CITS 3003 Graphics & 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

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

CS 4204 Computer Graphics

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

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

Lecture 3 Advanced Computer Graphics (CS & SE )

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

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

GL_COLOR_BUFFER_BIT, GL_PROJECTION, GL_MODELVIEW

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

Introduction to Computer Graphics with OpenGL/GLUT

Computer Graphics. OpenGL

CS Computer Graphics: OpenGL, Continued

CS Computer Graphics: OpenGL, Continued

Computer Graphics. Bing-Yu Chen National Taiwan University

VTU EDUSAT PROGRAMME. Computer Graphics & Visualization

GLUT Tutorial. Keyboard

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

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

RECITATION - 1. Ceng477 Fall

CS 548: COMPUTER GRAPHICS GLUT INPUT FUNCTIONS SPRING 2015 DR. MICHAEL J. REALE

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

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

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

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

Computer Graphics 1 Computer Graphics 1

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

CS Computer Graphics: Intro to OpenGL

CS Computer Graphics: Intro to OpenGL

Computer Graphics (4731) Lecture 4: 2D Graphics Systems (Drawing Polylines, tiling, & Aspect Ratio)

OpenGL refresher. Advanced Computer Graphics 2012

Drawing Primitives. OpenGL basics

Programming using OpenGL: A first Introduction

Input and Interaction

OpenGL and X, Column 1: An OpenGL Toolkit

COMPUTER GRAPHICS LAB # 3

C OMPUTER G RAPHICS Thursday

Windows and Viewports. Windows and Viewports. Windows and Viewports. Windows and Viewports. CSC 706 Computer Graphics

CMSC 425: Lecture 4 More about OpenGL and GLUT Tuesday, Feb 5, 2013

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

CMSC 427 Computer Graphics 1

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

GLUT. What is OpenGL? Introduction to OpenGL and GLUT

Computer Graphics Course 2005

1 (Practice 1) Introduction to OpenGL

OPENGL TM AND X, COLUMN 1: AN OPENGL TOOLKIT

Drawing and Coordinate Systems

Introduce the basic input devices Input, Interaction and Animation

Computer Graphics. Downloaded from: LectureNotes 1 CSC-254

Lecture 4 of 41. Lab 1a: OpenGL Basics

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

Computer Graphics Anatomy of GUI. Computer Graphics CSC470 1

Lecture 2 2D transformations Introduction to OpenGL

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

Graphics and Visualization

Drawing and Coordinate Systems

Rendering. Part 1 An introduction to OpenGL

Set the Viewport Clipping. Computer Graphics CSC470 1

2. OpenGL -I. 2.1 What is OpenGL? Things OpenGL can do: -23-

CS 432 Interactive Computer Graphics

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

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

More on Coordinate Systems. Coordinate Systems (3) Coordinate Systems (2) Coordinate Systems (5) Coordinate Systems (4) 9/15/2011

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

Today s class. Viewing transformation Menus Mandelbrot set and pixel drawing. Informationsteknologi

Computer graphic -- Programming with OpenGL 2

Programming with OpenGL Part 1: Background

Exercise 1 Introduction to OpenGL

CSCI 4620/8626. The 2D Viewing Pipeline

SOURCES AND URLS BIBLIOGRAPHY AND REFERENCES

To Do. Computer Graphics (Fall 2008) Course Outline. Course Outline. Methodology for Lecture. Demo: Surreal (HW 3)

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

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

Lectures OpenGL Introduction

Interaction. CSCI 480 Computer Graphics Lecture 3

Cameras (and eye) Ideal Pinhole. Real Pinhole. Real + lens. Depth of field

Lecture 4 Advanced Computer Graphics (CS & SE )

Announcements OpenGL. Computer Graphics. Spring CS4815

CS380: Computer Graphics Basic OpenGL Structure. Sung-Eui Yoon ( 윤성의 ) Course URL:

Set the Viewport. Set the Viewport Clipping. Set the Viewport. Set the Viewport. Set the Viewport. Resizing the Viewport W = H

Transformation, Input and Interaction. Hanyang University

An Introduction to. Graphics Programming

DONALD HOUSE: CPSC 8170, FALL 2018 DESIGN OF A REAL-TIME ANIMATION PROGRAM

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

CS559: Computer Graphics. Lecture 12: OpenGL Li Zhang Spring 2008

Input and Interaction

2/3/16. Interaction. Triangles (Clarification) Choice of Programming Language. Buffer Objects. The CPU-GPU bus. CSCI 420 Computer Graphics Lecture 3

Interaction. CSCI 420 Computer Graphics Lecture 3

UNIVERSITY OF NEBRASKA AT OMAHA Computer Science 4620/8626 Computer Graphics Spring 2014 Homework Set 1 Suggested Answers

Computer Graphics and Visualization SYLLABUS COMPUTER GRAPHICS AND VISUALIZATION

CS 4204 Computer Graphics

Building Models. CS 537 Interactive Computer Graphics Prof. David E. Breen Department of Computer Science

Comp 410/510 Computer Graphics Spring Programming with OpenGL Part 2: First Program

Transcription:

Input and Interaction Adapted from Edward Angel, UNM! Angel: Interactive Computer Graphics 3E Addison-Wesley 2002

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 sketchpad 1! sketchpad 2! Angel: Interactive Computer Graphics 3E Addison-Wesley 2002 1

Event Types Window: resize, expose, iconify Mouse: click one or more buttons Motion: move mouse Keyboard: press or release a key Idle: nonevent Define what should be done if no other event is in queue

Callbacks Programming interface for event-driven input Define a callback function for each type of event the graphics system recognizes This user-supplied function is executed when the event occurs GLUT example: glutmousefunc(mymouse) mouse callback function

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

Glut Event Loop Remember 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 looks at the events in the queue for each event in the queue, GLUT executes the appropriate callback function if one is defined if no callback is defined for the event, the event is ignored

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

Post Redisplay Many events may invoke the display callback function To avoid multiple displays glutpostredisplay(); 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

Idle and Timers The idle callback is executed whenever there are no events in the event queue glutidlefunc(myidle) The timer callback is executed at specified times gluttimerfunc(33, mytimercb) Must remember to reschedule the timer

Using Globals common approach The form of all GLUT callbacks is fixed void mydisplay() void mymouse(glint button, GLint state, GLint x, GLint y) Must use globals to pass information to callbacks float t; /*global */ void mydisplay() { /* draw something that depends on t }

The Mouse Callback glutmousefunc(mymouse) void mymouse(glint button, GLint state, GLint x, GLint y) Returns which button (GLUT_LEFT_BUTTON, GLUT_MIDDLE_BUTTON, GLUT_RIGHT_BUTTON) caused event state of that button (GLUT_UP, GLUT_DOWN) Position in window

Positioning in Windows The position in the screen window is usually measured in pixels with the origin at the top-left corner OpenGL uses a coordinate system with origin at the bottom left Must invert y coordinate returned by callback by height of window y = h y; (0,0) h! w

Keyboard Callback glutkeyboardfunc(mykey) void mykey(unsigned char key, int x, int y) void mykey(unsigned char key, int x, int y) { if(key == Q key == q ) exit(0); }

Modifier Keys GLUT defines the special keys in glut.h Function key 1: GLUT_KEY_F1 Up arrow key: GLUT_KEY_UP Can check these in glutspecialfunc() callback Can also check if one of the modifiers GLUT_ACTIVE_SHIFT GLUT_ACTIVE_CTRL GLUT_ACTIVE_ALT int mod = glutgetmodifiers() Must be within a callback!

Menus GLUT supports pop-up menus - A menu can have submenus Three steps - Define entries for the menu - Define action for each menu item Action carried out if entry selected - Attach menu to a mouse button

Menus In main.c callback! menu_id = glutcreatemenu(mymenu); glutaddmenuentry( clear Screen, 1); gluaddmenuentry( exit, 2); glutattachmenu(glut_right_button); clear screen exit entries that appear when right button depressed identifiers

Menus - Menu callback - Add submenus by void mymenu(int id) { if(id == 1) glclear(); if(id == 2) exit(0); } glutaddsubmenu(char *submenu_name, submenu id) name in parent menu

Submenus 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); Quit Resize Increase square size Decrease square size

Viewports Do not have to use the entire window for the image: glviewport(x,y,w,h)

Reshaping the window We can reshape and resize the OpenGL display window by pulling the corner of the window What happens to the display?

The Reshape callback glutreshapefunc(myreshape) void myreshape( int w, int h) Returns width and height of new window (in pixels) A redisplay is posted automatically at end of execution of the callback GLUT has a default reshape callback to set the viewport to the window size

Reshape Possibilities original reshaped

Default Window Sizing (No Reshape CB) Resizes the viewport to match the window Does not change the view volume

Window resizing Do Nothing Write a Reshape function, but do nothing in it. Does not change view volume AND does not change viewport

Better Answer Make view volume aspect ratio match the viewport AR (which matches the window AR) Square view volume Resized window and a viewport with no distortion

Example Reshape: Ortho void myreshape(int w, int h) { } glviewport(0,0,w,h); float ar = w/h; if( ar < startar) { // (w <= h ){ //taller proj = Ortho(vl, vr, vl * (GLfloat) h / (GLfloat) w, vr * (GLfloat) h / (GLfloat) w, 0.1,10.0); } else //wider } { proj = Ortho(vb * (GLfloat) w / (GLfloat) h, vt * (GLfloat) w / (GLfloat) h, vb, vt,0.1,10.0); How would you modify to work with Perspective Projections?