Transformations. CSCI 420 Computer Graphics Lecture 4

Similar documents
Transformations. CSCI 420 Computer Graphics Lecture 5

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

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

Transformations Computer Graphics I Lecture 4

Transformations Computer Graphics I Lecture 4

Lecture 4: Transformations and Matrices. CSE Computer Graphics (Fall 2010)

CS 4204 Computer Graphics

Computer Graphics. Chapter 7 2D Geometric Transformations

Viewing and Projection

EECE 478. Learning Objectives. Learning Objectives. Linear Algebra and 3D Geometry. Linear algebra in 3D. Coordinate systems

Viewing and Projection

Computer Graphics Geometric Transformations

CS D Transformation. Junqiao Zhao 赵君峤

CSC 470 Computer Graphics

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

Lecture 5b. Transformation

3D Transformation. In 3D, we have x, y, and z. We will continue use column vectors:. Homogenous systems:. x y z. x y z. glvertex3f(x, y,z);

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

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

Computer Graphics. Chapter 5 Geometric Transformations. Somsak Walairacht, Computer Engineering, KMITL

Reading. Hierarchical Modeling. Symbols and instances. Required: Angel, sections , 9.8. Optional:

GL_MODELVIEW transformation

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

CS 428: Fall Introduction to. Transformations in OpenGL + hierarchical modeling. Andrew Nealen, Rutgers, /21/2009 1

Order of Transformations

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

CSCI E-74. Simulation and Gaming

Modeling Objects by Polygonal Approximations. Linear and Affine Transformations (Maps)

Last week. Machiraju/Zhang/Möller

Spring 2013, CS 112 Programming Assignment 2 Submission Due: April 26, 2013

CS452/552; EE465/505. Geometry Transformations

Chapter 3: Modeling Transformation

GEOMETRIC TRANSFORMATIONS AND VIEWING

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

Affine Transformations Computer Graphics Scott D. Anderson

C OMPUTER G RAPHICS Thursday

Quaternions and Rotations

Rendering Pipeline and Coordinates Transforms

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

Hierarchical Modeling. University of Texas at Austin CS384G - Computer Graphics Fall 2010 Don Fussell

Introduction to Computer Graphics with WebGL

Computer Graphics 7: Viewing in 3-D

Today s Agenda. Geometry

3.1 Viewing and Projection

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

Computer Graphics. Chapter 10 Three-Dimensional Viewing

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

CS Computer Graphics: Transformations & The Synthetic Camera

CIS 636 Interactive Computer Graphics CIS 736 Computer Graphics Spring 2011

CS 591B Lecture 9: The OpenGL Rendering Pipeline

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

Three Main Themes of Computer Graphics

Modeling with Transformations

Chapter 3 - Basic Mathematics for 3D Computer Graphics

DH2323 DGI16 Lab2 Transformations

CS380: Computer Graphics 2D Imaging and Transformation. Sung-Eui Yoon ( 윤성의 ) Course URL:

Computer Graphics (CS 4731) Lecture 11: Implementing Transformations. Prof Emmanuel Agu. Computer Science Dept. Worcester Polytechnic Institute (WPI)

CT5510: Computer Graphics. Transformation BOCHANG MOON

Computer Graphics. Bing-Yu Chen National Taiwan University

Objectives. transformation. General Transformations. Affine Transformations. Notation. Pipeline Implementation. Introduce standard transformations

Affine Transformation. Edith Law & Mike Terry

Viewing and Projection

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

Quaternions and Rotations

CS4202: Test. 1. Write the letter corresponding to the library name next to the statement or statements that describe library.

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

蔡侑庭 (Yu-Ting Tsai) National Chiao Tung University, Taiwan. Prof. Wen-Chieh Lin s CG Slides OpenGL 2.1 Specification

Review of Thursday. xa + yb xc + yd

Objectives. Geometry. Coordinate-Free Geometry. Basic Elements. Transformations to Change Coordinate Systems. Scalars

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

Transforms. COMP 575/770 Spring 2013

Transforms 1 Christian Miller CS Fall 2011

Luiz Fernando Martha André Pereira

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

Affine Transformations in 3D

