3D Viewing Episode 2

Similar documents
3D Viewing Episode 2

Graphics pipeline and transformations. Composition of transformations

GEOMETRIC TRANSFORMATIONS AND VIEWING

CS 432 Interactive Computer Graphics

COMP3421. Vector geometry, Clipping

COMP30019 Graphics and Interaction Three-dimensional transformation geometry and perspective

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

Fachhochschule Regensburg, Germany, February 15, 2017

Affine Transformations in 3D

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

Transformation Pipeline

Transforms. COMP 575/770 Spring 2013

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

Lecture 4. Viewing, Projection and Viewport Transformations

3.1 Viewing and Projection

CSE528 Computer Graphics: Theory, Algorithms, and Applications

Viewing with Computers (OpenGL)

Overview. By end of the week:

Viewing and Projection

CSE328 Fundamentals of Computer Graphics

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

COMP3421. Introduction to 3D Graphics

Transforms 1 Christian Miller CS Fall 2011

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

CS354 Computer Graphics Viewing and Modeling

CS 4204 Computer Graphics

Math background. 2D Geometric Transformations. Implicit representations. Explicit representations. Read: CS 4620 Lecture 6

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

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

Mathematics 308 Geometry. Chapter 9. Drawing three dimensional objects

CGT520 Transformations

Answers. Chapter 2. 1) Give the coordinates of the following points:

COMP3421. Introduction to 3D Graphics

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

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

CS251 Spring 2014 Lecture 7

COMS 4160: Problems on Transformations and OpenGL

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

Perspective transformations

Mouse Ray Picking Explained

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

COMP3421. Introduction to 3D Graphics

Perspective Mappings. Contents

Computer Viewing Computer Graphics I, Fall 2008

Computer Graphics with OpenGL ES (J. Han) Chapter IV Spaces and Transforms

Geometric Transformations

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

C O M P U T E R G R A P H I C S. Computer Graphics. Three-Dimensional Graphics I. Guoying Zhao 1 / 52

For each question, indicate whether the statement is true or false by circling T or F, respectively.

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

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

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

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

OpenGL Transformations

Camera Placement for Ray Tracing

3D Viewing. CS 4620 Lecture 8

COMP 175 COMPUTER GRAPHICS. Ray Casting. COMP 175: Computer Graphics April 26, Erik Anderson 09 Ray Casting

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

Introduction to Computer Graphics with WebGL

CT5510: Computer Graphics. Transformation BOCHANG MOON

Object Representation Affine Transforms. Polygonal Representation. Polygonal Representation. Polygonal Representation of Objects

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

CS559 Computer Graphics Fall 2015

EECS : Introduction to Computer Graphics Building the Virtual Camera ver. 1.4

Computer Graphics. Chapter 7 2D Geometric Transformations

Linear and Affine Transformations Coordinate Systems

CS 130 Final. Fall 2015

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

INTRODUCTION TO COMPUTER GRAPHICS. It looks like a matrix Sort of. Viewing III. Projection in Practice. Bin Sheng 10/11/ / 52

Viewing and Projection

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. Lecture 04 3D Projection and Visualization. Edirlei Soares de Lima.

Game Engineering: 2D

ALGEBRA 2 W/ TRIGONOMETRY MIDTERM REVIEW

Viewing Transformation

Select, Move, Rotate and Scale

Visualisation Pipeline : The Virtual Camera

BASIC ELEMENTS. Geometry is the study of the relationships among objects in an n-dimensional space

SUMMARY. CS380: Introduction to Computer Graphics Varying Variables Chapter 13. Min H. Kim KAIST School of Computing 18/04/26.

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

Matrix Transformations The position of the corners of this triangle are described by the vectors: 0 1 ] 0 1 ] Transformation:

CSC 470 Computer Graphics. Three Dimensional Viewing

CSC 470 Computer Graphics

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

Matrices. Chapter Matrix A Mathematical Definition Matrix Dimensions and Notation

AH Matrices.notebook November 28, 2016

Computer Graphics. Chapter 10 Three-Dimensional Viewing

Computing the 3D Viewing Transformation

3D Geometry and Camera Calibration

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

Ray Tracer I: Ray Casting Due date: 12:00pm December 3, 2001

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

Projection Matrix Tricks. Eric Lengyel

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)

Introduction to Computer Graphics with WebGL

THE VIEWING TRANSFORMATION

CIS 636 Interactive Computer Graphics CIS 736 Computer Graphics Spring 2011

The Graphics Pipeline and OpenGL I: Transformations!

CSC 470 Computer Graphics

Computer graphics 2: Graduate seminar in computational aesthetics

Transcription:

