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

Similar documents
Transformations. CSCI 420 Computer Graphics Lecture 5

Transformations. CSCI 420 Computer Graphics Lecture 4

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

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

Viewing and Projection

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

CS D Transformation. Junqiao Zhao 赵君峤

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

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

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

Introduction to Computer Graphics with WebGL

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

Computer Graphics Geometric Transformations

Order of Transformations

CSC 470 Computer Graphics

Last week. Machiraju/Zhang/Möller

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

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

CSCI E-74. Simulation and Gaming

CS452/552; EE465/505. Geometry Transformations

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

GEOMETRIC TRANSFORMATIONS AND VIEWING

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

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

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

Computer Graphics 7: Viewing in 3-D

Quaternions and Rotations

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

Today s Agenda. Geometry

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

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

Three Main Themes of Computer Graphics

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

Affine Transformation. Edith Law & Mike Terry

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

CS452/552; EE465/505. Transformations

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

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

CT5510: Computer Graphics. Transformation BOCHANG MOON

COMP30019 Graphics and Interaction Three-dimensional transformation geometry and perspective

CS 591B Lecture 9: The OpenGL Rendering Pipeline

Quaternions and Rotations

C OMPUTER G RAPHICS Thursday

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

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

Transforms. COMP 575/770 Spring 2013

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

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

3.1 Viewing and Projection

Viewing and Projection

CS Computer Graphics: Transformations & The Synthetic Camera

Computer Graphics. Chapter 10 Three-Dimensional Viewing

Rendering Pipeline and Coordinates Transforms

Affine Transformations Computer Graphics Scott D. Anderson

Computer Science 336 Fall 2017 Homework 2

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

Quaternions and Rotations

INF3320 Computer Graphics and Discrete Geometry

GL_MODELVIEW transformation

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

Shaders. Introduction. OpenGL Grows via Extensions. OpenGL Extensions. OpenGL 2.0 Added Shaders. Shaders Enable Many New Effects

3D Viewing Episode 2

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

Lecture 5b. Transformation

Shadows in Computer Graphics

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

Transformations: 2D Transforms

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

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

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

Interaction. CSCI 420 Computer Graphics Lecture 3

Computer Graphics Lighting

Computer Graphics Lighting. Why Do We Care About Lighting?

DH2323 DGI16 Lab2 Transformations

Visual Recognition: Image Formation

Geometric Queries for Ray Tracing

Computer Graphics. Bing-Yu Chen National Taiwan University

Chapter 3: Modeling Transformation

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

Chapter 3 - Basic Mathematics for 3D Computer Graphics

Overview. By end of the week:

1. We ll look at: Types of geometrical transformation. Vector and matrix representations

2D Object Definition (1/3)

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

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

Review of Thursday. xa + yb xc + yd

Vector Algebra Transformations. Lecture 4

The Importance of Matrices in the DirectX API. by adding support in the programming language for frequently used calculations.

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

Transformation Pipeline

Figure 1. Lecture 1: Three Dimensional graphics: Projections and Transformations

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

3-D D Euclidean Space - Vectors

Transcription:

CSCI 420 Computer Graphics Lecture 5 OpenGL Transformations Transformations Vector Spaces Euclidean Spaces Frames Homogeneous Coordinates Transformation Matrices Jernej Barbic [Angel, Ch. 3] University of Southern California 1 2 OpenGL Transformation Matrices matrix (4x4 matrix) matrix (4x4 matrix) 4x4 Matrix (this lecture) Translate, rotate, scale objects Position the camera in 3D (object space) in the camera coordinate in 2D in 3D (object space) in the camera coordinate in 2D 3 4 4x4 Matrix (next lecture) OpenGL Transformation Matrices Project from 3D to 2D in 3D in canonical 3D coordinate in 2D Manipulated separately in OpenGL Core profile: set them directly Compatibility profile: must set matrix mode glmatrixmode (GL_MODELVIEW); glmatrixmode (GL_PROJECTION); 5 6 1

