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.

Slides:



Advertisements
Similar presentations
Coordinate System.
Advertisements

Better Interactive Programs
Computer Graphics- SCC 342
Graphics Shapes. Setup for using graphics You have to import the graphics library You can use either “import graphics” or “from graphics import *” or.
Ray tracing. New Concepts The recursive ray tracing algorithm Generating eye rays Non Real-time rendering.
Graphics Pipeline.
OPENGL Return of the Survival Guide. Buffers (0,0) OpenGL holds the buffers in a coordinate system such that the origin is the lower left corner.
Computer Graphic Creator: Mohsen Asghari Session 2 Fall 2014.
Informationsteknologi Monday, November 12, 2007Computer Graphics - Class 71 Today’s class Viewing transformation Menus Mandelbrot set and pixel drawing.
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.
Projections and Picking Wed 24 Sep 2003
1 Python Programming: An Introduction to Computer Science Chapter 3 Objects and Graphics.
Informationsteknologi Tuesday, November 6, 2007Computer Graphics - Class 41 Today’s class Input and interaction.
CS 4731: Computer Graphics Lecture 17: Texturing Emmanuel Agu.
3D Rendering with JOGL Introduction to Java OpenGL Graphic Library By Ricardo Veguilla
OpenGL Pixel Operations, Bitmaps, Fonts and Images The Current Raster Position Current raster position: A position in window coordinates where the next.
Cornell CS465 Fall 2004 Lecture 3© 2004 Steve Marschner 1 Ray Tracing CS 465 Lecture 3.
Cornell CS465 Fall 2004 Lecture 3© 2004 Steve Marschner 1 Ray Tracing CS 465 Lecture 3.
Geometric Objects and Transformations Chapter 4. Points, Scalars and Vectors  Points - position in space  Scalars - real numbers, complex numbers obey.
19/4/ :32 Graphics II Syllabus Selection and Picking Session 1.
COMP 175: Computer Graphics March 24, 2015
 Bitmap: A bitmap is a rectangular array of 0s and 1s that serves as a drawing mask for a corresponding rectangular portion of the window.  Applications:
Computer Graphics Texture Mapping Eriq Muhammad Adams
CSC461 Lecture 11: Interactive Programs Contents and Objectives Picking Writing modes – XOR/Copy Rubberbanding Display list.
Open GL Programming Speaker: 彭任右 Date: 2005/10/3.
Computational Biology, Part E Basic Principles of Computer Graphics Robert F. Murphy Copyright  1996, 1999, 2000, All rights reserved.
Korea University Korea University Computer Graphics Laboratory Computer Graphics Laboratory Jung Lee, Chapter 13.
CSE 470: Computer Graphics. 10/15/ Defining a Vertex A 2D vertex: glVertex2f(GLfloat x, GLfloat y); 2D vertexfloating pointopenGL parameter type.
Addison Wesley is an imprint of © 2010 Pearson Addison-Wesley. All rights reserved. Chapter 7 The Game Loop and Animation Starting Out with Games & Graphics.
Week 13 - Monday.  What did we talk about last time?  Exam 2!  Before that…  Polygonal techniques ▪ Tessellation and triangulation  Triangle strips,
Computing & Information Sciences Kansas State University Lecture 20 of 42CIS 636/736: (Introduction to) Computer Graphics Lecture 21 of 42 William H. Hsu.
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.
Computer Graphics Bing-Yu Chen National Taiwan University.
OpenGL Selection. Three Selection Methods Color coding (OpenGL) Selection mode (OpenGL) Selection ray (generic)
Games Development 1 Camera Projection / Picking CO3301 Week 8.
111/17/ :24 UML Solution Involves Selection of Discrete Representation Values.
OpenGL The Viewing Pipeline: Definition: a series of operations that are applied to the OpenGL matrices, in order to create a 2D representation from 3D.
OpenGL Viewing and Modeling Transformation Geb Thomas Adapted from the OpenGL Programming Guidethe OpenGL Programming Guide.
Basic Perspective Projection Watt Section 5.2, some typos Define a focal distance, d, and shift the origin to be at that distance (note d is negative)
1 Graphics CSCI 343, Fall 2015 Lecture 6 Viewing, Animation, User Interface.
Computer Graphics Camera Projection / Picking CO2409 Week 8 - Optional Advanced Material Not on Exam.
Chapters 5 2 March Classical & Computer Viewing Same elements –objects –viewer –projectors –projection plane.
CS COMPUTER GRAPHICS LABORATORY. LIST OF EXPERIMENTS 1.Implementation of Bresenhams Algorithm – Line, Circle, Ellipse. 2.Implementation of Line,
1 Georgia Tech, IIC, GVU, 2006 MAGIC Lab Rossignac Graphic pipeline  Scan-conversion algorithm (high level)  Pixels.
Chap 3 Viewing and Transformation
Lecture 7 Midterm Review. OpenGL Libraries gl: Basic OpenGL library, e.g. primitives. glu: OpenGL Utility library, a set of functions to create texture.
Details of Texture Mapping Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, December 1, 2003.
Coordinate Systems Lecture 1 Fri, Sep 2, The Coordinate Systems The points we create are transformed through a series of coordinate systems before.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
Selection Mode, Introduction to Widgets Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, October 6, 2003.
OpenGL CS418 Computer Graphics John C. Hart. OpenGL Based on GL (graphics library) by Silicon Graphics Inc. (SGI) Advantages: Runs on everything, including.
CS425 © 2003 Ray S. Babcock Pixels and Bitmaps ● OpenGL allows us to work directly with bits and groups of bits, or pixels, which flow down a parallel.
Texture Mapping CEng 477 Introduction to Computer Graphics.
Better Interactive Programs
“Computer Science is no more about computers than astronomy is about telescopes.” Professor Edsger Dijkstra.
Advanced Menuing, Introduction to Picking
Intro to lighting (Chapter 11)
Geb Thomas Adapted from the OpenGL Programming Guide
Class 26 more textures environmental textures Color ramps
Project 1: Into Space! CG Concepts Needed
Introduction to Computer Graphics with WebGL
Picking.
Better Interactive Programs
OpenGL program.
Computer Graphics Practical Lesson 8
Computer Graphics 3Practical Lesson
Class 27 more textures environmental textures Color ramps
Picking in OpenGL Yingcai Xiao.
Presentation transcript:

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

Example

How to do it cal/selection.htmhttp:// cal/selection.htm als:Pickinghttp://gpwiki.org/index.php/OpenGL:Tutori als:Picking g/index.php?openglwayhttp:// g/index.php?openglway

Color Picking sing_Unique_Color_IDshttp://gpwiki.org/index.php/OpenGL_Selection_U sing_Unique_Color_IDs

Color Picking: Step 1 When the user clicks the mouse: Render all the pickable objects in the scene, each with a unique color –How to render an object to be a specific color? glColor3f(r,g,b); Is this enough? glDisable(GL_TEXTURE2D); glDisable(GL_LIGHTING); glDisable(GL_FOG);

Color Picking: Step 2 Figure out what the color of the pixel is where the mouse was clicked void glReadPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid * data);Parametersx, y Specify the window coordinates of the first pixel that is read from the frame buffer. This location is the lower left corner of a rectangular block of pixels. width, height Specify the dimensions of the pixel rectangle. width and height of one correspond to a single pixel. format Specifies the format of the pixel data. typically GL_RGB, GL_RGBA, type Specifies the data type of the pixel data. Must be one of GL_UNSIGNED_BYTE, data Returns the pixel data. – How to set glReadPixels?

Color Picking: Step 2 GLint viewport[4]; glGetIntegerv(GL_VIEWPORT, viewport); glReadPixels(x, viewport[3] - y, 1, 1, GL_RGB, GL_UNSIGNED_BYTE, pixel); Why do we do ‘viewport[3] – y’ –OS will often report mouse positions with the origin at the upper left –GL always puts the origin at the lower left

Color Picking: Step 3 Once you know the unique color, you can identify the object that was picked –Details When you false color your objects, wont this screw up rendering? –Yes, but how can you prevent this? –Don’t call glutSwapBuffers() directly after doing this. –With double buffering, everything is initially drawn into the back buffer – the user only ever sees the front buffer. –What are some limitations of this approach?

