Projections and Picking Wed 24 Sep 2003

Slides:



Advertisements
Similar presentations
Better Interactive Programs
Advertisements

CS 352: Computer Graphics Chapter 7: The Rendering Pipeline.
Graphics Pipeline.
Computer Graphic Creator: Mohsen Asghari Session 2 Fall 2014.
Computer Graphics Viewing.
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2005 Tamara Munzner Picking Week 10, Mon Mar.
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2007 Tamara Munzner Viewing/Projections I.
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2005 Tamara Munzner Prog 2, Kangaroo Hall.
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2008 Tamara Munzner Viewing/Projections IV.
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2005 Tamara Munzner Projections II Week 4,
University of British Columbia CPSC 314 Computer Graphics May-June 2005 Tamara Munzner Picking, Collision Week.
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2008 Tamara Munzner Viewing/Projections III.
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2007 Tamara Munzner Viewing/Projections II.
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2007 Tamara Munzner Viewing/Projections III.
Foundations of Computer Graphics (Spring 2010) CS 184, Lecture 5: Viewing
Objectives Derive the perspective projection matrices used for standard OpenGL projections Derive the perspective projection matrices used for standard.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Better Interactive Programs Ed Angel Professor of Computer Science, Electrical and Computer.
University of British Columbia CPSC 414 Computer Graphics Week 3, Monday 15 Oct 03 © Tamara Munzner 1 Hierarchies, Display Lists recap: matrix hierarchies,
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2008 Tamara Munzner Viewing/Projections I.
University of British Columbia CPSC 414 Computer Graphics © Tamara Munzner 1 Viewing and Projections Mon 22 Sep 2003 project 1 solution demo recap: projections.
University of British Columbia CPSC 414 Computer Graphics © Tamara Munzner 1 Midterm Review Week 7, Wed 16 Oct 2003 midterm review project 1 demos, hall.
OpenGL (II). How to Draw a 3-D object on Screen?
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2007 Tamara Munzner Picking II, Collision.
University of British Columbia CPSC 414 Computer Graphics © Tamara Munzner 1 Picking and Lighting Week 4, Fri 26 Sep 2003 recap: viewports and picking.
Informationsteknologi Tuesday, November 6, 2007Computer Graphics - Class 41 Today’s class Input and interaction.
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.
1 Perception, Illusion and VR HNRS 299, Spring 2008 Lecture 19 Other Graphics Considerations Review.
19/4/ :32 Graphics II Syllabus Selection and Picking Session 1.
COMP 175: Computer Graphics March 24, 2015
CSC461 Lecture 11: Interactive Programs Contents and Objectives Picking Writing modes – XOR/Copy Rubberbanding Display list.
MIT EECS 6.837, Durand and Cutler Graphics Pipeline: Projective Transformations.
Korea University Korea University Computer Graphics Laboratory Computer Graphics Laboratory Jung Lee, Chapter 13.
Week 2 - Friday.  What did we talk about last time?  Graphics rendering pipeline  Geometry Stage.
Advanced Computer Graphics Depth & Stencil Buffers / Rendering to Textures CO2409 Computer Graphics Week 19.
CSE 470: Computer Graphics. 10/15/ Defining a Vertex A 2D vertex: glVertex2f(GLfloat x, GLfloat y); 2D vertexfloating pointopenGL parameter type.
OpenGL Conclusions OpenGL Programming and Reference Guides, other sources CSCI 6360/4360.
Computing & Information Sciences Kansas State University Lecture 20 of 42CIS 636/736: (Introduction to) Computer Graphics Lecture 21 of 42 William H. Hsu.
1 Better Interactive Programs. 2 Objectives Learn to build more sophisticated interactive programs using ­Picking Select objects from the display Three.
OpenGL Selection. Three Selection Methods Color coding (OpenGL) Selection mode (OpenGL) Selection ray (generic)
Games Development 1 Camera Projection / Picking CO3301 Week 8.
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2007 Tamara Munzner Procedural Approaches.
1 Perception and VR MONT 104S, Fall 2008 Lecture 21 More Graphics for VR.
CS 450: COMPUTER GRAPHICS PROJECTIONS SPRING 2015 DR. MICHAEL J. REALE.
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)
Computer Graphics Camera Projection / Picking CO2409 Week 8 - Optional Advanced Material Not on Exam.
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.
Foundations of Computer Graphics (Spring 2012) CS 184, Lecture 5: Viewing
Viewing
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2007 Tamara Munzner Viewing/Projections IV.
Viewing and Projection
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.
Lecture 13: Raster Graphics and Scan Conversion
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2010 Tamara Munzner Viewing/Projection V,
Computer Graphics I, Fall Programming with OpenGL Part 2: Complete Programs.
Viewing. Classical Viewing Viewing requires three basic elements - One or more objects - A viewer with a projection surface - Projectors that go from.
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2008 Tamara Munzner Viewing/Projections I.
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2016
Better Interactive Programs
CSCE 441 Computer Graphics 3-D Viewing
CSC461: Lecture 20 Parallel Projections in OpenGL
Viewing/Projections I Week 3, Fri Jan 25
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2016
Introduction to Computer Graphics with WebGL
Better Interactive Programs
Lecture 13 Clipping & Scan Conversion
Viewing III Week 4, Wed Jan 27
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2016
Clipping University of British Columbia CPSC 314 Computer Graphics
Presentation transcript:

Projections and Picking Wed 24 Sep 2003 project 1 solution demo recap: projections 2 projections 3 picking

News Project 1 solution executable available Readings reminder idea of what’s expected no need to copy look and feel exactly Readings reminder Chapter 5 Week 4, Wed 24 Sep 03 © Tamara Munzner

Projections recap

Transforming View Volumes orthographic view volume x z VCS y x=left y=top x=right z=-far z=-near y=bottom perspective view volume NDCS y (1,1,1) z (-1,-1,-1) x Week 4, Wed 24 Sep 03 © Tamara Munzner

Basic Perspective Projection y P(x,y,z) similar triangles P(x’,y’,d) z z=d also but nonuniform foreshortening not affine Week 4, Wed 24 Sep 03 © Tamara Munzner

Basic Perspective Projection can express as homogenous 4x4 matrix! Week 4, Wed 24 Sep 03 © Tamara Munzner

Projective Transformations determining the matrix representation need to observe 5 points in general position, e.g. [left,0,0,1]T[-1,0,0,1]T [0,top,0,1]T[0,1,0,1]T [0,0,-f,1]T[0,0,1,1]T [0,0,-n,1]T[0,0,-1,1]T [left*f/n,top*f/n,-f,1]T[-1,1,1,1]T solve resulting equation system to obtain matrix Week 4, Wed 24 Sep 03 © Tamara Munzner

OpenGL Orthographic Matrix scale, translate, reflect for new coord sys Week 4, Wed 24 Sep 03 © Tamara Munzner

OpenGL Perspective Matrix shear, scale, reflect for new coord sys Week 4, Wed 24 Sep 03 © Tamara Munzner

Projection Normalization viewing clipping normalized device VCS CCS NDCS projection transformation perspective division alter w / w distort such that orthographic projection of distorted objects is desired persp projection separate division from standard matrix multiplies division: normalization Week 4, Wed 24 Sep 03 © Tamara Munzner

Projections 3

Demos Brown Projections Demos http://www.cs.brown.edu/exploratories/freeSoftware/catalogs/viewing_techniques.html Nate Robbins tutorial (take 2): http://www.xmission.com/~nate/tutors.html Week 4, Wed 24 Sep 03 © Tamara Munzner

Perspective Example view volume left = -1, right = 1 bot = -1, top = 1 near = 1, far = 4 Week 4, Wed 24 Sep 03 © Tamara Munzner

Perspective Example view volume left = -1, right = 1 tracks in VCS: bot = -1, top = 1 near = 1, far = 4 tracks in VCS: left x=-1, y=-1 right x=1, y=-1 x=-1 x=1 1 ymax-1 z=-4 real midpoint z=-1 -1 -1 1 xmax-1 x -1 NDCS (z not shown) DCS (z not shown) z VCS top view Week 4, Wed 24 Sep 03 © Tamara Munzner

Perspective Example / w Week 4, Wed 24 Sep 03 © Tamara Munzner

Viewport Transformation generate pixel coordinates map x, y from range –1…1 (normalized device coordinates) to pixel coordinates on the display involves 2D scaling and translation y display x viewport Week 4, Wed 24 Sep 03 © Tamara Munzner

Viewport Transformation (1,1) (w,h) DCS b NDCS a y (-1,-1) x (0,0) OpenGL glViewport(x,y,a,b); default: glViewport(0,0,w,h); Week 4, Wed 24 Sep 03 © Tamara Munzner

Projective Rendering Pipeline glVertex3f(x,y,z) object world viewing alter w OCS WCS VCS glFrustum(...) projection transformation modeling transformation viewing transformation clipping glTranslatef(x,y,z) glRotatef(th,x,y,z) .... gluLookAt(...) / w CCS perspective division normalized device OCS - object coordinate system WCS - world coordinate system VCS - viewing coordinate system CCS - clipping coordinate system NDCS - normalized device coordinate system DCS - device coordinate system glutInitWindowSize(w,h) glViewport(x,y,a,b) NDCS viewport transformation device DCS Week 4, Wed 24 Sep 03 © Tamara Munzner