Computer Graphics CS 543 Lecture 5 (Part 2) Implementing Transformations

9. [20 points] A degree three Bezier curve q(u) has the four control points p 0 = 0,0, p 1 = 2,0, p 2 = 0,2, and p 3 = 4,4.

Quaternions and Rotations

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

2D Image Transforms Computer Vision (Kris Kitani) Carnegie Mellon University

OpenGL Transformations

3D Viewing Episode 2

COMP30019 Graphics and Interaction Three-dimensional transformation geometry and perspective

Translation. 3D Transformations. Rotation about z axis. Scaling. CS 4620 Lecture 8. 3 Cornell CS4620 Fall 2009!Lecture 8

Computer Graphics I. Midterm Examination. October 23, This is a closed-book exam; only one double-sided sheet of notes is permitted.

Transformations. Mike Bailey. Oregon State University. Oregon State University. Computer Graphics. transformations.

CS452/552; EE465/505. Transformations

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

INF3320 Computer Graphics and Discrete Geometry

Today s class. Viewing transformation Menus Mandelbrot set and pixel drawing. Informationsteknologi

CSE Intro to Computer Graphics. ANSWER KEY: Midterm Examination. November 18, Instructor: Sam Buss, UC San Diego

Shadows in Computer Graphics

S U N G - E U I YO O N, K A I S T R E N D E R I N G F R E E LY A VA I L A B L E O N T H E I N T E R N E T

Computer Graphics Hands-on

Fundamental Types of Viewing

Scene Graphs. CS4620/5620: Lecture 7. Announcements. HW 1 out. PA 1 will be out on Wed

Transformations: 2D Transforms

Fachhochschule Regensburg, Germany, February 15, 2017

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

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

Transcription:

CSCI 420 Computer Graphics Lecture 4 Transformations Jernej Barbic University of Southern California Vector Spaces Euclidean Spaces Frames Homogeneous Coordinates Transformation Matrices [Angel, Ch. 4] 1

OpenGL Transformations 2

OpenGL Transformation Matrices Model-view matrix (4x4 matrix) Projection matrix (4x4 matrix) vertices in 3D Model-view vertices in canonical 3D world coordinate system Projection vertices in 2D 3

4x4 Model-view Matrix (this lecture) Translate, rotate, scale objects Position the camera vertices in 3D Model-view vertices in canonical 3D world coordinate system Projection vertices in 2D 4

4x4 Projection Matrix (next lecture) Project from 3D to 2D vertices in 3D Model-view vertices in canonical 3D world coordinate system Projection vertices in 2D 5

OpenGL Transformation Matrices Model-view Projection Manipulated separately in OpenGL (must set matrix mode) : glmatrixmode (GL_MODELVIEW); glmatrixmode (GL_PROJECTION); 6

Setting the Current Model-view Matrix Load or post-multiply glmatrixmode (GL_MODELVIEW); glloadidentity(); // very common usage float m[16] = { }; glloadmatrixf(m); // rare, advanced glmultmatrixf(m); // rare, advanced Use library functions gltranslatef(dx, dy, dz); glrotatef(angle, vx, vy, vz); glscalef(sx, sy, sz); 7

Translated, rotated, scaled object world 8

The rendering coordinate system Initially (after glloadidentity()) : rendering coordinate system = world coordinate system world 9

The rendering coordinate system gltranslatef(x, y, z); [x, y,z] world rendering coordinate system 10

The rendering coordinate system glrotatef(angle, ax, ay, az); world 11

The rendering coordinate system glscalef(sx, sy, sz); world 12

OpenGL code glmatrixmode (GL_MODELVIEW); glloadidentity(); gltranslatef(x, y, z); glrotatef(angle, ax, ay, az); glscalef(sx, sy, sz); renderbunny(); world 13

Rendering more objects How to obtain this frame? world 14

How to obtain this frame? Solution 1: Find gltranslate( ), glrotatef( ), glscalef( ) world 15

Solution 2: gl{push,pop}matrix glmatrixmode (GL_MODELVIEW); glloadidentity(); // render first bunny glpushmatrix(); // store current matrix gltranslate3f( ); glrotatef( ); renderbunny(); glpopmatrix(); // pop matrix // render second bunny glpushmatrix(); // store current matrix gltranslate3f( ); glrotatef( ); renderbunny(); glpopmatrix(); // pop matrix world 16

