Advanced Computer Graphics (CS & SE )

Similar documents
Lecture 5: Viewing. CSE Computer Graphics (Fall 2010)

12. Selection. - The objects selected are specified by hit records in the selection buffer. E.R. Bachmann & P.L. McDowell MV 4202 Page 1 of 13

Getting Started. Overview (1): Getting Started (1): Getting Started (2): Getting Started (3): COSC 4431/5331 Computer Graphics.

Computer Graphics. Chapter 10 Three-Dimensional Viewing

Better Interactive Programs. Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico

CS380: Computer Graphics Viewing Transformation. Sung-Eui Yoon ( 윤성의 ) Course URL:

Viewing Transformation

The Viewing Pipeline adaptation of Paul Bunn & Kerryn Hugo s notes

COMP Computer Graphics and Image Processing. 5: Viewing 1: The camera. In part 1 of our study of Viewing, we ll look at ˆʹ U ˆ ʹ F ˆʹ S

Precept 2 Aleksey Boyko February 18, 2011

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

Describe the Orthographic and Perspective projections. How do we combine together transform matrices?

CIS 636 Interactive Computer Graphics CIS 736 Computer Graphics Spring 2011

OpenGL Transformations

Models and Architectures

Introduction to Computer Graphics with WebGL

1 Transformations. Chapter 1. Transformations. Department of Computer Science and Engineering 1-1

3D Viewing. With acknowledge to: Ed Angel. Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico

Spring 2013, CS 112 Programming Assignment 2 Submission Due: April 26, 2013

Lecture 4 Advanced Computer Graphics (CS & SE )

2D and 3D Viewing Basics

CS 4204 Computer Graphics

1 (Practice 1) Introduction to OpenGL

CSE 690: GPGPU. Lecture 2: Understanding the Fabric - Intro to Graphics. Klaus Mueller Stony Brook University Computer Science Department

Fachhochschule Regensburg, Germany, February 15, 2017

Computer Viewing Computer Graphics I, Fall 2008

Introduction to OpenGL Transformations, Viewing and Lighting. Ali Bigdelou

Surface Graphics. 200 polys 1,000 polys 15,000 polys. an empty foot. - a mesh of spline patches:

Fundamental Types of Viewing

Wire-Frame 3D Graphics Accelerator IP Core. C Library Specification

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

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

Overview. Viewing and perspectives. Planar Geometric Projections. Classical Viewing. Classical views Computer viewing Perspective normalization

Overview of Projections: From a 3D world to a 2D screen.

Lecture 4. Viewing, Projection and Viewport Transformations

3D Graphics Pipeline II Clipping. Instructor Stephen J. Guy

Computer Graphics (Basic OpenGL)

Notes on Assignment. Notes on Assignment. Notes on Assignment. Notes on Assignment

Better Interactive Programs

Geometry: Outline. Projections. Orthographic Perspective

Computer Graphics. Basic 3D Programming. Contents

CS 591B Lecture 9: The OpenGL Rendering Pipeline

Lecture 4 of 41. Lab 1a: OpenGL Basics

CS418 OpenGL & GLUT Programming Tutorial (IV) MP2 Bonus/Object Picking. Presented by : Wei-Wen Feng 2/20/2008

Three-Dimensional Graphics III. Guoying Zhao 1 / 67

CITSTUDENTS.IN VIEWING. Computer Graphics and Visualization. Classical and computer viewing. Viewing with a computer. Positioning of the camera

Graphics and Visualization

Computer Graphics and Visualization. Graphics Systems and Models

Computer Viewing. CITS3003 Graphics & Animation. E. Angel and D. Shreiner: Interactive Computer Graphics 6E Addison-Wesley

CS354 Computer Graphics Viewing and Modeling

COMP3421. Introduction to 3D Graphics

3D Graphics for Game Programming (J. Han) Chapter II Vertex Processing

3D graphics, raster and colors CS312 Fall 2010

COMS 4160: Problems on Transformations and OpenGL

Chapter 13 Selection and Feedback

COMP3421. Introduction to 3D Graphics

OpenGL: Open Graphics Library. Introduction to OpenGL Part II. How do I render a geometric primitive? What is OpenGL

COMP3421. Introduction to 3D Graphics

Transformation Pipeline

Today. Rendering pipeline. Rendering pipeline. Object vs. Image order. Rendering engine Rendering engine (jtrt) Computergrafik. Rendering pipeline

