CS 4204 Computer Graphics

Similar documents
Introduction to Computer Graphics with WebGL

CSC 470 Computer Graphics

Order of Transformations

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

CS D Transformation. Junqiao Zhao 赵君峤

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

Transformations. CSCI 420 Computer Graphics Lecture 4

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

Computer Graphics Geometric Transformations

CS452/552; EE465/505. Transformations

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

Computer Graphics. Chapter 7 2D Geometric Transformations

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

Transformations Computer Graphics I Lecture 4

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

Transformations Computer Graphics I Lecture 4

Transformations. CSCI 420 Computer Graphics Lecture 5

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

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

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);

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

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

Introduction to Computer Graphics with WebGL

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

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

Lecture 5b. Transformation

C OMPUTER G RAPHICS Thursday

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

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

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

GL_MODELVIEW transformation

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

Computer Graphics. Bing-Yu Chen National Taiwan University

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

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

CSCI E-74. Simulation and Gaming

Affine Transformations Computer Graphics Scott D. Anderson

GEOMETRIC TRANSFORMATIONS AND VIEWING

CS 591B Lecture 9: The OpenGL Rendering Pipeline

Affine Transformations in 3D

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

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

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

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

Chapter 3: Modeling Transformation

Hierarchical Modeling: Tree of Transformations, Display Lists and Functions, Matrix and Attribute Stacks,

Transforms 1 Christian Miller CS Fall 2011

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

Computer Graphics 7: Viewing in 3-D

Questions HW1 Transform Q/A. Transform. Shaoting Zhang. May 11, 2008

Transformations II. Arbitrary 3D Rotation. What is its inverse? What is its transpose? Can we constructively elucidate this relationship?

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

CS Computer Graphics: Transformations & The Synthetic Camera

Modeling Objects. Modeling. Symbol-Instance Table. Instance Transformation. Each appearance of the object in the model is an instance

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

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

Coordinate transformations. 5554: Packet 8 1

Modeling with Transformations

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

CS 4204 Computer Graphics

Fachhochschule Regensburg, Germany, February 15, 2017

COMP3421. Week 2 - Transformations in 2D and Vector Geometry Revision

Hello, welcome to the video lecture series on Digital Image Processing. So in today's lecture

Luiz Fernando Martha André Pereira

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

Rendering Pipeline and Coordinates Transforms

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

Graphics and Visualization

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

UNIT 2 2D TRANSFORMATIONS

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

COMP3421. Week 2 - Transformations in 2D and Vector Geometry Revision

2D TRANSFORMATIONS AND MATRICES

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

Two possible ways to specify transformations. Each part of the object is transformed independently relative to the origin

Graphics and Interaction Transformation geometry and homogeneous coordinates

COMP30019 Graphics and Interaction Transformation geometry and homogeneous coordinates

Affine Transformation. Edith Law & Mike Terry

Computer Graphics. Chapter 10 Three-Dimensional Viewing

Representing 2D Transformations as Matrices

OpenGL: Open Graphics Library. Introduction to OpenGL Part II. How do I render a geometric primitive? What is OpenGL

Hierarchical Modeling

COMP 175 COMPUTER GRAPHICS. Lecture 07: Scene Graph. COMP 175: Computer Graphics March 10, Remco Chang 07 Scene Graph

Chapter 3 - Basic Mathematics for 3D Computer Graphics

Using GLU/GLUT Objects

OpenGL. Toolkits.

GRAFIKA KOMPUTER. ~ M. Ali Fauzi

Introduction to OpenGL

Prof. Feng Liu. Fall /19/2016

2D and 3D Transformations AUI Course Denbigh Starkey

Introduction to OpenGL Transformations, Viewing and Lighting. Ali Bigdelou

Vertex Buffer Objects and Transformations Week 4

Lecture 5 2D Transformation

3.2 Hierarchical Modeling

Computer graphics MN1

UNIT 2. Translation/ Scaling/ Rotation. Unit-02/Lecture-01

Fundamental Types of Viewing

(x, y) (ρ, θ) ρ θ. Polar Coordinates. Cartesian Coordinates

Exercise Max. Points Total 90

GLOBAL EDITION. Interactive Computer Graphics. A Top-Down Approach with WebGL SEVENTH EDITION. Edward Angel Dave Shreiner

Transcription:

CS 424 Computer Graphics 2D Transformations Yong Cao Virginia Tech References: Introduction to Computer Graphics course notes by Doug Bowman Interactive Computer Graphics, Fourth Edition, Ed Angle

Transformations What are they? changing something to something else via rules mathematics: mapping between values in a range set and domain set (function/relation) geometric: translate, rotate, scale, shear, Why are they important to graphics? moving objects on screen / in space mapping from model space to world space to camera space to screen space specifying parent/child relationships

Translation Moving an object is called a translation. We translate a point by adding to the x and y coordinates, respectively, the amount the point should be shifted in the x and y directions. We translate an object by translating each vertex in the object. t y t x x new = x old + t x ; y new = y old + t y

