Selection Mode, Introduction to Widgets Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, October 6, 2003.

Slides:



Advertisements
Similar presentations
Better Interactive Programs
Advertisements

CS0004: Introduction to Programming Visual Studio 2010 and Controls.
1 Computer Graphics Week6 –Basic Transformations- Translation & Scaling.
Chapter 12 Interactive Graphics Chih-Kuo Yeh. Direct Manipulation Demo.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Better Interactive Programs Ed Angel Professor of Computer Science, Electrical and Computer.
Based on slides created by Edward Angel
Informationsteknologi Tuesday, November 6, 2007Computer Graphics - Class 41 Today’s class Input and interaction.
Jittering, Introduction to Stenciling Glenn G. Chappell U. of Alaska Fairbanks CS 481/681 Lecture Notes Friday, February 6, 2004.
Picking. What is picking? Selecting an object on the screen What does this require? –Get Mouse Location –Compute what objects are rendered at the position.
Course Overview, Introduction to CG Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Friday, September 5, 2003.
19/4/ :32 Graphics II Syllabus Selection and Picking Session 1.
Mouse-Based Viewing & Navigation Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, November 3, 2003.
CSC461 Lecture 11: Interactive Programs Contents and Objectives Picking Writing modes – XOR/Copy Rubberbanding Display list.
Lehigh University Introduction to Flash MX Sharmeen Mecklai.
Linear Interpolation, Brief Introduction to OpenGL Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, September.
Introduction to Arrays. definitions and things to consider… This presentation is designed to give a simple demonstration of array and object visualizations.
Data Structures for Scenes, The Basics of Scene Graphs Glenn G. Chappell U. of Alaska Fairbanks CS 481/681 Lecture Notes Friday,
Korea University Korea University Computer Graphics Laboratory Computer Graphics Laboratory Jung Lee, Chapter 13.
Implementing Scene Graphs, CSG Trees Glenn G. Chappell U. of Alaska Fairbanks CS 481/681 Lecture Notes Monday, January 26, 2004.
Homogeneous Form, Introduction to 3-D Graphics Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, October 20,
Shadows via Projection Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Wednesday, November 5, 2003.
Computing & Information Sciences Kansas State University Lecture 20 of 42CIS 636/736: (Introduction to) Computer Graphics Lecture 21 of 42 William H. Hsu.
Forms and Server Side Includes. What are Forms? Forms are used to get user input We’ve all used them before. For example, ever had to sign up for courses.
Chapter 5 Quick Links Slide 2 Performance Objectives Understanding Framesets and Frames Creating Framesets and Frames Selecting Framesets and Frames Using.
Introduction to Excel Editing Your Workbook.
More on Advanced Interfaces, Image Basics Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Friday, November 21, 2003.
1 Better Interactive Programs. 2 Objectives Learn to build more sophisticated interactive programs using ­Picking Select objects from the display Three.
FIX Eye FIX Eye Getting started: The guide EPAM Systems B2BITS.
More on Drawable Objects, Hierarchical Objects Glenn G. Chappell U. of Alaska Fairbanks CS 481/681 Lecture Notes Wednesday, January.
Modeling with OpenGL Practice with OpenGL transformations.
Computer Graphics Chapter 6 Andreas Savva. 2 Interactive Graphics Graphics provides one of the most natural means of communicating with a computer. Interactive.
Intro. to Advanced Lighting, Basic Ray Tracing Glenn G. Chappell U. of Alaska Fairbanks CS 481/681 Lecture Notes Monday, April.
More on Environment Mapping Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Wednesday, December 10, 2003.
Introduction to Processing. 2 What is processing? A simple programming environment that was created to make it easier to develop visually oriented applications.
OpenGL Selection. Three Selection Methods Color coding (OpenGL) Selection mode (OpenGL) Selection ray (generic)
Build-A-Button Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Wednesday, October 8, 2003.
Copyright © Curt Hill More Components Varying the input of Dev-C++ Windows Programs.
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.
More on GLUT Programming Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, September 15, 2003.
Computer Graphics: Programming, Problem Solving, and Visual Communication Steve Cunningham California State University Stanislaus and Grinnell College.
Advanced Viewing Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Friday, October 31, 2003.
Pop-Up Menus Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Friday, September 26, 2003.
Pinnacle Pro Painting Program User Manual Created by: David Kwasny Chris Schulz W. Scott DePouw.
By: Susan Freeman Getting Started 1.Go to Start Programs Microsoft PowerPoint.
Introduction to Drafting and Design In order to begin our drawing we have to set the drawing limits or the paper size.
Details of Texture Mapping Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, December 1, 2003.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
Introduction to Input/Interaction Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Friday, September 19, 2003.
Learning the Basics of ArcMap 3.3 Updated 4/27/2010 Using Arc/View pt. 1 1.
Creating a PowerPoint With Sound PowerPoint 2007 Version.
SurveyDIG 2.1 Tutorial. Tutorial Contents Introduction Introduction Item Groups Item Groups –Creating new Groups –Naming Convention –Searching/Editing.
OpenGL LAB III.
Introduction to 3-D Viewing Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, October 27, 2003.
Layers in Adobe After Effect
Stenciling Effects Glenn G. Chappell
D.Y.O. Web The new and easy way to create and maintain your own professional dynamic website.
Introduction to the Mouse
Better Interactive Programs
Advanced Menuing, Introduction to Picking
Intro to lighting (Chapter 11)
Projection in 3-D Glenn G. Chappell
Display Lists & Text Glenn G. Chappell
Better Interactive Programs
More on Widgets, Misc. Topics
Computer Graphics Practical Lesson 8
Picking in OpenGL Yingcai Xiao.
Group Boxes, Radio buttons and Checked List Boxes
Preview of 3-D Graphics Glenn G. Chappell
Presentation transcript:

Selection Mode, Introduction to Widgets Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, October 6, 2003

6 Oct 2003CS 3812 Where Are We? We have covered: Chapter 1. Intro. to CG. Chapter 2. Basic CG Programming. Much of Chapter 3. GUI’s & picking. Now we continue with picking, and discuss widgets. Next week, we switch to 3-D CG: Chapter 4. Math of 3-D CG. Chapter 5. 3-D Viewing. Chapter 6. Lighting.

6 Oct 2003CS 3813 Review: Picking Methods [1/2] Method #1: Extent Testing The “obvious” way to do picking: Figure out the extent of each object. For each, test whether the mouse position is inside it. In a 2½-D interface (e.g., overlapping windows), can test in front-to-back order. Disadvantage Complex object shapes can make for tricky testing.

6 Oct 2003CS 3814 Review: Picking Methods [2/2] Method #2: Buffer Reading If we can read the frame buffer: Draw each object in a different, solid color. Read the color of the pixel at the mouse position to determine what was clicked on. Double buffering makes this nicer. Draw to and read from the back buffer, without swapping. Then users don’t need to see the strangely colored version of the scene. Method #3: Selection Mode We examine this method in detail today.

6 Oct 2003CS 3815 Selection Mode: Introduction Our third picking method uses OpenGL’s “selection mode”. A “name” can be given to a primitive. As usual, a name is actually a number. In selection mode, drawing commands produce no output. Instead, we get a list of the names of primitives that were not discarded by during clipping. If we set the clipping region to be a small area around the mouse position, then we can use selection mode to determine what was clicked on (i.e., to do picking). Example code can be found in selectionmode.cpp, on the web page. Also select.c, which is from the red book.

6 Oct 2003CS 3816 Selection Mode: The Method When the mouse is clicked: Allocate a selection buffer. This will hold the hits: names of objects at the mouse position. Initialize selection mode and the name stack. In selection mode, “drawing” produces no output, only hits. The name stack keeps track of the current name. Set up the projection. Redo the projection, just like normal, only putting a call to gluPickMatrix just before **the call to gluOrtho2D. This sets up the required clipping region. **“Draw” the scene, with names inserted into the pipeline. No output, so THE RULES are not being broken. Restore the old projection and the “normal” rendering mode. And, as a side benefit, find out the number of hits. Now the hits are in the selection buffer. At this point, I usually put the hit data into a simpler format.

6 Oct 2003CS 3817 Selection Mode: Organizing the Code The **’s on the previous slide mark things that need to be done in two places. The call to gluOrtho2D needs to be made both in the reshape (or init) function and during selection mode. Drawing the named objects in the scene needs to be done both in the display function and during selection mode. Idea: Make separate functions for each of these. Both functions are called in two places. In selectionmode.cpp, I call these functions “ set_up_coords ” and “ draw_with_names ”, respectively. Now write a function to do all the selection mode stuff. Mine is called “ doselect ”. You can probably use doselect without modification.

6 Oct 2003CS 3818 Selection Mode: Function doselect [1/7] The “magic” in this program happens in doselect, which is called from the mouse & motion functions. Function doselect is given the mouse position. It returns a list of hits. Along the way, it calls set_up_coords and draw_with_names. Despite the drawing calls, doselect produces no output, so it can (and should!) be called outside the display function. void doselect(int x, int y, int & hitcount, int hitarray[100]) I return at most 100 hits. You want more? That’s your problem.