3D Math Review 17

Scalars Scalars α, β, γ from a scalar field Operations α+β, α β, 0, 1, -α, ( ) -1 Expected laws apply Examples: rationals or reals with addition and multiplication 18

Vectors Vectors u, v, w from a vector space Vector addition u + v, subtraction u - v Zero vector 0 Scalar multiplication α v 19

Euclidean Space Vector space over real numbers Three-dimensional in computer graphics Dot product: α = u v = u 1 v 1 + u 2 v 2 + u 3 v 3 0 0 =0 u, v are orthogonal if u v = 0 v 2 = v v defines v, the length of v 20

Lines and Line Segments Parametric form of line: P(α) = P0 + α d Line segment between Q and R: P(α) = (1-α) Q + α R for 0 α 1 21

Convex Hull Convex hull defined by P = α 1 P 1 + + α n P n for α 1 + + α n = 1 and 0 α i 1, i = 1,..., n 22

Projection Dot product projects one vector onto another vector u v = u 1 v 1 + u 2 v 2 + u 3 v 3 = u v cos(θ) pr v u = (u v) v / v 2 23

Cross Product a x b = a b sin(θ) Cross product is perpendicular to both a and b Right-hand rule 24 Source: Wikipedia

Plane Plane defined by point P0 and vectors u and v u and v should not be parallel Parametric form: T(α, β) = P0 + α u + β v (α and β are scalars) n = u x v / u x v is the normal n (P P0) = 0 if and only if P lies in plane 25

Coordinate Systems Let v 1, v 2, v 3 be three linearly independent vectors in a 3-dimensional vector space Can write any vector w as w = α 1 v 1 + α 2 v 2 + α 3 v 3 for some scalars α 1, α 2, α 3 26

Frames Frame = origin P0 + coordinate system Any point P = P0 + α 1 v 1 + α 2 v 2 + α 3 v 3 27

In Practice, Frames are Often Orthogonal 28

Change of Coordinate System Bases {u 1, u 2, u 3 } and {v 1, v 2, v 3 } Express basis vectors u i in terms of v j Represent in matrix form: 29

Representing 3D transformations (and model-view matrices) 30

Linear Transformations 3 x 3 matrices represent linear transformations a = Mb Can represent rotation, scaling, and reflection Cannot represent translation 31

In order to represent rotations, scales AND translations: Homogeneous Coordinates Augment [α 1 α 2 α 3 ] T by adding a fourth component (1): p = [α 1 α 2 α 3 1] T Homogeneous property: p = [α 1 α 2 α 3 1] T = [βα 1 βα 2 βα 3 β] T, for any scalar β 0 32

Homogeneous coordinates are transformed by 4x4 matrices p q q = A p world 4-vector 4x4 matrix 4-vector 33

Affine Transformations (4x4 matrices) Translation Rotation Scaling Any composition of the above Later: projective (perspective) transformations - Also expressible as 4 x 4 matrices! 34

Translation q = p + d where d = [α x α y α z 0] T p = [x y z 1] T q = [x y z 1] T Express in matrix form q = T p and solve for T 35

Scaling x = βx x y = βy y z = βz z Express as q = S p and solve for S 36

Rotation in 2 Dimensions Rotation by θ about the origin x = x cos θ y sin θ y = x sin θ + y cos θ Express in matrix form: Note that the determinant is 1 37

Rotation in 3 Dimensions Orthogonal matrices: RR T = R T R = I det(r) = 1 Affine transformation: 38

Affine Matrices are Composed by Matrix Multiplication A = A 1 A 2 A 3 Applied from right to left A p = (A 1 A 2 A 3 ) p = A 1 (A 2 (A 3 p)) When calling gltranslate3f, glrotatef, or glscalef, OpenGL forms the corresponding 4x4 matrix, and multiplies the current modelview matrix with it. 39

Summary OpenGL Transformation Matrices Vector Spaces Frames Homogeneous Coordinates Transformation Matrices 40