Viewing and Projection

Similar documents
Viewing and Projection

3.1 Viewing and Projection

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

Viewing and Projection

Viewing and Projection

Fundamental Types of Viewing

Transformation Pipeline

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

Transformations. CSCI 420 Computer Graphics Lecture 4

Three-Dimensional Graphics III. Guoying Zhao 1 / 67

OpenGL Transformations

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

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

Computer Graphics. Chapter 10 Three-Dimensional Viewing

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

Prof. Feng Liu. Fall /19/2016

Overview. By end of the week:

Introduction to Computer Graphics 4. Viewing in 3D

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

Geometry: Outline. Projections. Orthographic Perspective

CSE328 Fundamentals of Computer Graphics

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

Fachhochschule Regensburg, Germany, February 15, 2017

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

Transformations. CSCI 420 Computer Graphics Lecture 5

Transformations. OpenGL Transformations. 4x4 Model-view Matrix (this lecture) OpenGL Transformation Matrices. 4x4 Projection Matrix (next lecture)

CSE528 Computer Graphics: Theory, Algorithms, and Applications

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

CSE 167: Introduction to Computer Graphics Lecture #5: Projection. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2017

CS 4204 Computer Graphics

Computer Viewing Computer Graphics I, Fall 2008

Lecture 4. Viewing, Projection and Viewport Transformations

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

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

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

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

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

Viewing COMPSCI 464. Image Credits: Encarta and

Transformations (Rotations with Quaternions) October 24, 2005

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

3D Viewing Episode 2

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

CSC 470 Computer Graphics

CSC 470 Computer Graphics. Three Dimensional Viewing

GRAFIKA KOMPUTER. ~ M. Ali Fauzi

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

CS 543: Computer Graphics. Projection

CSE 167: Introduction to Computer Graphics Lecture #3: Projection. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2013

GEOMETRIC TRANSFORMATIONS AND VIEWING

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

CSE 167: Introduction to Computer Graphics Lecture #3: Projection. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2016

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

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

Viewing with Computers (OpenGL)

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

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

Fall CSCI 420: Computer Graphics. 2.2 Transformations. Hao Li.

Introduction to Computer Vision

Three-Dimensional Viewing Hearn & Baker Chapter 7

3D Viewing Episode 2

CSE 167: Introduction to Computer Graphics Lecture #3: Coordinate Systems

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

Viewing Transformation

Projection: Mapping 3-D to 2-D. Orthographic Projection. The Canonical Camera Configuration. Perspective Projection

Transformations Computer Graphics I Lecture 4

Computer Graphics 7: Viewing in 3-D

Viewing. Reading: Angel Ch.5

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

To Do. Demo (Projection Tutorial) Motivation. What we ve seen so far. Outline. Foundations of Computer Graphics (Fall 2012) CS 184, Lecture 5: Viewing

Specifying Complex Scenes

CMSC427 Transformations II: Viewing. Credit: some slides from Dr. Zwicker

Models and The Viewing Pipeline. Jian Huang CS456

CS 428: Fall Introduction to. Viewing and projective transformations. Andrew Nealen, Rutgers, /23/2009 1

Transforms 3: Projection Christian Miller CS Fall 2011

Transforms 1 Christian Miller CS Fall 2011

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

CS 418: Interactive Computer Graphics. Projection

Lecture 6 Sections 4.3, 4.6, 4.7. Wed, Sep 9, 2009

Transformation Algebra

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

MAE : Lecture #12 - Projection and Perspective. Lecture Overview:

Computer Graphics Geometric Transformations

Transformations Computer Graphics I Lecture 4

Basic Graphics Programming

Geometric transformations in 3D and coordinate frames. Computer Graphics CSE 167 Lecture 3

COMP30019 Graphics and Interaction Three-dimensional transformation geometry and perspective

Chapter 5. Projections and Rendering

To Do. Motivation. Demo (Projection Tutorial) What we ve seen so far. Computer Graphics. Summary: The Whole Viewing Pipeline

Lecture 4 of 41. Lab 1a: OpenGL Basics

CS 591B Lecture 9: The OpenGL Rendering Pipeline

COMP3421. Introduction to 3D Graphics

Modeling Transform. Chapter 4 Geometric Transformations. Overview. Instancing. Specify transformation for objects 李同益

Affine Transformations in 3D

Precept 2 Aleksey Boyko February 18, 2011

Motivation. What we ve seen so far. Demo (Projection Tutorial) Outline. Projections. Foundations of Computer Graphics

Camera Model and Calibration

3D Polygon Rendering. Many applications use rendering of 3D polygons with direct illumination

CSE 167: Lecture #4: Vertex Transformation. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2012

Virtual Cameras & Their Matrices

Transcription:

CSCI 480 Computer Graphics Lecture 5 Viewing and Projection January 25, 2012 Jernej Barbic University of Southern California Shear Transformation Camera Positioning Simple Parallel Projections Simple Perspective Projections [Angel, Ch. 5] http://www-bcf.usc.edu/~jbarbic/cs480-s12/ 1

Reminder: Affine Transformations Given a point [x y z], form homogeneous coordinates [x y z 1]. The transformed point is [x y z ]. 2

Transformation Matrices in OpenGL Transformation matrices in OpenGL are vectors of 16 values (column-major matrices) In glloadmatrixf(glfloat *m); m = {m 1, m 2,..., m 16 } represents Some books transpose all matrices! 3

Shear Transformations x-shear scales x proportional to y Leaves y and z values fixed 4

Specification via Shear Angle cot(θ) = (x -x) / y x = x + y cot(θ) y = y z = z y (x,y) x -x θ (x,y ) y θ = shear angle θ x 5