GL_SELECT als:Picking Render twice –glRenderMode(GL_SELECT); –SetViewport to one pixel –It counts how many objects render to that pixel –Read back # (glRenderMode(GL_RENDER) –Identify objects – use name stack

GL_SELECT: Step 1 Tell GL which objects are pickable glRenderMode(GL_SELECT); –The default is glRenderMode(GL_RENDER); Use the Name stack glInitNames() – initializes/clears the name stack glPushName, glPopName, glLoadName –E.g., glPushName(Gluint name); - names are numbers – unique identifiers Render your objects

GL_SELECT: Step 2 Define a buffer to store information about what was picked #define BUFSIZE 512 GLuint selectBuf[BUFSIZE] … glSelectBuffer(BUFSIZE,selectBuf);

GL_SELECT: Step 3 Set the size of the selection region around the cursor to determine what has been picked –void gluPickMatrix(GLdouble x, GLdouble y, GLdouble delX, GLdouble delY, GLint * viewport); x,y – mouse coords (viewport[3] – y) delX,delY – width and height of region viewport – the current viewport (e.g., glGetIntegerv(GL_VIEWPORT, viewport))

GL_SELECT: Step 4 Process the ‘hits’ ( where the cursor region overlaps with pickable objects) numhits = glRenderMode(GL_RENDER); // assuming you were previously in GL_SELECT mode If there are hits, iterate through your select buffer (selectBuf) and decide how to process them

GL_SELECT: Select buffer example Hit Record ContentsDescription 0 No names have been stored for the first hit e+009Minimum depth for first hit e+009Maximum depth for first hit 1 Number of names for the second hit e+009 Minimum depth for second hit e+009 Maximum depth for second hit 6 A single name for the second hit 2 Number of names for the third hit e+009Minimum depth for third hit e+009Maximum depth for third hit 2First name for third hit 5Second name for third hit Depth values (which are in the range [0,1]) are multiplied by 2 32 – 1, before being placed in the hit record.

gluUnProject Take x-y window coordinates and figure out what the corresponding 3D coordinates are. –We are reversing the graphics pipeline! What is a 2D coordinate after being ‘unprojected’ into 3D?

gluUnProject x,y in window coordinates

gluUnProject GLint gluUnProject( GLdouble winX, GLdouble winY, GLdouble winZ, const GLdouble *model, const GLdouble *proj, const GLint *view, GLdouble* objX, GLdouble* objY, GLdouble* objZ ) –winX,winY,winZ : window coordinates –model: the modelview matrix you want to invert –proj: the projection matrix you want to invert –view: the viewport –objX,objY,objZ: the resulting 3D coordinates Why does the 2D window coordinates have 3 variables? –If winZ == 0, then the resulting point will be on the near plane –If winZ==1 then the resulting point will be on the far plane Create a ray based on these near and far points –Test for intersection with objects…

Ray-Object Intersections This is very similar to collision detection REMEMBER: you must project the window points into the same coordinate system (e.g., world coordinates) as the objects you are trying to select. Keep this in mind when selecting the modelview matrix to use You can do ray-BB, ray-sphere, or ray- triangle detection –The resulting accuracy will be the same as it is for the associated collision detection routines

Ray-sphere intersection (this is really for a line, but it works with some minor changes) If== 0 hit on surface If >0 intersection If <0 no intersection p is the intersection point t is a point on the ray v is the direction of the ray c is the position of the sphere r is the radius of the sphere

Ray-triangle intersection 1 Form a plane from the three vertices Calculate ray intersection with plane Where: x is the intersection between the ray and the plane o is the origin of the ray d is the direction of the ray n is the normal of the plane p is a point on the plane λ is the ray’s scalar parameter

Ray-triangle intersection 2 Use cross products and the properties of vertex winding to figure out if x is inside the triangle Where p 0,p 1,p 2 are vertices of the triangle x is the intersection point n is the triangle normal p0p0 p1p1 p2p2 x Intersection occurs if: x

Ray-BB intersection Find the ray intersection with one of the planes Test against all the other planes to see if that intersection is in the BB –(see point – plane collision detection lecture)