6 Oct 2003CS 3819 Selection Mode: Function doselect [2/7] First, allocate a selection buffer. This is an array of GLuint ’s. 512 seems to be everyone’s favorite size. const int buffersize = 512; GLuint selectionbuffer[buffersize]; This array will hold the hit records. OpenGL will not write past the end of the buffer. We need to make sure we do not read past the end of the buffer.

6 Oct 2003CS Selection Mode: Function doselect [3/7] Next, initialize selection mode and the name stack. glSelectBuffer(buffersize, selectionbuffer); glRenderMode(GL_SELECT); glInitNames(); glPushName(0); We tell OpenGL about the selection buffer. Then we set selection mode. Now drawing commands now produce no output, only hits. Then we initialize the name stack. Lastly, we stick a “dummy” name on the stack.

6 Oct 2003CS Selection Mode: Function doselect [4/7] We are almost ready to draw. We need only set up the picking region. This is done with the projection matrix. glMatrixMode(GL_PROJECTION); glPushMatrix(); // save old projection glLoadIdentity(); // Insert the following three lines just before // your standard gluOrtho2D call. GLint vp[4]; glGetIntegerv(GL_VIEWPORT, vp); gluPickMatrix(x, vp[3]-y, 1, 1, vp); set_up_coords(); This is the code straight from the reshape function, with three magic lines inserted. Do not insert them in the reshape function. The glPushMatrix call is an easy way to save the old projection. Restore it later with glPopMatrix.

6 Oct 2003CS Selection Mode: Function doselect [5/7] Now, we draw, just as in the display function. We need names inserted in the pipeline (more on this later). glMatrixMode(GL_MODELVIEW); draw_with_names(); glFlush(); // Empty the pipeline It is generally good to be in model/view mode when drawing. More on this later in the course. Note the glFlush call. This program is doubly buffered. Thus, in the display function we flush using glutSwapBuffers. But we do not want to swap during selection mode. Right? Thus, we do not do any flushing in draw_with_names. And, thus, we need to do it here.

6 Oct 2003CS Selection Mode: Function doselect [6/7] Now we restore the old projection and the “normal” rendering mode. When we restore the rendering mode, we get the number of hits as a return value. // Done with pick matrix glMatrixMode(GL_PROJECTION); glPopMatrix(); // Restore the old projection glMatrixMode(GL_MODELVIEW); // Done with selection mode hitcount = glRenderMode(GL_RENDER); Now, we know how many hits there were. Details (names) are in the selection buffer. In a tricky format …

6 Oct 2003CS Selection Mode: Function doselect [7/7] At this point, I could just return the selection buffer. But I decided to simplify things a bit. The selection buffer holds a sequence of hit records, which may vary in length. Numbers in the hit record are: 1 GLuint : Name stack depth for this hit. 1 GLuint : Min depth for this hit. See doc’s for format. 1 GLuint : Max depth for this hit. 0 or more GLuint ’s: Name stack contents for this hit. # of values here is the stack depth, above. In a simple 2-D program, the number of interest is the last one in the hit record (the top of the name stack for this hit). So, for each hit, I collect the relevant value. This is the name of the object that was hit. I put all these values in an array and return it.

6 Oct 2003CS Selection Mode: Function draw_with_names Function draw_with_names is just the normal drawing code out of the display function, except: No clearing. No flushing or swapping. Only draw the things we want to do hit testing with. So, in this program, I draw the text instructions in the main display function. Add names. We put names in the name stack with glLoadName. If we are not in selection mode, this is ignored. If we are in selection mode, the name stack must be nonempty. Remember the glPushName call. Once a name is loaded, it applies to all primitives drawn until the name is changed. Just like any well-behaved OpenGL state.

6 Oct 2003CS Introduction to Widgets: What is a Widget? In a GUI, when a user specifies an action to be performed, a “widget” is often used. A widget (also called a control, esp. in MacOS) is a portion of the screen dedicated to mouse input. So widgets are a great application of picking! Examples: Checkboxes Radio buttons Scroll bars Buttons Menu pop-ups Some text boxes We will look at issues involved in the inclusion of widgets in a GUI and their implementation.

6 Oct 2003CS Introduction to Widgets: Issues Widgets often mimic physical objects. So: When a user deals with a widget, it must react immediately. The feedback must appear reasonable. Often shading suggests movement toward/away from the user (2 ½-D). Other issues: User must be able to predict what a widget will do. Nonstandard widgets may not be used. Generic do-anything widgets (like buttons) should be labeled. Scroll bars need to be next to what they scroll. Widgets that produce immediate actions (like buttons) should be easy to distinguish from those that do not (like checkboxes). Physical boundaries of widget should be clear to user. For fast feedback, must be able to draw widgets quickly. Widgets should not waste valuable screen space. Next time we discuss an implementation of a simple widget (a button).