Scaling Changing the size of an object is called a scale. We scale an object o by scaling the x and y coordinates of each vertex in the object. h old h new w old w new s x =w new /w old x new = s x x old s y =h new /h old y new = s y y old

Rotation about the origin Consider rotation about the origin by q degrees radius stays the same, angle increases by q x = r cos (φ + θ) y = r sin (φ + θ) x =x cos θ y sin θ y = x sin θ + y cos θ x = r cos φ y = r sin φ

Transformations as matrices Scale: x new = s x x old y new = s y y old Rotation: x 2 = x cosθ - y sin θ y 2 = x sin θ + y cos θ cosθ sinθ s x x sx = s y y sy x y sinθ x x cosθ y sinθ = cosθ y xsinθ + y cosθ Translation: x new = x old + t x y new = y old + t y t t x y + x y = x y + t + t x y

Homogeneous Coordinates In order to represent a translation as a matrix multiplication In order to represent a translation as a matrix multiplication operation we use 3 x 3 matrices and pad our points to become 3 operation we use 3 x 3 matrices and pad our points to become 3 x matrices. This coordinate system (using three values to x matrices. This coordinate system (using three values to represent a 2D point) is called homogeneous coordinates. represent a 2D point) is called homogeneous coordinates. = ), ( y x P y x =, y x y x s s S = cos sin sin cos θ θ θ θ R θ =, y x y x t t T

Composite Transformations Suppose we wished to perform multiple transformations on a point: P 2 = T 3, P P 3 = S 2, 2 P 2 P 4 = R 3 P 3 M = R 3 S 2,2 T 3, P 4 = MP Remember: Matrix multiplication is associative, not commutative! Transform matrices must be pre-multiplied The first transformation you want to perform will be at the far right, just before the point

Composite Transformations - Scaling Given our three basic transformations we can create other transformations. Scaling with a fixed point A problem with the scale transformation is that it also moves the object being scaled. Scale a line between (2, ) (4,) to twice its length. Before After 2 3 4 5 6 7 8 9 2 3 4 5 6 7 8 9

Composite Transforms - Scaling (cont.) If we scale a line between (,) & (2,) to twice its length, the t left-hand endpoint does not move. Before After 2 3 4 5 6 7 8 9 2 3 4 5 6 7 8 9 (,) is known as a fixed point for the basic scaling transformation. We can use composite transformations to create a scale transformation with different fixed points.

Fixed Point Scaling Scale by 2 with fixed point = (2,) Scale by 2 with fixed point = (2,) Translate the point (2,) to the origin Translate the point (2,) to the origin Scale by 2 Scale by 2 Translate origin to point (2,) Translate origin to point (2,) 2 3 4 5 6 7 8 9 2 3 4 5 6 7 8 9 Before After C T S T = 2 2 2 2 2 2, 2, 2, = 2 2 2 2 C = 6 4 2 2 C

Example of 2D transformation Rotate around an arbitraty point O: y P O x

Rotate around an arbitraty point y P O 9 P x

Rotate around an arbitraty point We know how to rotate around the origin y P O x

Rotate around an arbitraty point but that is not what we want to do! y O P 9 P x P

So what do we do? y P A x

Transform it to a known case Translate(-Ox,-Oy) Oy) y P O P O x

Second step: Rotation y P Translate(-Ox,-Oy) Oy) Rotate(-9) O P O P x

Final: Put everything back Translate(-Ox,-Oy) Oy) y O P Rotate(9) Translate(Ox,Oy) P P O P x

Rotation about arbitrary point IMPORTANT!: Order M = T(Ox,Oy)R(-9)T(-Ox,-Oy) Ox,-Oy) Oy) y O P P P O P x

