CS 490: Computer Graphics Chapter 5: Viewing. Interactive Computer GraphicsChapter 5 - 2 Overview Specifying the viewpoint Specifying the projection Types.

Slides:



Advertisements
Similar presentations
Computer Graphics - Viewing -
Advertisements

Defining the Viewing Coordinate System
Three-Dimensional Viewing Sang Il Park Sejong University Lots of slides are stolen from Jehee Lee’s.
Based on slides created by Edward Angel
Viewing and Transformation
Viewing and Projections
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Computer Viewing Ed Angel Professor of Computer Science, Electrical and Computer Engineering,
CS 352: Computer Graphics Chapter 5: Viewing. Interactive Computer GraphicsChapter Overview Specifying the viewpoint Specifying the projection Types.
Viewing Doug James’ CG Slides, Rich Riesenfeld’s CG Slides, Shirley, Fundamentals of Computer Graphics, Chap 7 Wen-Chieh (Steve) Lin Institute of Multimedia.
OpenGL (II). How to Draw a 3-D object on Screen?
CS 4731: Computer Graphics Lecture 11: 3D Viewing Emmanuel Agu.
1 Chapter 5 Viewing. 2 Perspective Projection 3 Parallel Projection.
Informationsteknologi Wednesday, November 14, 2007Computer Graphics - Class 81 Today’s class Orthogonal matrices Quaternions Shears Synthetic camera Viewing.
Introduction to 3D viewing 3D is just like taking a photograph!
Computer Graphics (fall 2009)
UBI 516 Advanced Computer Graphics Three Dimensional Viewing
Advanced Computer Graphics Three Dimensional Viewing
The Viewing Pipeline (Chapter 4) 5/26/ Overview OpenGL viewing pipeline: OpenGL viewing pipeline: – Modelview matrix – Projection matrix Parallel.
CS559: Computer Graphics Lecture 9: Projection Li Zhang Spring 2008.
Viewing Angel Angel: Interactive Computer Graphics5E © Addison-Wesley
Chapter 5 Viewing.
C O M P U T E R G R A P H I C S Guoying Zhao 1 / 67 C O M P U T E R G R A P H I C S Guoying Zhao 1 / 67 Computer Graphics Three-Dimensional Graphics III.
Graphics Graphics Korea University cgvr.korea.ac.kr 3D Viewing 고려대학교 컴퓨터 그래픽스 연구실.
Computer Graphics Bing-Yu Chen National Taiwan University.
Fundamentals of Computer Graphics Part 5 Viewing prof.ing.Václav Skala, CSc. University of West Bohemia Plzeň, Czech Republic ©2002 Prepared with Angel,E.:
CAP 4703 Computer Graphic Methods Prof. Roy Levow Chapter 5.
Demetriou/Loizidou – ACSC330 – Chapter 5 Viewing Dr. Giorgos A. Demetriou Computer Science Frederick Institute of Technology.
Computer Graphics I, Fall 2010 Computer Viewing.
CS 450: COMPUTER GRAPHICS PROJECTIONS SPRING 2015 DR. MICHAEL J. REALE.
Computer Graphics Zhen Jiang West Chester University.
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.
Viewing Chapter 5. CS 480/680 2Chapter 5 -- Viewing Introduction: Introduction: We have completed our discussion of the first half of the synthetic camera.
OpenGL Viewing and Modeling Transformation Geb Thomas Adapted from the OpenGL Programming Guidethe OpenGL Programming Guide.
Graphics Graphics Korea University kucg.korea.ac.kr Viewing 고려대학교 컴퓨터 그래픽스 연구실.
Review on Graphics Basics. Outline Polygon rendering pipeline Affine transformations Projective transformations Lighting and shading From vertices to.
The Camera Analogy ► Set up your tripod and point the camera at the scene (viewing transformation) ► Arrange the scene to be photographed into the desired.
Chapters 5 2 March Classical & Computer Viewing Same elements –objects –viewer –projectors –projection plane.
Three-Dimensional Viewing
12/24/2015 A.Aruna/Assistant professor/IT/SNSCE 1.
©2005, Lee Iverson Lee Iverson UBC Dept. of ECE EECE 478 Viewing and Projection.
Graphics CSCI 343, Fall 2015 Lecture 16 Viewing I
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Classical Viewing Ed Angel Professor of Computer Science, Electrical and Computer Engineering,
Classical Viewing Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico.
Taxonomy of Projections FVFHP Figure Taxonomy of Projections.
CS559: Computer Graphics Lecture 9: 3D Transformation and Projection Li Zhang Spring 2010 Most slides borrowed from Yungyu ChuangYungyu Chuang.
Viewing and Projection. The topics Interior parameters Projection type Field of view Clipping Frustum… Exterior parameters Camera position Camera orientation.
Classical Viewing Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico.
CS 551 / 645: Introductory Computer Graphics Viewing Transforms.
Viewing Angel Angel: Interactive Computer Graphics5E © Addison-Wesley
CS5500 Computer Graphics March 20, Computer Viewing Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts.
1 E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 Computer Viewing Isaac Gang University of Mary Hardin-Baylor.
OpenGL LAB III.
Viewing. Classical Viewing Viewing requires three basic elements - One or more objects - A viewer with a projection surface - Projectors that go from.
Viewing 고려대학교 컴퓨터 그래픽스 연구실 kucg.korea.ac.kr.
Rendering Pipeline Fall, 2015.
Viewing.
Computer Graphics - Chapter 5 Viewing
Computer Viewing.
Isaac Gang University of Mary Hardin-Baylor
CSCE 441 Computer Graphics 3-D Viewing
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.
CSC461: Lecture 19 Computer Viewing
Fundamentals of Computer Graphics Part 5 Viewing
Type of View Perspective View COP(Center of Plane) Diminution of size
Viewing (Projections)
Viewing (Projections)
Interactive Computer Graphics Viewing
Computer Graphics 3Practical Lesson
CS 352: Computer Graphics Chapter 5: Viewing.
Presentation transcript:

CS 490: Computer Graphics Chapter 5: Viewing

Interactive Computer GraphicsChapter Overview Specifying the viewpoint Specifying the projection Types of projections Viewing APIs Walking through a scene Projections and shadows

How do cameras work? Interactive Computer GraphicsChapter 5 - 3

Synthentic camera model 1. Camera is placed at a location, pointed in a direction (modeling matrix) 2. 3D points are flattened onto the viewing plane (projection matrix) What do we need to know about the camera (real or synthetic)? Interactive Computer GraphicsChapter 5 - 4

Synthetic camera parameters Position of camera Direction it is pointed [look vector] Angle of film to look vector [view plane normal] Rotation around viewing direction [up vector] Height angle (zoom setting) [fovy] Aspect ratio of "film" (width/height) Front and back clipping planes >>Limit extent of camera’s view by rendering (parts of) objects lying between them and throwing away everything outside of them Focal length Field of view Shutter speed Interactive Computer GraphicsChapter 5 - 5

Interactive Computer GraphicsChapter 5 - 6

Perspective distortion How would you film dizziness? Vertigo effect [2] Vertigo effect2 Interactive Computer GraphicsChapter 5 - 7

Interactive Computer GraphicsChapter Projections Basic Elements: Objects, viewer Projection plane Projectors Center of projection Direction of projection (DOP) Basic Types Perspective Parallel (COP at infinity)

Interactive Computer GraphicsChapter Classical viewing

Interactive Computer GraphicsChapter Orthographic projection Orthographic: parallel projection with projectors perpendicular to the projection plane. Often used as front, side, top views for 3D design Importance: preservation of distance and angle Often used for top, front, and size views, e.g. in a modeling program or working drawing

Interactive Computer GraphicsChapter Perspective projection Perspective projections: projectors converge at COP Classical perspective views: 1, 2, and 3-point (1, 2, or 3 vanishing points) Difference: how many of the principle axes of the object are parallel to projection plane (I.e., depends on relationship of object to viewing frame)

Computer viewing Interactive Computer GraphicsChapter There are three aspects of the viewing process, all implemented in the pipeline: Positioning the camera: Setting the model-view matrix. Selecting a lens: Setting the projection matrix. Clipping: Setting the view volume.

Interactive Computer GraphicsChapter Position the camera By default, camera is at origin, looking in –z dir To “move the camera”, set up a modelview matrix that moves objects that are drawn Ignore Z-coordinate when drawing E.g. dimetric view? modelview = identity translate(0,0,-d) rotate(-45, );

Interactive Computer GraphicsChapter Exercise: look from +x axis How would you change the camera to generate a view down the +x axis to origin? Do this before displaying objects: modelview = identity; translate(0, 0, -d); rotate(-90, [0, 1, 0]);

Interactive Computer GraphicsChapter Exercise: front/top view How would you change the camera to generate a view from (0, 10, 10) to origin? Do this before displaying objects: modelview = identity; translate(0,0,-14.14); rotate(45, [1, 0, 0]);

Interactive Computer GraphicsChapter Helper function: lookAt Most 3D toolkits let you position the camera by setting eyepoint, lookpoint, and up direction lookAt(X eye, Y eye, Z eye, X at, Y at, Z at, X up, Y up, Z up ): Effect: set the modelview matrix

Rolling your own lookAt How could you write your own lookAt function? lookAt(X eye, Y eye, Z eye, X at, Y at, Z at, X up, Y up, Z up ): Interactive Computer GraphicsChapter

Defining a lookAt function lookAt(X eye, Y eye, Z eye, X at, Y at, Z at, X up, Y up, Z up ): translate to origin rotate so that points in the Z direction normalize trackball-like rotation to rotate so is trackball-like rotation Interactive Computer GraphicsChapter

Interactive Computer GraphicsChapter Camera API 2: uvn frame Camera parameters: VRP: view reference point, a point on the image plane VPN: view plane normal (n) VUP: vector in up direction (also need viewing direction, if not VPN) Result: viewing coordinate system, u-v-n. v = projection of VUP onto image plane u = v x n u, v axes: coordinates in the image plane n axis: normal to image plane