Picking

Interactive Object Selection move cursor over object, click how to decide what is below? ambiguity many 3D world objects map to same 2D point four common approaches manual ray intersection bounding extents backbuffer color coding selection region with hit list Picking and 3D Selection Pick: Select an object by positioning mouse over it and clicking. Question: How do we decide what was picked? We could do the work ourselves: Map selection point to a ray; Intersect with all objects in scene. Let OpenGL/graphics hardware do the work. Idea: Draw entire scene, and ``pick'' anything drawn near the cursor. Only ``draw'' in a small viewport near the cursor. Just do clipping, no shading or rasterization. Need a method of identifying ``hits''. OpenGL uses a name stack managed by glInitNames(), glLoadName(), glPushName(), and glPopName(). ``Names'' are unsigned integers When hit occurs, copy entire contents of stack to output buffer. Process: Set up pick buffer Initialize name stack May need pushName(-1); Save old projective transformation and set up a new one Draw your scene with appropriate use of name stack Restore projective transformation Query for number of hits and process them A hit occurs if a draw occurs in the (small) viewport All information (except 'hits') is stored in buffer given with glSelectBuffer Example: Two objects Might pick none Might pick either one Might pick both glSelectBuffer(size, buffer); /* initialize */ glRenderMode(GL_SELECT); glInitNames(); glPushName(-1); glGetIntegerv(GL_VIEWPORT,viewport); /* set up pick view */ glMatrixMode(GL_PROJECTION); glPushMatrix(); glIdentity(); gluPickMatrix(x,y,w,h,viewport); glMatrixMode(GL_MODELVIEW); ViewMatrix(); glLoadName(1); Draw1(); glLoadName(2); Draw2(); glMatrixMode(GL_PROJECTION); glPopMatrix(); glMatrixMode(GL_MODELVIEW); hits = glRenderMode(GL_RENDER); Hits stored consequetively in array In general, if h is the number of hits, the following is returned. hits = h. h hit records, each with four parts: The number of items q on the name stack at the time of the hit (1 int). The minimum z value amoung the primitives hit (1 int). The maximum z value amoung the primitives hit (1 int). The contents of the hit stack, deepest element first (q ints). At most one hit between each call glRenderMode or a change to name stack In our example, you get back the following: If you click on Item 1 only: hits = 1, buffer = 1, min(z1), max(z1), 1. If you click on Item 2 only: hits = 1, buffer = 1, min(z2), max(z2), 2. If you click over both Item 1 and Item 2: hits = 2, buffer = 1, min(z1), max(z1), 1, 1, min(z2), max(z2), 2. More complex example: /* initialization stuff goes here */ glPushName(1); Draw1(); /* stack: 1 */ glPushName(1); Draw1_1(); /* stack: 1 1 */ glPushName(1); Draw1_1_1(); /* stack: 1 1 1 */ glPopName(); glPushName(2); Draw1_1_2(); /* stack: 1 1 2 */ glPopName(); glPopName(); glPushName(2); /* stack: 1 2 */ Draw1_2(); glPopName(); glPopName(); glPushName(2); Draw2(); /* stack: 2 */ glPopName(); /* wrap-up stuff here */ What you get back: If you click on Item 1: hits = 1, buffer = 1, min(z1), max(z1), 1. If you click on Items 1:1:1 and 1:2: hits = 2, buffer = 3, min(z111), max(z111), 1, 1, 1, 2, min(z12), max(z12), 1, 2. If you click on Items 1:1:2, 1:2, and 2: hits = 3, buffer = 3, min(z112), max(z112), 1, 1, 2, 2, min(z12), max(z12), 1, 2, 1, min(z2), max(z2), 2. Important Details: Make sure that projection matrix is saved with a glPushMatrix() and restored with a glPopMatrix(). glRenderMode(GL_RENDER) returns negative if buffer not big enough. When a hit occurs, a flag is set. Entry to name stack only made at next gl*Name(s) or glRenderMode call. So, each draw block can only generate at most one hit. Readings: GL Programming Manual, Chapter 12 -------------------- The user provides each object of interest with a “name” (in fact, the name is an integer). The user defines a small region of the screen. Typically, this is a rectangle that includes the mouse position and a few pixels either side. OpenGL then renders the scene in selection mode. Whenever a named object is displayed inside the selected region, a “hit record”, containing its name and some other information is added to the “selection list”. The user examines the hit records to determine the object — or objects — selected. Week 4, Wed 24 Sep 03 © Tamara Munzner

Manual Ray Intersection do all computation at application level map selection point to a ray intersect ray with all objects in scene. advantages no library dependence y VCS x Week 4, Wed 24 Sep 03 © Tamara Munzner