Rotation about arbitrary point Rotation Of θ Degrees About Point (x,y( x,y) Translate (x,y( x,y) ) to origin Rotate Translate origin to (x,y( x,y) (x,y) (x,y) C = T x, y x cosθ y sinθ sinθ cosθ R θ T x, y x y

Shears Original Data Original Data y Shear y Shear x Shear x Shear a b

Reflections Reflection about the y Reflection about the y-axis axis Reflection about the x Reflection about the x-axis axis

More Reflections Reflection about the origin Reflection about the line y=x?

Transformations as a change in coordinate system All transformations we have looked at involve transforming points in a fixed coordinate system (CS). Can also think of them as a transformation of the CS itself

Transforming the CS - examples Translate(4,4) Rotate(8 )

Why transform the CS? Objects often defined in a natural or convenient CS (2,2) To draw objects transformed by T, we could: Transform each vertex by T, then draw Or, draw vertices in a transformed CS

Drawing in transformed CS Tell system once how to draw the object, then draw in a transformed CS to transform the object House drawn in a CS that s been translated, rotated, and scaled M = S x,y R d T x,y

Mapping between systems Given: The vertices of an object in CS 2 A transformation matrix M that transforms CS to CS 2 What are the coordinates of the object s vertices in CS?

Mapping example Translate(4,4) P Point P is at (,) in the transformed CS (CS 2 ). Where is it in CS? Answer: (4,4) *Note: (4,4) = T 4,4 P

Mapping rule In general, if CS is transformed by a matrix M to form CS 2, a point P in CS 2 is represented by MP in CS

Another example P Translate(4,4), then Scale(.5,.5) Where is P in CS 3? (2,2) Where is P in CS 2? S.5,.5 (2,2) = (,) Where is P in CS? T 4,4 (,) = (5,5) *Note: to go directly from CS 3 to CS we can calculate T 4,4 S.5,.5 (2,2) = (5,5)

General mapping rule If CS is transformed consecutively by M, M 2,, M n to form CS n+, then a point P in CS n+ is represented by CS n+ M M 2 MM n P Pin CS. To form the composite transformation between CSs,, you postmultiply each successive transformation matrix.

OpenGL Transformations Learn how to carry out transformations in OpenGL Rotation Translation Scaling Introduce OpenGL matrix modes Model-view Projection

OpenGL Matrices In OpenGL matrices are part of the state Multiple types Model-View (GL_MODELVIEW) Projection (GL_PROJECTION) Texture (GL_TEXTURE) ) (ignore for now) Color(GL_COLOR) ) (ignore for now) Single set of functions for manipulation Select which to manipulated by glmatrixmode(gl_modelview); glmatrixmode(gl_projection);

Current Transformation Matrix (CTM) Conceptually there is a 4 x 4 homogeneous coordinate matrix, the current transformation matrix (CTM) that is part of the state and is applied to all vertices that pass down the pipeline The CTM is defined in the user program and loaded into a transformation unit C p p =Cp vertices CTM vertices

CTM operations The CTM can be altered either by loading a new CTM or by postmutiplication Load an identity matrix: C I Load an arbitrary matrix: C M Load a translation matrix: C T Load a rotation matrix: C R Load a scaling matrix: C S Postmultiply by an arbitrary matrix: C CM Postmultiply by a translation matrix: C CT Postmultiply by a rotation matrix: C CR Postmultiply by a scaling matrix: C CS

Rotation about a Fixed Point Start with identity matrix: C I Move fixed point to origin: C CT Rotate: C CR Move fixed point back: C CT - Result: C = TR T which is backwards. This result is a consequence of doing postmultiplications. Let s s try again.

Reversing the Order We want C = T R T so we must do the operations in the following order C I C CT - C CR C CT Each operation corresponds to one function call in the program. Note that the last operation specified is the first executed in the program

CTM in OpenGL OpenGL has a model-view and a projection matrix in the pipeline which are concatenated together to form the CTM Can manipulate each by first setting the correct matrix mode

Rotation, Translation, Scaling Load an identity matrix: glloadidentity() Multiply on right: glrotatef(theta, vx, vy, vz) theta in degrees, (vx, vy, vz) define axis of rotation gltranslatef(dx, dy, dz) glscalef( sx, sy, sz) Each has a float (f) and double (d) format (glscaled)

Example Rotation about z axis by 3 degrees with a fixed point of (., 2., 3.) glmatrixmode(gl_modelview); glloadidentity(); gltranslatef(., 2., 3.); glrotatef(3.,.,.,.); gltranslatef(-., -2., -3.); Remember that last matrix specified in the program is the first applied

Arbitrary Matrices Can load and multiply by matrices defined in the application program glloadmatrixf(m) glmultmatrixf(m) The matrix m is a one dimension array of 6 elements which are the components of the desired 4 x 4 matrix stored by columns In glmultmatrixf, m multiplies the existing matrix on the right

Transformations in OpenGL OpenGL makes it easy to do transformations to the CS, not the object Sequence of operations: Set up a routine to draw the object in its base CS Call transformation routines to transform the CS Object drawn in transformed CS

OpenGL transformation example drawhouse(){ glbegin(gl_line_loop); glvertex2i(,); glvertex2i(,2);... glend(); } drawtransformedhouse(){ glmatrixmode(gl_modelview); gltranslatef(4., 4.,.); glscalef(.5,.5,.); drawhouse(); } Draws basic house Draws transformed house

Matrix Stacks In many situations we want to save transformation matrices for use later Traversing hierarchical data structures Avoiding state changes when executing display lists OpenGL maintains stacks for each type of matrix Access present type (as set by glmatrixmode) by glpushmatrix() glpopmatrix()

OpenGL matrix stack example M glloadmatrixf(m); glpushmatrix(); glmultmatrixf(m); glpushmatrix(); glmultmatrixf(m4); render chair2; glpop M atrix(); glpushmatrix(); glmultmatrixf(m3); render chair; glpop M atrix(); render table; glpop M atrix(); glpushmatrix(); glmultmatrixf(m2); render rug; glpop M atrix() render room; M room M 2 table rug M 3 M 4 chair chair2 M *M *M 4 M *M M