Interactive Computer GraphicsChapter Camera API 3: roll, pitch, yaw Specify location + orientation: roll, pitch, yaw These angles are specified relative to the center of mass of the vehicle and to a coordinate system aligned along the axes of the vehicle, as shown in Figure

2. Specify projection Interactive Computer GraphicsChapter Once we have located and pointed the camera along the –z axis, we still need to specify the lens (projection).

Parallel projection We’re already looking along the –z axis Set z=0 for all points (or ignore z coordinate when rendering) Interactive Computer GraphicsChapter

Interactive Computer GraphicsChapter Parallel projection View volume is generally specified with clipping planes: e.g. glOrtho(xmin, xmax, ymin, ymax, near, far) Z clipping planes at –near and –far The near (front) clipping plane is located a distance near from the origin, and the far (back) clipping plane is at a distance far from the origin. All these values are in camera coordinates.We will derive a function mat4 Ortho(GLfloat left, GLfloat right, GLfloat bottom, GLfloat top,GLfloat near, GLfloat far)

Parallel projection Interactive Computer GraphicsChapter

Perspective projection Need to build appropriate perspective projection matrix into vertex shader What kind of transformation would this be? Interactive Computer GraphicsChapter

Interactive Computer GraphicsChapter Perspective projections COP at origin Looking in –z direction Projection plane in front of origin at z=d

Interactive Computer GraphicsChapter Foreshortening By similar triangles in previous image, we see that and similarly for y. Using the perspective matrix we get p’ = Adding divide-by-w to the graphics pipeline gives the correct result.

Perspective Frustum Perspective viewing region is a “frustum”: Viewplane normally coincides with front clip plane Interactive Computer GraphicsChapter

Interactive Computer GraphicsChapter Camera APIs In raw OpenGL ES, you “position the camera” by programming a vertex shader to apply a modelview matrix Frameworks provide functions to build a viewing matrix for you, using a “camera API” Example: perspectiveCamera(FOV, aspect, near, far)

Perspective projection 3D graphics toolkits provide tools for specifying a perspective projection, e.g. Interactive Computer GraphicsChapter

Interactive Computer GraphicsChapter Shadows How can one generate shadows in a scene using interactive graphics techniques?shadows In general it's hard, not supported in standard graphics pipeline—you need to know where everything is globally to render a point locally Special techniques let you “fake it”

Interactive Computer GraphicsChapter Projections and shadows Projections can be used to generate simple shadow polygons Light (x l, y l, z l ) Translate light to origin Project down y axis [M] Translate back

Interactive Computer GraphicsChapter Simple Shadow in OpenGL GLfloat m[16];//projection matrix for (int i=0; i<16; i++) m[i]=0; m[0]=m[5]=m[10]=1; m[7] = -1/yl; glBegin(); [draw polygon normally]; glEnd(); glMatrixMode(GL_MODELVIEW); glPushMatrix;//save state glTranslatef(xl, yl, zl); glMultMatrix(m); glTranslatef(-xl, -yl, -zl); glColor3fv(shadow_color); [draw polygon] glEnd(); glPopMatrix();

Interactive Computer GraphicsChapter Stereo Viewing In our stereo setup, we need two images (4x3 size ratio), side-by-side We want to render perspective views from viewpoints (say) 3 inches apart How to set up the views?* * “Simple, Low-Cost Stereographics: VR for Everyone,” J. Zelle & C. Figura, Proc. SIGCSE 2004 p. 348.

Interactive Computer GraphicsChapter Direct both eyes at the same point?

Interactive Computer GraphicsChapter Direct both eyes in parallel?

Interactive Computer GraphicsChapter Parallel views and asymmetric frustum

Interactive Computer GraphicsChapter Stereo viewing: // set up the projection transformation // focalLength is distance to screen (objects // closer will float in front of screen) top = eyeSeparation / 2.0 * (near / focalLength); glFrustum(-right+off, right+off, -top, top, near, far); // now set up the model-view transformation // right is a unit vector in right direction viewpoint = viewpoint – right * eyeOffset; center = center – right * eyeOffset; gluLookAt(viewpoint[X],viewpoint[Y],viewpoint[Z], center[X], center[Y], center[Z], up[x], up[y], up[z]);

Interactive Computer GraphicsChapter Drawing left and right views //create window int width=400; int height=300; glutInitWindowSize(2*width, height); // // draw left image glViewport (0, 0, width, height); // set up projection and modeling matrices // render image // draw right image glViewport (width, 0, width, height); // set up projection and modeling matrices // render image

Interactive Computer GraphicsChapter Walking through a scene How to animate viewer motion through a scene? [Demo]Demo Assume viewer’s height is fixed; looking direction is in y=6 plane Store viewer’s location (x,6,z) and orientation (θ). Update appropriately with user commands LookAt(x, y, z, x + cos(θ), y, z + sin(θ), 0, 1, 0);

Credits 1. (Pinhole camera): Wikipedia. 5. Synthetic camera parameters: Liz Marai, Pitt Demos Musical solar system Interactive Computer GraphicsChapter