Android and OpenGL. Android Smartphone Programming. Matthias Keil. University of Freiburg

Visualizing Molecular Dynamics

CSC 470 Computer Graphics. Three Dimensional Viewing

CSC 470 Computer Graphics

CS 4204 Computer Graphics

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

Announcements. Submitting Programs Upload source and executable(s) (Windows or Mac) to digital dropbox on Blackboard

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

Matrix-Rechnung I ' z =... Universität Frankfurt

Introduction to OpenGL

OpenGL. Toolkits.

COMP Computer Graphics and Image Processing. a6: Projections. In part 2 of our study of Viewing, we ll look at. COMP27112 Toby Howard

Rasterization Overview

3D Viewing. CMPT 361 Introduction to Computer Graphics Torsten Möller. Machiraju/Zhang/Möller

7. 3D Viewing. Projection: why is projection necessary? CS Dept, Univ of Kentucky

Working Style of Program

Lecture 26 of 41. Picking Videos 5: More CGA

CSCI 4620/8626. The 2D Viewing Pipeline

6.837 Introduction to Computer Graphics Assignment 5: OpenGL and Solid Textures Due Wednesday October 22, 2003 at 11:59pm

Introduction to Computer Graphics 4. Viewing in 3D

CS 381 Computer Graphics, Fall 2008 Midterm Exam Solutions. The Midterm Exam was given in class on Thursday, October 23, 2008.

CSE4030 Introduction to Computer Graphics

Computer Graphics. Bing-Yu Chen National Taiwan University

Lecture 3 Sections 2.2, 4.4. Mon, Aug 31, 2009

3D Viewing. Introduction to Computer Graphics Torsten Möller. Machiraju/Zhang/Möller

Today s Agenda. Basic design of a graphics system. Introduction to OpenGL

3D Viewing Episode 2

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

Order of Transformations

Input and Interaction

Scientific Visualization Basics

Chapter 5. Projections and Rendering

part 3 Martin Samuelčík Room I4

The View Frustum. Lecture 9 Sections 2.6, 5.1, 5.2. Robb T. Koether. Hampden-Sydney College. Wed, Sep 14, 2011

OUTLINE. Learn the basic design of a graphics system Introduce pipeline architecture Examine software components for a graphics system

Loop Boundary - ignore edge vertex near boundary rule. use the same edge vertex rule. Deadline changed to Friday night(7/20) 11:59p Selection - extra

Lecture 4. Interaction / Graphical Devices. CS 354 Computer Graphics Sunday, January 20, 13

CSE 167: Introduction to Computer Graphics Lecture #4: Vertex Transformation

CS 4620 Program 3: Pipeline

Viewing with Computers (OpenGL)

Transcription:

Advanced Computer Graphics (CS & SE 233.420)

Topics Covered Picking Pipeline Viewing and Transformations

Rendering Modes OpenGL can render in one of three modes selected by glrendermode(mode) GL_RENDER Normal rendering to the frame buffer (default) GL_FEEDBACK Provides list of primitives rendered but no output to the frame buffer GL_SELECTION Each primitive in the view volume generates a hit record that is placed in a name stack which can be examined later

Picking Picking occurs when the mouse is positioned over an area of the screen to create and modify the viewing volume during selection The process of determine which object is beneath the mouse pointer is called picking Identify a user-defined object on the display In principle, it should be simple The mouse gives the position Should be able to determine to which object(s) a position corresponds Practical difficulties Pipeline architecture is feed forward, Hard to go from screen back to world Complicated by screen being 2D, world is 3D How close do we have to come to object to say we selected it?

The Name Stack The OpenGL API provides a mechanism for picking objects in a 3D scene The steps involved in detecting which objects are at the location where the mouse was clicked are: Get the window coordinates of the mouse Enter selection mode Redefine the viewing volume so that only a small area of the window around the cursor is rendered Render the scene, either using all primitives or only those relevant to the picking operation Exit selection mode and identify the objects which were rendered on that small part of the screen.

The Name Stack In order to identify the rendered objects using the OpenGL API you must name all relevant objects in your scene The OpenGL API allows you to give names to primitives, or sets of primitives (objects) glrendermode(gl_selection) When in selection mode, No objects are actually rendered in the framebuffer. Names of the objects (plus depth information) are collected in an array. For unnamed objects, only depth information is collected.