Manual Ray Intersection do all computation at application level map selection point to a ray intersect ray with all objects in scene. advantages no library dependence disadvantages difficult to program slow: work to do depends on total number and complexity of objects in scene Week 4, Wed 24 Sep 03 © Tamara Munzner

Bounding Extents keep track of axis-aligned bounding rectangles advantages conceptually simple easy to keep track of boxes in world space Week 4, Wed 24 Sep 03 © Tamara Munzner

Bounding Extents disadvantages extensions low precision must keep track of object-rectangle relationship extensions do more sophisticated bound bookkeeping Week 4, Wed 24 Sep 03 © Tamara Munzner

Backbuffer Color Coding use backbuffer for picking create image as computational entity never displayed to user redraw all objects in backbuffer turn off shading calculations set unique color for each pickable object store in table read back pixel at cursor location check against table Week 4, Wed 24 Sep 03 © Tamara Munzner

Backbuffer Color Coding advantages conceptually simple variable precision disadvantages number of color bits must be adequate introduce 2x redraw delay Week 4, Wed 24 Sep 03 © Tamara Munzner

Backbuffer Example for(int i = 0; i < 2; i++) for(int j = 0; j < 2; j++) { glPushMatrix(); switch (i*2+j) { case 0: glColor3ub(255,0,0);break; case 1: glColor3ub(0,255,0);break; case 2: glColor3ub(0,0,255);break; case 3: glColor3ub(250,0,250);break; } glTranslatef(i*3.0,0,-j * 3.0) glCallList(snowman_display_list); glPopMatrix(); } glColor3f(1.0f, 1.0f, 1.0f); for(int i = 0; i < 2; i++) for(int j = 0; j < 2; j++) { glPushMatrix(); glTranslatef(i*3.0,0,-j * 3.0); glColor3f(1.0f, 1.0f, 1.0f); glCallList(snowman_display_list); glPopMatrix(); } http://www.lighthouse3d.com/opengl/picking/ Week 4, Wed 24 Sep 03 © Tamara Munzner

Select/Hit use small region around cursor for viewport assign per-object integer keys (names) redraw in special mode store hit list of objects in region examine hit list OpenGL support Week 4, Wed 24 Sep 03 © Tamara Munzner

Viewport small rectangle around cursor why rectangle instead of point? change coord sys so fills viewport why rectangle instead of point? people aren’t great at positioning mouse Fitts’s Law: time to acquire a target is function of the distance to and size of the target allow several pixels of slop Week 4, Wed 24 Sep 03 © Tamara Munzner

Viewport tricky to compute simple utility command invert viewport matrix, set up new orthogonal projection simple utility command gluPickMatrix(x,y,w,h,viewport) x,y: cursor point w,h: sensitivity/slop (in pixels) push old setup first, so can pop it later Week 4, Wed 24 Sep 03 © Tamara Munzner

Render Modes glRenderMode(mode) GL_RENDER: normal color buffer default GL_SELECT: selection mode for picking (GL_FEEDBACK: report objects drawn) Week 4, Wed 24 Sep 03 © Tamara Munzner

Name Stack “names” are just integers glInitNames() flat list glLoadName(name) or hierarchy supported by stack glPushName(name), glPopName can have multiple names per object stack is at least 64 levels deep Week 4, Wed 24 Sep 03 © Tamara Munzner

Hierarchical Names Example for(int i = 0; i < 2; i++) { glPushName(i); for(int j = 0; j < 2; j++) { glPushMatrix(); glPushName(j); glTranslatef(i*10.0,0,j * 10.0); glPushName(HEAD); glCallList(snowManHeadDL); glLoadName(BODY); glCallList(snowManBodyDL); glPopName(); glPopName(); glPopMatrix(); } glPopName(); } http://www.lighthouse3d.com/opengl/picking/ Week 4, Wed 24 Sep 03 © Tamara Munzner

Hit List glSelectBuffer(buffersize, *buffer) where to store hit list data on hit, copy entire contents of name stack to output buffer. hit record number of names on stack minimum and minimum depth of object vertices depth lies in the z-buffer range [0,1] multiplied by 2^32 -1 then rounded to nearest int Week 4, Wed 24 Sep 03 © Tamara Munzner

Separate Pick Function? use same function to draw and pick simpler to code name stack commands ignored in render mode customize functions for each potentially more efficient can avoid drawing unpickable objects Week 4, Wed 24 Sep 03 © Tamara Munzner

Select/Hit advantages disadvantages faster flexible precision OpenGL support means hardware accel only do clipping work, no shading or rasterization flexible precision size of region controllable flexible architecture custom code possible, e.g. guaranteed frame rate disadvantages more complex Week 4, Wed 24 Sep 03 © Tamara Munzner