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

Similar documents
Viewing and Projection

Viewing and Projection

3.1 Viewing and Projection

Viewing and Projection

Viewing and Projection

Transformations. CSCI 420 Computer Graphics Lecture 5

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

Fundamental Types of Viewing

Viewing with Computers (OpenGL)

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

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

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

Overview. By end of the week:

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

Introduction to Computer Graphics 4. Viewing in 3D

CSE328 Fundamentals of Computer Graphics

Three-Dimensional Graphics III. Guoying Zhao 1 / 67

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

CSE528 Computer Graphics: Theory, Algorithms, and Applications

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

Viewing. Reading: Angel Ch.5

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

Computer Viewing Computer Graphics I, Fall 2008

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

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

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

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

OpenGL Transformations

Geometry: Outline. Projections. Orthographic Perspective

Transformation Pipeline

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

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

CS 4204 Computer Graphics

GEOMETRIC TRANSFORMATIONS AND VIEWING

Lecture 4. Viewing, Projection and Viewport Transformations

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 2013

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

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

Fachhochschule Regensburg, Germany, February 15, 2017

3D Viewing Episode 2

Three-Dimensional Viewing Hearn & Baker Chapter 7

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

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

Evening s Goals. Mathematical Transformations. Discuss the mathematical transformations that are utilized for computer graphics

CSC 470 Computer Graphics

CSC 470 Computer Graphics. Three Dimensional Viewing

Prof. Feng Liu. Fall /19/2016

Models and The Viewing Pipeline. Jian Huang CS456

Computer Graphics 7: Viewing in 3-D

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

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

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

Computer Graphics. Chapter 10 Three-Dimensional Viewing

3D Viewing Episode 2

Transforms 3: Projection Christian Miller CS Fall 2011

Viewing COMPSCI 464. Image Credits: Encarta and

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

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

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

Chapter 5. Projections and Rendering

Hierarchical Models. Roadmap. Importance of shadows. Importance of shadows. Importance of shadows. Importance of shadows

CS 543: Computer Graphics. Projection

Lecture 4: 3D viewing and projections

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

2/3/16. Interaction. Triangles (Clarification) Choice of Programming Language. Buffer Objects. The CPU-GPU bus. CSCI 420 Computer Graphics Lecture 3

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

Transformations. CSCI 420 Computer Graphics Lecture 4

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

Interaction. CSCI 420 Computer Graphics Lecture 3

Specifying Complex Scenes

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

Graphics pipeline and transformations. Composition of transformations

GRAFIKA KOMPUTER. ~ M. Ali Fauzi

Computer Graphics: Viewing in 3-D. Course Website:

CS488. Implementation of projections. Luc RENAMBOT

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

3D Viewing and Projec5on. Taking Pictures with a Real Camera. Steps: Graphics does the same thing for rendering an image for 3D geometric objects

Clipping and Scan Conversion

CS 432 Interactive Computer Graphics

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

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

CS 418: Interactive Computer Graphics. Projection

Chap 7, 2008 Spring Yeong Gil Shin

Today. Today. Introduction. Matrices. Matrices. Computergrafik. Transformations & matrices Introduction Matrices

Introduction to Computer Graphics with WebGL

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

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

Introduction to Computer Vision

Cameras and Radiometry. Last lecture in a nutshell. Conversion Euclidean -> Homogenous -> Euclidean. Affine Camera Model. Simplified Camera Models

Projection and viewing. Computer Graphics CSE 167 Lecture 4

Chapter 5-3D Camera & Optimizations, Rasterization

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

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

Virtual Cameras & Their Matrices

Projection Lecture Series

Viewing Transformation

CGT520 Transformations

Virtual Cameras and The Transformation Pipeline

Computer Graphics. Ch 6. 3D Viewing

Transcription:

CSCI 420 Computer Graphics Lecture 6 Viewing and Projection Jernej Barbic University o Southern Caliornia Shear Transormation Camera Positioning Simple Parallel Projections Simple Perspective Projections [Angel, Ch. 4] Reminder: Aine Transormations Given a point [x y z], orm homogeneous coordinates [x y z 1]. The transormed point is [x y z ]. 1 2 Transormation Matrices in OpenGL Transormation matrices in OpenGL are vectors o 16 values (column-major matrices) Shear Transormations x-shear scales x proportional to y Leaves y and z values ixed m = {m 1, m 2,..., m 16 } represents Some books transpose all matrices! 3 4 Speciication via Shear Angle Speciication via Ratios cot(q) = (x -x) / y x = x + y cot(q) y = y z = z y (x,y) (x,y ) x -x q y q = shear angle For example, shear in both x and z direction Leave y ixed Slope a or x-shear, g or z-shear Solve Yields q x 5 6 1

Composing Transormations Let p = A q, and q = B s. Then p = (A B) s. s q p B A Composing Transormations Fact: Every aine transormation is a composition o rotations, scalings, and translations So, how do we compose these to orm an x-shear? Exercise! AB matrix multiplication 7 8 Outline Shear Transormation Camera Positioning Simple Parallel Projections Simple Perspective Projections Transorm Camera = Transorm Scene Camera position is identiied with a rame Either move and rotate the objects Or move and rotate the camera Initially, camera at origin, pointing in negative z-direction 9 10 The Look-At Function Convenient way to position camera OpenGLMatrix::LookAt(ex, ey, ez, x, y, z, ux, uy, uz); // core proile glulookat(ex, ey, ez, x, y, z, ux, uy, uz); // compatibility proile e = eye point = ocus point u = up vector e u e view plane u 11 OpenGL code void display() { glclear (GL_COLOR_BUFFER_BIT GL_DEPTH_BUFFER_BIT); openglmatrix->setmatrixmode(openglmatrix::modelview); openglmatrix->loadidentity(); openglmatrix->lookat(e x, e y, e z, x, y, z, u x, u y, u z ); openglmatrix->translate(x, y, z); // transorm the object... loat m[16]; // column-major openglmatrix->getmatrix(m); // ill m with the matrix entries gluniormmatrix4v(h_modelviewmatrix, 1, GL_FALSE, m); renderbunny(); glutswapbuers(); } 12 2