In GL Speak A hit occurs whenever a primitive is rendered in selection mode. Hit records are stored in the selection buffer. Upon exiting the selection mode OpenGL returns the selection buffer with the set of hit records. Since OpenGL provides depth information for each hit the application can then easily detect which object is closer to the user.

Using Selection Mode Initialize name buffer Enter selection mode (using mouse) Render scene with user-defined identifiers Reenter normal render mode This operation returns number of hits Examine contents of name buffer (hit records) Hit records include id and depth information

Manipulating the Name Stack OpenGL provides the following functions to manipulate the name stack glinitnames() initializes name stack Creates an empty name stack glpushname(id) Adds name to the top of the stack glpopname() Removes the name from top of the stack glloadname(id Replaces the top of the stack with name. It is the same as calling glpopname(); glpushname(name); Calls to the above functions are ignored when not in selection mode You can't place these functions inside a glbegin-glend construction

The Selection Mode Used for picking purposes The first step is to tell OpenGL where to store the hit records. This is accomplished with the following function: void glselectbuffer(glsizei size, GLuint *buffer); buffer : An array of unsigned integers. where OpenGL will store the hit records size : The size of the array Required to call this function before entering the selection mode Next you enter the selection mode with a call to void glrendermode(glenum mode); mode - use GL_SELECT to enter the rendering mode and GL_RENDER to return to normal rendering

Clearing Projection Matrix Redefine the viewing volume so that it renders only a small area around the place where the mouse was clicked. In order to do that it is necessary to set the matrix mode to GL_PROJECTION. Afterwards, the application should push the current matrix to save the normal rendering mode settings. Next initialise the matrix. The following snippet of code shows how to do this: glmatrixmode(gl_projection); glpushmatrix(); glloadidentity(); Result is a clean projection matrix

Redefine Viewing Volume First get the current viewport. This can be done querying OpenGL for the state variable GL_VIEWPORT (use the function glgetintegerv) Define the viewing volume so that rendering is done only in a small area around the cursor void glupickmatrix(gldouble x, GLdouble y, GLdouble witdth, GLdouble height, GLint viewport[4]); x,y : define the centre of the picking area width, height : The size of the picking region viewport : The current viewport Set your projection (perspective or orthogonal) just as you did for the normal rendering mode Finally get back to the modelview matrix mode, and initialise the Name Stack to start rendering

Redefine Viewing Volume The following code shows the sequence of function calls to do the above using a perspective projection glgetintegerv(gl_viewport,viewport); glupickmatrix(cursorx,viewport[3]-cursory,5,5,viewport);* gluperspective(45,ratio,0.1,1000); glmatrixmode(gl_modelview); glinitnames(); *Transforms the origin from the upper left corner, as provided by GLUT for example, into the bottom left corner Defines a 5x5 picking region

Processing the Hit Records In order to process the hit records Restore the original projection matrix. glmatrixmode(gl_projection); glpopmatrix(); glmatrixmode(gl_modelview); glflush(); Return to the normal rendering mode Num_hits = glrendermode(gl_render). This function returns the number of hit records that were created during rendering in the selection mode. Next, process the selection buffer. if (hits!= 0) processhits(hits,selectbuf);

Using Regions of the Screen Many applications use a simple rectangular arrangement of the screen Example: Maya, Photoshop Easier to look at mouse position and determine which area of screen it is in than using selection mode picking M E N U TOOLBAR

Camera Models The camera is modeled by its optical centre, C, and its retinal plane (or image plane) R. In each camera, a 3-D point, w=(x,y,z) T, in world coordinates (where the world coordinate frame is fixed arbitrarily) is projected into an image point m = (u,v) T in camera coordinates m = Pw P is the projection matrix We know perspective and orthogonal Can make your own P matrix (fish eye, wide angle, etc)

Camera Specification Six degrees of freedom Position of center of lens Orientation Lens Film size Orientation of film plane

Projections Rays (projectors) projected from the center of projection pass through each point of the models and intersect projection plane. Since everything is synthetic, the projection plane can be in front of the models, inside the models, or behind the models. 2 main types: perspective projection and parallel projection. Which type of projection is used depends on the needs of the user - whether the goal is the mathematically correct depiction of length and angles, or a realistic looking image of the object.

Parallel Projection Center of projection infinitely far from view plane Projectors will be parallel to each other Need to define the direction of projection (vector) 2 sub-types orthographic - direction of projection is normal to view plane oblique - direction of projection not normal to view plane Better for drafting / CAD applications

Perspective Projection Center of projection finitely far from view plane Projectors will not be parallel to each other Need to define the location of the center of projection (point) Classified into 1, 2, or 3-point perspective More visually realistic - has perspective foreshortening (objects further away appear smaller)

Advantages of Synthetic Camera Modeling Separation of objects, viewer, light sources Two-dimensional graphics is a special case of three-dimensional graphics Leads to simple software API Specify objects, lights, camera, attributes Let implementation determine image Leads to fast hardware implementation Via the pipeline

Following the Pipeline Transformations Much of the work in the pipeline is in converting object representations from one coordinate system to another World coordinates Camera coordinates Screen coordinates Every change of coordinates is equivalent to a matrix transformation

Clipping Just as a real camera cannot see the whole world, the virtual camera can only see part of the world space Objects that are not within this volume are said to be clipped out of the scene

Projection Must carry out the process that combines the 3D viewer with the 3D objects to produce the 2D image Perspective projections: all projectors meet at the center of projection Parallel projection: projectors are parallel, center of projection is replaced by a direction of projection

Rasterization If an object is visible in the image, the appropriate pixels in the frame buffer must be assigned colors Vertices assembled into objects Effects of lights and materials must be determined Polygons filled with interior colors/shades Must have also determine which objects are in front (hidden surface removal)

Pipeline

Viewing - Camera Analogy Set up the tripod and point the camera (view transform) Arrange the objects in the scene (model transform) Choose a lens and adjust zoom (projection transform) Choose photo print size (viewport transform)

OpenGL Transforms There are five transforms in OpenGL Vertices pass through these three. 1. Viewing Specifies location of camera 2. Modeling Moves objects around the scene 3. Projection Defines the viewing volume 4. Viewport Maps the 2D projection to the rendering window 5. Modelview Combination of viewing and modeling transforms Must be executed in a specific order.

Vertex Transformation

Modelview Matrix Modelview matrix converts object coordinates into eye coordinates Model transformations move the object, view transformations move the eyepoint, interchangeable!

Projection Matrix Selecting the lens, telephoto or wide angle Mathematically, selecting the volume to be mapped to viewport (mapping, homology, projective transform)

Perspective Division The divide by w step [ x y z z/d ] x projected = dx/z = x/(z/d) y projected = dy/z = y/(z/d)

Vertex Transformation Mapping window on projection plane to viewport Use glviewport Done in reshape function so you know what size the viewport has become

Viewing Use rotations and translations or void glulookat( GLdouble eyex, GLdouble eyey, GLdouble eyez, GLdouble centerx, GLdouble centery, GLdouble centerz, GLdouble upx, GLdouble upy, GLdouble upz); Eye point Center of field of view (aim point) Up vector Default: glulookat (0.0, 0.0, 0.0, 0.0, 0.0, -100.0, 0.0, 1.0, 0.0);

glulookat(eyex,eyey,eyez, centerx,centery,centerz, upx,upy,upz) Defines a viewing matrix and multiplies it to the right of the current matrix. The desired viewpoint is specified by eyex, eyey, and eyez. The centerx, centery, and centerz arguments specify any point along the desired line of sight, but typically they're some point in the center of the scene being looked at. The upx, upy, and upz arguments indicate which direction is up (that is, the direction from the bottom to the top of the viewing volume).

References Ed Angel Lecture notes and Slides by Edward Angel 2002 (Lectures 9 and 10) Open GL web page www.opengl.org http://www.opengl.org/resources/faq/technical http://www.newcyber3d.com/asia/selfstudy/tips/selection.htm http://www.lighthouse3d.com/opengl/displaylists http://www.mfcogl.com/multiview%20animation%20mfc_opengl.h tm www.cs.colorado.edu/~janem/cs4229/lec6_ch3-4.pdf http://www.codecolony.de/docs/camera.htm http://mathcs.holycross.edu/~croyden/graphics/assignments/sol5/s olution5.html www.cs.stevens-tech.edu/~quynh/courses/cs537- fa03/projection_gl.ppt http://gamecode.tripod.com/tut/tut03.htm http://www.basic4gl.net/introduction%20to%20opengl%20part%20 2.htm http://www.falloutsoftware.com/tutorials/gl/gl0.htm