Setting the Modelview Matrix: Core Profile Set identity: openglmatrix->setmatrixmode(openglmatrix::modelview); openglmatrix->loadidentity(); Setting the Modelview Matrix: Compatibility Profile Load or post-multiply glmatrixmode (GL_MODELVIEW); glloadidentity(); // very common usage float m[16] = { }; glloadmatrixf(m); // rare, advanced glmultmatrixf(m); // rare, advanced Use our openglmatrix library functions: openglmatrix->translate(dx, dy, dz); openglmatrix->rotate(angle, vx, vy, vz); openglmatrix->scale(sx, sy, sz); Upload m to the GPU: float m[16]; // column-major openglmatrix->getmatrix(m); GLboolean isrowmajor = GL_FALSE; gluniformmatrix4fv(h_modelviewmatrix, 1, isrowmajor, m); // note: h_modelviewmatrix is a handle of the shader modelview matrix variable (will discuss in Shaders lecture) 7 Translated, rotated, scaled object Use library functions gltranslatef(dx, dy, dz); glrotatef(angle, vx, vy, vz); glscalef(sx, sy, sz); 8 The rendering coordinate Initially (after LoadIdentity()) : rendering coordinate = coordinate 9 10 The rendering coordinate The rendering coordinate Translate(x, y, z); Rotate(angle, ax, ay, az); [x, y,z] rendering coordinate 11 12 2

The rendering coordinate OpenGL pseudo-code Scale(sx, sy, sz); MatrixMode(ModelView); LoadIdentity(); Translate(x, y, z); Rotate(angle, ax, ay, az); Scale(sx, sy, sz); gluniformmatrix4fv( ); renderbunny(); 13 14 Rendering more objects Rendering more objects How to obtain this frame? How to obtain this frame? Solution 1: Find Translate( ), Rotate( ), Scale( ) 15 16 Rendering more objects How to obtain this frame? 3D Math Review Solution 2: LoadIdentity(); Find Translate( ), Rotate( ), Scale( ) 17 18 3

Scalars Scalars α, β, γ from a scalar field Operations α+β, α β, 0, 1, -α, ( )-1 Expected laws apply Examples: rationals or reals with addition and multiplication Vectors Vectors u, v, w from a vector space Vector addition u + v, subtraction u - v Zero vector 0 Scalar multiplication α v 19 20 Euclidean Space Vector space over real numbers Lines and Line Segments Parametric form of line: P(α) = P0 + α d 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 Line segment between Q and R: P(α) = (1-α) Q + α R for 0 α 1 21 22 Convex Hull Convex hull defined by P = α 1 P 1 + + α n P n for α 1 + + α n = 1 and 0 α i 1, i = 1,..., n 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 24 4

Cross Product Plane Plane defined by point P0 and vectors u and v u and v should not be parallel a x b = a b sin(θ) Cross product is perpendicular to both a and b Right-hand rule Parametric form: T(α, β) = P0 + α u + β v (α and β are scalars) n = u x v / u x v is the normal 25 Source: Wikipedia n (P P0) = 0 if and only if P lies in plane 26 Coordinate Systems Let v 1, v 2, v 3 be three linearly independent vectors in a 3-dimensional vector space Frames Frame = origin P0 + coordinate Any point P = P0 + α 1 v 1 + α 2 v 2 + α 3 v 3 Can write any vector w as w = α 1 v 1 + α 2 v 2 + α 3 v 3 for some scalars α 1, α 2, α 3 27 28 In Practice, Frames are Often Orthogonal 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 30 5

Linear Transformations Representing 3D transformations (and model-view matrices) 3 x 3 matrices represent linear transformations a = Mb Can represent rotation, scaling, and reflection Cannot represent translation 31 32 In order to represent rotations, scales AND translations: Homogeneous Coordinates Homogeneous coordinates are transformed by 4x4 matrices 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 = [bα 1 bα 2 bα 3 b] T, for any scalar b 0 p q = A p q 33 4-vector 4x4 matrix 4-vector 34 Affine Transformations (4x4 matrices) Translation Rotation Scaling Any composition of the above Later: projective (perspective) transformations - Also expressible as 4 x 4 matrices! 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 36 6

Scaling x = βx x y = βy y z = βz z Express as q = S p and solve for S 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 38 Rotation in 3 Dimensions Orthogonal matrices: RR T = R T R = I det(r) = 1 Affine transformation: 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)) 39 Compatibility mode: When calling gltranslate3f, glrotatef, or glscalef, OpenGL forms the corresponding 4x4 matrix, and multiplies the current modelview matrix with it. 40 Summary OpenGL Transformation Matrices Vector Spaces Frames Homogeneous Coordinates Transformation Matrices 41 7