Implementing the Look-At Function Plan: 1. Transorm world rame to camera rame Compose a rotation R with translation T W = T R 2. Invert W to obtain viewing transormation V V = W -1 = (T R) -1 = R -1 T -1 Derive R, then T, then R -1 T -1 World Frame to Camera Frame I Camera points in negative z direction n = ( e) / e is unit normal to view plane Thereore, R maps [0 0-1] T to [n x n y n z ] T u n e view plane 13 14 World Frame to Camera Frame II R maps [0,1,0] T to projection o u onto view plane This projection v equals: a = (u n) / n = u n v 0 = u a n v = v 0 / v 0 u 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 0 e a n w v e n view plane view plane 15 16 Summary o Rotation glulookat(e x, e y, e z, x, y, z, u x, u y, u z ); n = ( e) / 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 World Frame to Camera Frame IV Translation o origin to e = [e x e y e z 1] T 17 18 3

World Frame to Camera Frame V = W -1 = (T R) -1 = R -1 T -1 R is rotation, so R -1 = R T Putting it Together Calculate V = R -1 T -1 T is translation, so T -1 negates displacement This is dierent rom book [Angel, Ch. 5.3.2] There, u, v, n are right-handed (here: u, v, -n) 19 20 Other Viewing Functions Roll (about z), pitch (about x), yaw (about y) Outline Shear Transormation Camera Positioning Simple Parallel Projections Simple Perspective Projections Assignment 2 poses a related problem 21 22 Projection Matrices Recall geometric pipeline Projection takes 3D to 2D Projections are not invertible Projections are described by a 4x4 matrix Homogenous coordinates crucial Parallel and perspective projections Parallel Projection Project 3D object to 2D via parallel lines The lines are not necessarily orthogonal to projection plane 23 source: Wikipedia 24 4

Parallel Projection Orthographic Projection Problem: objects ar away do not appear smaller Can lead to impossible objects : A special kind o parallel projection: projectors perpendicular to projection plane Simple, but not realistic Used in blueprints (multiview projections) Penrose stairs source: Wikipedia 25 26 Orthographic Projection Matrix Perspective Project onto z = 0 xp = x, yp = y, zp = 0 In homogenous coordinates Perspective characterized by oreshortening More distant objects appear smaller Parallel lines appear to converge Rudimentary perspective in cave drawings: Lascaux, France source: Wikipedia 27 28 Discovery o Perspective Middle Ages Foundation in geometry (Euclid) Art in the service o religion Perspective abandoned or orgotten Mural rom Pompeii, Italy Ottonian manuscript, ca. 1000 29 30 5

Renaissance Rediscovery, systematic study o perspective Filippo Brunelleschi Florence, 1415 Projection (Viewing) in OpenGL Remember: camera is pointing in the negative z direction 31 32 Orthographic Viewing in OpenGL (compatibility proile) glortho(xmin, xmax, ymin, ymax, near, ar) Orthographic Viewing in OpenGL (core proile) OpenGLMatrix::Ortho(xmin, xmax, ymin, ymax, near, ar) z min = near, z max = ar z min = near, z max = ar 33 34 Perspective Viewing in OpenGL Two interaces: glfrustum and gluperspective {OpenGLMatrix::, gl}frustum( xmin, xmax, ymin, ymax, near, ar); Field o View Interace {OpenGLMatrix::, glu}perspective( ovy, aspectratio, near, ar); near and ar as beore aspectratio = w / h Fovy speciies ield o view as height (y) angle z min = near, z max = ar 35 36 6

OpenGL code OpenGL code void reshape(int x, int y) { glviewport(0, 0, x, y); openglmatrix->matrixmode(openglmatrix::projection); openglmatrix->loadidentity(); openglmatrix->perspective(60.0, 1.0 * x / y, 0.01, 10.0); openglmatrix->matrixmode(openglmatrix::modelview); } 37 void displayfunc() { openglmatrix->setmatrixmode(openglmatrix::projection); loat p[16]; // column-major openglmatrix->getmatrix(p); const GLboolean isrowmajor = alse; gluniormmatrix4v(h_projectionmatrix, 1, isrowmajor, p); renderbunny(); glutswapbuers(); } 38 Perspective Viewing Mathematically Exploiting the 4 th Dimension Perspective projection is not aine: d has no solution or M d = ocal 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! Idea: exploit homogeneous coordinates or arbitrary w ¹ 0 39 40 Perspective Projection Matrix Use multiple o point 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 Solve with 3. Perorm perspective division: X / W, Y / W, Z / W Output: (X / W, Y / W, Z / W) (last coordinate will be d) 41 42 7

Perspective Division Normalize [x y z w] T to [(x/w) (y/w) (z/w) 1] T Perorm perspective division ater projection Projection in OpenGL is more complex (includes clipping) 43 8