Computer Viewing and Projection. Overview. Computer Viewing. David Carr Fundamentals of Computer Graphics Spring 2004 Based on Slides by E.

Similar documents
Computer Viewing. CS 537 Interactive Computer Graphics Prof. David E. Breen Department of Computer Science

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

Three-Dimensional Graphics III. Guoying Zhao 1 / 67

Course no. DIS4566 National Chiao Tung Univ, Taiwan By: I-Chen Lin, Assistant Professor

Computer Viewing Computer Graphics I, Fall 2008

Fundamental Types of Viewing

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

Introduction to Computer Graphics with WebGL

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

Orthogonal Projection Matrices. Angel and Shreiner: Interactive Computer Graphics 7E Addison-Wesley 2015

Introduction to Computer Graphics 4. Viewing in 3D

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

CS452/552; EE465/505. Intro to Lighting

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

Viewing with Computers (OpenGL)

Virtual Cameras & Their Matrices

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

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

Announcement. Project 1 has been posted online and in dropbox. Due: 11:59:59 pm, Friday, October 14

Introduction to Computer Graphics with WebGL

5.8.3 Oblique Projections

CS354 Computer Graphics Viewing and Modeling

Chap 3 Viewing Pipeline Reading: Angel s Interactive Computer Graphics, Sixth ed. Sections 4.1~4.7

One or more objects A viewer with a projection surface Projectors that go from the object(s) to the projection surface

Classical and Computer Viewing. Adapted From: Ed Angel Professor of Emeritus of Computer Science University of New Mexico

Viewing. Reading: Angel Ch.5

Three-Dimensional Viewing Hearn & Baker Chapter 7

On the Midterm Exam. Monday, 10/17 in class. Closed book and closed notes. One-side and one page cheat sheet is allowed. A calculator is allowed

Lecture 4: Viewing. Topics:

Transformations. Overview. Standard Transformations. David Carr Fundamentals of Computer Graphics Spring 2004 Based on Slides by E.

COMP3421. Introduction to 3D Graphics

GEOMETRIC TRANSFORMATIONS AND VIEWING

Reminder: Affine Transformations. Viewing and Projection. Shear Transformations. Transformation Matrices in OpenGL. Specification via Ratios

COMP3421. Introduction to 3D Graphics

To Do. Outline. Translation. Homogeneous Coordinates. Foundations of Computer Graphics. Representation of Points (4-Vectors) Start doing HW 1

Overview. By end of the week:

CSE328 Fundamentals of Computer Graphics

3.1 Viewing and Projection

Chapter 8 Three-Dimensional Viewing Operations

Transformations. Standard Transformations. David Carr Virtual Environments, Fundamentals Spring 2005 Based on Slides by E. Angel

COMP3421. Introduction to 3D Graphics

Viewing and Modeling

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

Building Models. Angel and Shreiner: Interactive Computer Graphics 7E Addison-Wesley 2015

Transforms 3: Projection Christian Miller CS Fall 2011

COMS 4160: Problems on Transformations and OpenGL

CS 418: Interactive Computer Graphics. Projection

The Importance of Matrices in the DirectX API. by adding support in the programming language for frequently used calculations.

Introduction to Computer Graphics. Overview. What is Computer Graphics?

So we have been talking about 3D viewing, the transformations pertaining to 3D viewing. Today we will continue on it. (Refer Slide Time: 1:15)

Last week. Machiraju/Zhang/Möller/Fuhrmann

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

Geometry: Outline. Projections. Orthographic Perspective

CS 432 Interactive Computer Graphics

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

CSE528 Computer Graphics: Theory, Algorithms, and Applications

Viewing and Projection

Viewing and Projection

Viewing and Projection

Computer Graphics. Bing-Yu Chen National Taiwan University The University of Tokyo

Chapter 5. Projections and Rendering

Computer Graphics. Jeng-Sheng Yeh 葉正聖 Ming Chuan University (modified from Bing-Yu Chen s slides)

Models and The Viewing Pipeline. Jian Huang CS456

Visualisation Pipeline : The Virtual Camera

THE VIEWING TRANSFORMATION

15. Clipping. Projection Transformation. Projection Matrix. Perspective Division

Chapter 5-3D Camera & Optimizations, Rasterization

Chap 7, 2008 Spring Yeong Gil Shin

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

Graphics pipeline and transformations. Composition of transformations

Buffers, Textures, Compositing, and Blending. Overview. Buffers. David Carr Virtual Environments, Fundamentals Spring 2005 Based on Slides by E.

Three Main Themes of Computer Graphics

Institutionen för systemteknik

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

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

CS 4204 Computer Graphics

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

Computer Graphics. P05 Viewing in 3D. Part 1. Aleksandra Pizurica Ghent University

Basic Elements. Geometry is the study of the relationships among objects in an n-dimensional space

Lecture 4. Viewing, Projection and Viewport Transformations

Prof. Feng Liu. Fall /19/2016

CSE528 Computer Graphics: Theory, Algorithms, and Applications