3D Viewing Episode 2 1 Positioning and Orienting the Camera Recall that our projection calculations, whether orthographic or frustum/perspective, were made with the camera at (0, 0, 0) looking down the z-axis. The camera is also vertically oriented i.e., up is the vector 0, 1, 0. But we want the camera to be anywhere, looking anywhere; how is this done? Recall that transforming an object is equivalent to transforming its axes in the opposite manner: e.g., moving an object centered on the origin to the right by 10 units is visually identical to moving the origin (and its axes) to the left by 10 units. Suppose that we would like to position our camera at some point P the center of projection (COP). The camera is looking toward Q the look-at or eye point and is oriented according to the up vector, which indicates what is vertical relative to the camera. Figure 1 illustrates this setup. 2 Deriving the Transformation The idea here is to derive the transformation such that 1, 0, 0 x e, 0, 1, 0 y e, and 0, 0, 1 z e. x e, y e, and z e are vectors, so they can be broken down in terms of their components as x ex, x ey, x ez, y ex, y ey, y ez, and z ex, z ey, z ez. Thus, the matrix that transforms the standard cartesian axes into axes relative to the camera is: x ey y ey z ey 0 x ez y ez z ez 0 (1) 1

y e < 0, 1, 0 > up Q P x e proj (up, z e ) z e < 1, 0, 0 > < 0, 0, 1 > Figure 1: Setting up the camera in terms of a center of projection P looking toward the point Q with some up vector. 2

So what are x e, y e, and z e anyway? Easier than it seems they can actually be derived from our look-at arguments: z e = U P Q (2) y e = U up proj( up, ze) (3) x e = y e z e (4) Note how, since z e and y e have been normalized into unit vectors, then x e is automatically a unit vector. The matrix in (1) only rotates the coordinate system it is still centered on the origin. Thus, we need to translate the axes to P (note how matrix composition reads from right to left): 1 0 0 P x 0 1 0 P y 0 0 1 P z x ey y ey z ey 0 x ez y ez z ez 0 (5) Remember that (5) is the transformation that converts the axes to match the desired axes for the camera. However, we want the transform that converts the objects in 3D space according to the camera. Thus, what we really want is the inverse of (5) e.g., an object that is at the origin would have coordinates ( P x, P y, P z ) from the perspective of a camera that is located at world coordinates (P x, P y, P z ). Instead of multiplying out the matrices and then inverting after, we use the matrix multiplication identity (AB) 1 = B 1 A 1. So what are the inverses of these matrices? The inverse of the translation matrix is straightforward: we translate by ( P x, P y, P z ) instead of (P x, P y, P z ): 1 0 0 P x 0 1 0 P y 0 0 1 P z (6) The axis orientation matrix is also easy to state, but a little trickier to explain; it is the matrix s transpose (A T ): (7) Now, to see why this is the case, think about the characteristics of x e, y e, and z e. If you look at the product of the axis orientation matrix and its transpose, we get: 3

x ey y ey z ey 0 x ez y ez z ez 0 = x e x e x e y e x e z e 0 y e x e y e y e y e z e 0 z e x e z e y e z e z e 0 (8) x e, y e, and z e are all unit vectors see (4), (3), and (2) and so x e x e, y e y e, and z e z e are all equal to one. Further, x e, y e, and z e are mutually perpendicular to each other and thus the dot product of any two of these vectors is equal to zero. If you substitute those values into the product, note that you get the identity matrix and thus, A 1 = A T for the axis orientation matrix! To wrap it all up, we now have our final lookat matrix: 1 0 0 P x 0 1 0 P y 0 0 1 P z (9) All that s left is to multiply the matrices, yielding: x ex x ey x ez (P x e ) y ex y ey y ez (P y e ) z ex z ey z ez (P z e ) (10) This is what glulookat() multiplies to the current matrix, of course substituting the x e, y e, and z e with their derivations in (4), (3), and (2), respectively. And yes, this transform is affine! 3 Putting Them Together Notice that positioning the camera does not actually position a camera, but the entire world! The traditional arguments to the camera or lookat function are the flattened versions of the center of projection P, the eye point Q, and the up vector up, or: lookat(px, py, pz, qx, qy, qz, ux, uy, uz) If you put everything together, every vertex in OpenGL thus goes through these matrices on its journey from the 3D world to the screen or window: [ viewport matrix ] [ projection matrix ] [ modelview matrix ] (11) 4

Of these, the viewport matrix is transparent to the vertex shader, and in there you are really only dealing with: [ projection matrix ] [ modelview matrix ] (12) Because the camera matrix happens to be yet another matrix that transforms the 3D world, it can be lumped in with the modelview matrix. However, the camera typically affects the entire world, so it also makes sense to manage it separately. This becomes the view part of the modelview matrix: [ projection matrix ] [ view/camera matrix ] [ model matrix ] (13) The final choice is yours what matters is that you know how these computations interact, and how to combine them in your specific application for both correctness and efficiency. Note how we keep these three matrices distinct instead of multiplying them together. One reason is to maintain the ability to manipulate them separately for example, if the window size changes, only the viewport and projection matrices will change, but not the modelview matrix (or at least it shouldn t). 5