Specification via Ratios For example, shear in both x and z direction Leave y fixed Slope α for x-shear, γ for z-shear Solve Yields 6

Composing Transformations Let p = A q, and q = B s. Then p = (A B) s. s q p B A AB matrix multiplication 7

Composing Transformations Fact: Every affine transformation is a composition of rotations, scalings, and translations So, how do we compose these to form an x-shear? Exercise! 8

Outline Shear Transformation Camera Positioning Simple Parallel Projections Simple Perspective Projections 9

Transform Camera = Transform Scene Camera position is identified with a frame Either move and rotate the objects Or move and rotate the camera Initially, camera at origin, pointing in negative z-direction 10

The Look-At Function Convenient way to position camera glulookat(ex, ey, ez, fx, fy, fz, ux, uy, uz); e = eye point f = focus point u = up vector u e f u e f view plane 11

OpenGL code void display() { glclear (GL_COLOR_BUFFER_BIT GL_DEPTH_BUFFER_BIT); glmatrixmode (GL_MODELVIEW); glloadidentity(); glulookat (e x, e y, e z, f x, f y, f z, u x, u y, u z ); gltranslatef(x, y, z);... renderbunny(); glutswapbuffers(); } 12

Implementing the Look-At Function Plan: 1. Transform world frame to camera frame Compose a rotation R with translation T W = T R 2. Invert W to obtain viewing transformation V V = W -1 = (T R) -1 = R -1 T -1 Derive R, then T, then R -1 T -1 13

World Frame to Camera Frame I Camera points in negative z direction n = (f e) / f e is unit normal to view plane Therefore, R maps [0 0-1] T to [n x n y n z ] T u n e f view plane 14

World Frame to Camera Frame II R maps [0,1,0] T to projection of u onto view plane This projection v equals: α = (u n) / n = u n v 0 = u α n v = v 0 / v 0 u V 0 e α n f view plane 15

World Frame to Camera Frame III Set w to be orthogonal to n and v w = n x v (w, v, -n) is right-handed v n w e f view plane 16

Summary of Rotation glulookat(e x, e y, e z, f x, f y, f z, u x, u y, u z ); n = (f e) / f e v = (u (u n) n) / u (u n) n w = n x v Rotation must map: (1,0,0) to w (0,1,0) to v (0,0,-1) to n 17

World Frame to Camera Frame IV Translation of origin to e = [e x e y e z 1] T 18

Camera Frame to Rendering Frame V = W -1 = (T R) -1 = R -1 T -1 R is rotation, so R -1 = R T T is translation, so T -1 negates displacement 19

Putting it Together Calculate V = R -1 T -1 This is different from book [Angel, Ch. 5.3.2] There, u, v, n are right-handed (here: u, v, -n) 20

Other Viewing Functions Roll (about z), pitch (about x), yaw (about y) Assignment 2 poses a related problem 21

Outline Shear Transformation Camera Positioning Simple Parallel Projections Simple Perspective Projections 22

Projection Matrices Recall geometric pipeline Projection takes 3D to 2D Projections are not invertible Projections also described by 4x4 matrix Homogenous coordinates crucial Parallel and perspective projections 23

Parallel Projection Project 3D object to 2D via parallel lines The lines are not necessarily orthogonal to projection plane source: Wikipedia 24

Parallel Projection Problem: objects far away do not appear smaller Can lead to impossible objects : Penrose stairs source: Wikipedia 25

Orthographic Projection A special kind of parallel projection: projectors perpendicular to projection plane Simple, but not realistic Used in blueprints (multiview projections) 26

Orthographic Projection Matrix Project onto z = 0 x p = x, y p = y, z p = 0 In homogenous coordinates 27

Perspective Perspective characterized by foreshortening More distant objects appear smaller Parallel lines appear to converge Rudimentary perspective in cave drawings: Lascaux, France source: Wikipedia 28

Discovery of Perspective Foundation in geometry (Euclid) Mural from Pompeii, Italy 29

Middle Ages Art in the service of religion Perspective abandoned or forgotten Ottonian manuscript, ca. 1000 30

Renaissance Rediscovery, systematic study of perspective Filippo Brunelleschi Florence, 1415 31

Projection (Viewing) in OpenGL Remember: camera is pointing in the negative z direction 32

Orthographic Viewing in OpenGL glortho(xmin, xmax, ymin, ymax, near, far) z min = near, z max = far 33

Perspective Viewing in OpenGL Two interfaces: glfrustum and gluperspective glfrustum(xmin, xmax, ymin, ymax, near, far); z min = near, z max = far 34

Field of View Interface gluperspective(fovy, aspectratio, near, far); near and far as before aspectratio = w / h Fovy specifies field of view as height (y) angle 35

OpenGL code void reshape(int x, int y) { glviewport(0, 0, x, y); glmatrixmode(gl_projection); glloadidentity(); } gluperspective(60.0, 1.0 * x / y, 0.01, 10.0); 36

Perspective Viewing Mathematically d d = focal length y/z = y p /d so y p = y/(z/d) = y d / z Note that y p is non-linear in the depth z! 37

Exploiting the 4 th Dimension Perspective projection is not affine: has no solution for M Idea: exploit homogeneous coordinates for arbitrary w 0 38

Perspective Projection Matrix Use multiple of point Solve with 39

Projection Algorithm Input: 3D point (x,y,z) to project 1. Form [x y z 1] T 2. Multiply M with [x y z 1] T ; obtaining [X Y Z W] T 3. Perform perspective division: X / W, Y / W, Z / W Output: (X / W, Y / W, Z / W) (last coordinate will be d) 40

Perspective Division Normalize [x y z w] T to [(x/w) (y/w) (z/w) 1] T Perform perspective division after projection Projection in OpenGL is more complex (includes clipping) 41