OpenGL Selection. Three Selection Methods Color coding (OpenGL) Selection mode (OpenGL) Selection ray (generic)

Slides:



Advertisements
Similar presentations
Better Interactive Programs
Advertisements

Technische Universität München Computer Graphics SS 2014 Graphics Effects Rüdiger Westermann Lehrstuhl für Computer Graphik und Visualisierung.
Ray tracing. New Concepts The recursive ray tracing algorithm Generating eye rays Non Real-time rendering.
Graphics Pipeline.
Computer Graphic Creator: Mohsen Asghari Session 2 Fall 2014.
3D Graphics Rendering and Terrain Modeling
CAP4730: Computational Structures in Computer Graphics Visible Surface Determination.
Computer Graphics Visible Surface Determination. Goal of Visible Surface Determination To draw only the surfaces (triangles) that are visible, given a.
Informationsteknologi Thursday, November 22, 2007Computer Graphics - Class 111 Today’s class Clipping Parametric and point-normal form of lines Intersecting.
Ray Tracing Tutorial. Ray Casting One type of visibility algorithm.
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.
Foundations of Computer Graphics (Spring 2010) CS 184, Lecture 14: Ray Tracing
OpenGL (II). How to Draw a 3-D object on Screen?
Informationsteknologi Tuesday, November 6, 2007Computer Graphics - Class 41 Today’s class Input and interaction.
CHAPTER 7 Viewing and Transformations © 2008 Cengage Learning EMEA.
2D Transformations. World Coordinates Translate Rotate Scale Viewport Transforms Hierarchical Model Transforms Putting it all together.
3D Rendering with JOGL Introduction to Java OpenGL Graphic Library By Ricardo Veguilla
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.
19/4/ :32 Graphics II Syllabus Selection and Picking Session 1.
COMP 175: Computer Graphics March 10, 2015
COMP 175: Computer Graphics March 24, 2015
Technology and Historical Overview. Introduction to 3d Computer Graphics  3D computer graphics is the science, study, and method of projecting a mathematical.
CSE 381 – Advanced Game Programming Basic 3D Graphics
CSC461 Lecture 11: Interactive Programs Contents and Objectives Picking Writing modes – XOR/Copy Rubberbanding Display list.
Open GL Programming Speaker: 彭任右 Date: 2005/10/3.
The Viewing Pipeline (Chapter 4) 5/26/ Overview OpenGL viewing pipeline: OpenGL viewing pipeline: – Modelview matrix – Projection matrix Parallel.
Image Synthesis Rabie A. Ramadan, PhD 2. 2 Java OpenGL Using JOGL: Using JOGL: Wiki: You can download JOGL from.
Texture Mapping. Scope Buffers Buffers Various of graphics image Various of graphics image Texture mapping Texture mapping.
2 COEN Computer Graphics I Evening’s Goals n Discuss the mathematical transformations that are utilized for computer graphics projection viewing.
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.
1 Graphics CSCI 343, Fall 2015 Lecture 1 Introduction to Graphics Read: Chapter 1 of textbook.
CSC 461: Lecture 3 1 CSC461 Lecture 3: Models and Architectures  Objectives –Learn the basic design of a graphics system –Introduce pipeline architecture.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
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.
Rendering Overview CSE 3541 Matt Boggus. Rendering Algorithmically generating a 2D image from 3D models Raster graphics.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
1 Better Interactive Programs. 2 Objectives Learn to build more sophisticated interactive programs using ­Picking Select objects from the display Three.
2 COEN Computer Graphics I Evening’s Goals n Discuss application bottleneck determination n Discuss various optimizations for making programs execute.
Intro. to Advanced Lighting, Basic Ray Tracing Glenn G. Chappell U. of Alaska Fairbanks CS 481/681 Lecture Notes Monday, April.
Games Development 1 Camera Projection / Picking CO3301 Week 8.
Parallel Ray Tracer Computer Systems Lab Presentation Stuart Maier.
CSE 681 Introduction to 3D Graphics. CSE 681 Computer graphics is “the creation and manipulation of graphics images by means of computer.” (Marc Berger,
Image Synthesis Rabie A. Ramadan, PhD 4. 2 Review Questions Q1: What are the two principal tasks required to create an image of a three-dimensional scene?
Basic Ray Tracing CMSC 435/634.
Review on Graphics Basics. Outline Polygon rendering pipeline Affine transformations Projective transformations Lighting and shading From vertices to.
Chapters 5 2 March Classical & Computer Viewing Same elements –objects –viewer –projectors –projection plane.
Three-Dimensional Viewing
Projections. Viewports Windows can have separate viewports void glViewport(GLint x, GLint y, GLsizei width, GLsizei height ) x, y - Specify the lower.
Ray Tracing Fall, Introduction Simple idea  Forward Mapping  Natural phenomenon infinite number of rays from light source to object to viewer.
CS COMPUTER GRAPHICS LABORATORY. LIST OF EXPERIMENTS 1.Implementation of Bresenhams Algorithm – Line, Circle, Ellipse. 2.Implementation of Line,
11/24/ :45 Graphics II Shadow Maps Reflections Session 5.
RENDERING : Global Illumination
OpenGL and You I Cast, Therefore I Am. Ray Casting Idea is simple, implementation takes some work –Cast rays as if you were the camera –Determine intersection.
Selection Mode, Introduction to Widgets Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, October 6, 2003.
Chapter 1 Graphics Systems and Models Models and Architectures.
1 E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 Models and Architectures 靜宜大學 資訊工程系 蔡奇偉 副教授 2012.
Computer Graphics I, Fall Programming with OpenGL Part 2: Complete Programs.
OpenGL LAB III.
Visible Surface Detection
CSE 167 [Win 17], Lecture 15: Ray Tracing Ravi Ramamoorthi
3D Computer Graphics (3080/GV10) Week 5-6 Tutorial 3
Better Interactive Programs
Modeling 101 For the moment assume that all geometry consists of points, lines and faces Line: A segment between two endpoints Face: A planar area bounded.
Intro to lighting (Chapter 11)
Better Interactive Programs
Computer Graphics Practical Lesson 8
Picking in OpenGL Yingcai Xiao.
Presentation transcript:

OpenGL Selection

Three Selection Methods Color coding (OpenGL) Selection mode (OpenGL) Selection ray (generic)

Method 1: Color Coding To make a selection at (x, y): Draw a color-coded image in the mouse callback function, Read the pixel value from the back frame buffer, The pixel color tells you the selection. (x, y)

Method 1: Color Coding To read the pixel value: Only the visible object will be selected The nearest object (if using the depth test) The latest object (otherwise) To avoid the color-coded image from display Remember to use double buffering Don’t swap the frame buffer glReadPixels(x, y, width, height, format, type, *data) glReadBuffer(GL_BACK) default

Method 2: Selection Mode The idea is similar to color coding. You will still need to pretend to draw something. However, No need to assign unique colors. No need to use double buffering. The selection can ignore the visibility and pick multiple objects. OpenGL can help you do it.

Method 2: Selection Mode To start the fake drawing process: To specify the selection region: To store the selections: To give each object a name: glRenderMode(GL_SELECT) gluPickMatrix(x, y, width, height, viewport) glGetIntegerv(GL_VIEWPORT, viewport) glSelectBuffer(buffer_length, buffer) glInitNames(); glPushName(…); glLoadName(…);

An Example glRenderMode(GL_SELECT); int selectBuffer[100]; glSelectBuffer(100, selectBuffer); glMatrixMode(GL_PROJECTION); glLoadIdentity(); int vp[4]; glGetIntegerv(GL_VIEWPORT, vp); gluPickMatrix(x, y, 5, 5, vp); gluPerspective(10, 1, 1, 100); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); //Change camera view glInitNames(); glPushName(0); glLoadName(1); //Draw A, A has a name: 1 glLoadName(2); //Draw B, B has a name: 2 int hits=glRenderMode(GL_RENDER); //The selections are stored in the buffer