Computer Graphics (CS 543) Lecture 6a: Viewing & Camera Control. Prof Emmanuel Agu. Computer Science Dept. Worcester Polytechnic Institute (WPI)

Chap 7, 2009 Spring Yeong Gil Shin

CS452/552; EE465/505. Review & Examples

Computer Graphics 7: Viewing in 3-D

QUESTION BANK 10CS65 : COMPUTER GRAPHICS AND VISUALIZATION

Computer Graphics. Coordinate Systems and Change of Frames. Based on slides by Dianna Xu, Bryn Mawr College

3D Viewing Episode 2

Lecture 4: 3D viewing and projections

MORE OPENGL. Pramook Khungurn CS 4621, Fall 2011

CSE452 Computer Graphics

Lecture 5: Transforms II. Computer Graphics and Imaging UC Berkeley CS184/284A

OpenGL Transformations

3-Dimensional Viewing

The Graphics Pipeline and OpenGL I: Transformations!

CS230 : Computer Graphics Lecture 6: Viewing Transformations. Tamar Shinar Computer Science & Engineering UC Riverside

CS 543: Computer Graphics. Projection

(Refer Slide Time: 00:04:20)

Fachhochschule Regensburg, Germany, February 15, 2017

Transcription:

INSTITUTIONEN FÖR SYSTEMTEKNIK LULEÅ TEKNISKA UNIVERSITET Computer Viewing and Projection David Carr Fundamentals of Computer Graphics Spring 24 Based on Slides by E. Angel Projection 1 L Overview Computer Viewing - Introduction to the mathematics of projection - OpenGL viewing functions - Alternate viewing APIs Projection Matrices - Derive the projection matrices used for standard OpenGL projections - Introduce oblique projections - Introduce projection normalization Projection 2 L INSTITUTIONEN FÖR SYSTEMTEKNIK LULEÅ TEKNISKA UNIVERSITET Computer Viewing Projection 3 L 1

Three Aspects of Computer Viewing Positioning the camera - Setting the model-view matrix Selecting a lens - Setting the projection matrix Clipping - Setting the view volume All are implemented in the pipeline Projection 4 L The OpenGL Camera In OpenGL: - Initially the world and camera frames are the same - Default model-view matrix is an identity The camera is: - Located at origin - Points in the negative z-direction OpenGL also specifies: - Default view volume + Cube with sides of length 2 + Centered at the origin - Default projection matrix is an identity Projection 5 L Default Projection Default projection is orthogonal 2 clipped out z= Projection 6 L 2

Moving the Camera Frame To visualize an object with both positive and negative z values: - Move the camera in the positive z direction + Translate the camera frame - Move the objects in the negative z direction + Translate the world frame Both of these views are: - Equivalent - Determined by the model-view matrix - Want a translation: + gl.gltranslatef(.,.,-d); with d > Projection 7 L Moving Camera back from Origin Default Frames Frames after Translation by d d > Projection 8 L Moving the Camera We can move the camera to any desired position by a sequence of : - Rotations and translations Example: side view - Rotate the camera - Move it away from origin - Model-view matrix C = TR Projection 9 L 3

OpenGL code Remember that last transformation specified is first to be applied gl.glmatrixmode(gl_modelview) gl.glloadidentity(); gl.gltranslatef(.,., -d); gl.glrotatef(9.,., 1.,.); Projection 1 L The LookAt Method The GLU object contains the function gllookat - Simple interface to form the model-view matrix - Specify camera location (eye) - Specify point in view to look at (at) - Specify a vector representing the upward direction (up) Still need to initialize - Can concatenate with modeling transformations Example: isometric view of cube aligned with axes gl.glmatrixmode(gl_modelview): gl.glloadidentity(); glu.glulookat(1.,1.,1.,.,.,.,.,1.,.); Projection 11 L LookAt glu.glulookat(eyex,eyey,eyez, atx,aty,atz, upx,upy,upz) Projection 12 L 4

Other Viewing APIs The LookAt function is only one possible API for positioning the camera Others include - View reference point, view plane normal, view up (PHIGS, GKS-3D) - Yaw, pitch, roll - Elevation, azimuth, twist - Direction angles Projection 13 L Projections and Normalization The default projection in the eye (camera) frame is orthogonal For points within the default view volume x p = x y p = y z p = Most graphics systems use view normalization - All other views are converted to the default view by transformations that determine the projection matrix - Allows use of the same pipeline for all views Projection 14 L Homogeneous Coordinate Representation xp = x yp = y zp = wp = 1 M = È1 Î p p = Mp 1 1 In practice, we can let M = I and set the z term to zero later Projection 15 L 5

Simple Perspective Center of projection at the origin Projection plane z = d, d < Projection 16 L Consider top and side views Perspective Equations x z / d x p = x z / d y p = y z / d z p = d Projection 17 L consider q = Mp where È1 M = Î Homogeneous Coordinate Form Èx y z Î1 q = fi p = È Î 1 x y z z / d 1/ d Projection 18 L 1 6