In the Selection Buffer

Some Tips The fake drawing process is the same as the regular drawing process, except for those selection functions. An object can have multiple names. If you don’t reset the projection matrix in your display function, remember to restore it after you finish the selection projection (using glPushMatrix and glPopMatrix). When multiple objects are selected, you can use the depth information to know which one is visible.

Method 3: Selection Ray It is a generic method, not limited to OpenGL. It is a basic component in ray tracing (an advanced rendering algorithm). Relies on the projection matrix and ray-object intersection tests. So it needs some effort to implement.

Basic Idea A pixel on the image is actually a ray. Any point on this ray will be projected onto this pixel. Image Plane Center of Projection An image (640*640)

Basic Idea So to find the selection, we can just test the intersection between the ray and any object. Image Plane Center of Projection An image (640*640)

Basic Idea Two questions: How to get this ray How to do the intersection test Image Plane Center of Projection An image (640*640)

To Get the Selection Ray Given a projection matrix M, which can be obtained by glGetFloatv(GL_PROJECTION_MATRIX, M) Given a selection pixel ( x, y ), for -1<x, y<1, which can be obtained by: x =mouse_x×2/screen_width-1 y =1-mouse_y×2/screen_height We know: Any point on the rayAny vector

To Get the Selection Ray So we can find two points on the ray: They need be transformed from the eye to the world coordinate system (how?): Finally, the ray is:

To Find The Intersection The ray-sphere intersection r C P Q s is the unknown. Solve it! The smallest s ( s>0 ) gives the earliest intersection.

To Find The Intersection The ray-triangle intersection Q V0V0 V2V2 V1V1 P N Let N be the triangle normal: R This is a linear equation. Solve s and find R. for R is in the triangle, if barycentric Coordinates 0≤b 0, b 1, b 2 ≤1.

Method 3: Selection Ray It does not need to read the frame buffer. It is flexible, independent of the rendering system. Each primitive type needs a ray intersection algorithm. Needs multiple matrix computation steps, so it is relatively slow.

Method 3: Selection Ray When the scene contains multiple objects? Test each of them and find the nearest intersection. It is slow, how to make it faster? Use Bounding Volume Hierarchy.