x p = x z / d Perspective Division However w 1, so we must divide by w to return from homogeneous coordinates This perspective division yields y p = y z / d z p = d The desired perspective equations We will consider the corresponding clipping volume with the OpenGL functions Projection 19 L OpenGL Orthogonal Viewing gl.glortho(xmin,xmax,ymin,ymax,near,far) gl.glortho(left,right,bottom,top,near,far) near and far measured from camera Projection 2 L OpenGL Perspective gl.glfrustum(xmin,xmax,ymin,ymax,near,far) Projection 21 L 7

Using Field of View With glfrustum it is often difficult to get the desired view glu.gluperpective(fovy, aspect, near, far) often provides a better interface front plane aspect = w/h Projection 22 L INSTITUTIONEN FÖR SYSTEMTEKNIK LULEÅ TEKNISKA UNIVERSITET Projection Matrices Projection 23 L Normalization Rather than derive a different projection matrix for each type of projection Convert all projections to orthogonal projections with the default view volume This strategy allows us to: - Use standard transformations in the pipeline - Make clipping efficient Projection 24 L 8

Pipeline View Model-View Transformation nonsingular Projection Transformation Perspective Division 4D Æ 3D Clipping Against Default Cube Projection 3D Æ 2D Projection 25 L Notes We stay in four-dimensional homogeneous coordinates - For both the model-view and projection transformations - Both these transformations are nonsingular - Default to identity matrices (orthogonal view) Normalization lets us clip against simple cube regardless of type of projection Delay final projection until end - Important for hidden-surface removal to retain depth information as long as possible Projection 26 L Orthogonal Normalization glortho(left,right,bottom,top,near,far) normalization fi find transformation to convert specified clipping volume to default Projection 27 L 9

Orthogonal Matrix Two steps - Move center to origin + T(-(left+right)/2, -(bottom+top)/2,(near+far)/2)) - Scale to have sides of length 2 + S(2/(left-right),2/(top-bottom),2/(near-far)) P = ST = È 2 right - left - right - left right - left 2 top + bottom - top - bottom top - bottom 2 far + near near - far far - near Î 1 Projection 28 L Final Projection Set z = Equivalent to the homogeneous coordinate transformation È1 1 M orth = Î 1 Hence, general orthogonal projection in 4D is P = M orth ST Projection 29 L Oblique Projections The OpenGL projection functions cannot produce general parallel projections such as However: - If we look at a cube it appears that the cube has been sheared Oblique Projection = Shear + Orthogonal Projection Projection 3 L 1

General Shear top view side view Projection 31 L Shear Matrix x-y shear (z values unchanged) È 1 -cotq H(q,f) = 1 -cot f 1 Î 1 Projection matrix General case: P = M orth H(q,f) P = M orth STH(q,f) Projection 32 L Equivalency Projection 33 L 11

Effect on Clipping The projection matrix P = STH transforms the original clipping volume to the default clipping volume object top view z = 1 DOP clipping volume DOP x = -1 x = 1 far plane z = -1 near plane distorted object (projects correctly) Projection 34 L Simple Perspective Consider a simple perspective with the COP at the origin, the near clipping plane at z = -1, and a 9 degree field of view determined by the planes x = ±z, y = ±z Projection 35 L Perspective Matrices Simple projection matrix in homogeneous coordinates M = È1 Î 1 1-1 Note that this matrix is independent of the far clipping plane Projection 36 L 12

Generalization N = È 1 1 a b Î -1 after persepective divison, the point (x, y, z, 1) goes to x = x/z y = y/z z = -(a+b/z) which projects orthogonally to the desired point regardless of a and b Projection 37 L Picking a and b If we pick near + far a = far - near 2near * far b = near - far the near plane is mapped to z = -1 the far plane is mapped to z =1 and the sides are mapped to x = ± 1, y = ± 1 Hence the new clipping volume is the default clipping volume Projection 38 L Normalization Transformation distorted object projects correctly original clipping volume original object new clipping volume Projection 39 L 13

Normalization and Hidden-Surface Removal Although our selection of the form of the perspective matrices may appear somewhat arbitrary, - Chosen so that if z 1 > z 2 in the original clipping volume - Then the for the transformed points z 1 > z 2 Thus, hidden surface removal works if the normalization transformation is applied first However, the formula z = -(a+b/z) implies that - Distances are distorted by the normalization - Can cause numerical problems especially if the near distance is small Projection 4 L OpenGL Perspective gl.glfrustum allows for an non-symmetric viewing frustum (although glu.gluperspective does not) Projection 41 L OpenGL Perspective Matrix The normalization in gl.glfrustum require: - Initial shear to form a right viewing pyramid, followed by - Scaling to get the normalized perspective volume. - The perspective matrix results in needing only a final orthogonal transformation P = NSH our previously defined perspective matrix shear and scale Projection 42 L 14

Why do we do it this way? Allows for a single pipeline for both - Perspective viewing - Orthogonal viewing Keep in 4-dimensional homogeneous coordinates - As long as possible - Retain 3-dimensional information needed for hidden-surface removal and shading Simplify clipping Projection 43 L Questions? Projection 44 L 15