Introduction to Computer Graphics with WebGL

Similar documents
CS452/552; EE465/505. Transformations

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

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

Introduction to Computer Graphics with WebGL

CS 4204 Computer Graphics

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

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

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

Order of Transformations

Introduction to Computer Graphics with WebGL

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

CSC 470 Computer Graphics

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

Transformations. Rotation and Scaling

CS D Transformation. Junqiao Zhao 赵君峤

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

Computer Graphics. Chapter 7 2D Geometric Transformations

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

Transformations Computer Graphics I Lecture 4

Transformations Computer Graphics I Lecture 4

Transformations. CSCI 420 Computer Graphics Lecture 5

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

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

Transformations. CSCI 420 Computer Graphics Lecture 4

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

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

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

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

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

Fachhochschule Regensburg, Germany, February 15, 2017

Computer Graphics Geometric Transformations

Introduction to OpenGL

3D Viewing Episode 2

Computer Graphics. Bing-Yu Chen National Taiwan University

Affine Transformations in 3D

CS 432 Interactive Computer Graphics

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

C OMPUTER G RAPHICS Thursday

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

Computer Graphics 7: Viewing in 3-D

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

CSCI E-74. Simulation and Gaming

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

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

Graphics pipeline and transformations. Composition of transformations

3D Viewing Episode 2

CS452/552; EE465/505. Models & Viewing

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

Review of Thursday. xa + yb xc + yd

Introduction to Computer Graphics with WebGL

Computer Graphics (CS 543) Lecture 6a: Hierarchical 3D Models. Prof Emmanuel Agu. Computer Science Dept. Worcester Polytechnic Institute (WPI)

Transforms 1 Christian Miller CS Fall 2011

Prof. Feng Liu. Fall /19/2016

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

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

Computer Viewing Computer Graphics I, Fall 2008

CS Computer Graphics: Transformations & The Synthetic Camera

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

Hierarchical Modeling I. Angel and Shreiner: Interactive Computer Graphics 7E Addison-Wesley 2015

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

Overview. By end of the week:

OPENGL RENDERING PIPELINE

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

Computer graphics 2: Graduate seminar in computational aesthetics

Computer Science 336 Fall 2017 Homework 2

Hierarchical Modeling. CS 432 Interactive Computer Graphics Prof. David E. Breen Department of Computer Science

Transformation. Computer Graphics October. Dr Anton Gerdelan

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

Virtual Cameras & Their Matrices

GL_MODELVIEW transformation

GEOMETRIC TRANSFORMATIONS AND VIEWING

Transformation Pipeline

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

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

Lecture 08: Hierarchical Modeling with Scene Graphs

Programming with OpenGL Part 3: Shaders. Ed Angel Professor of Emeritus of Computer Science University of New Mexico

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

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

Building Models. Angel and Shreiner: Interactive Computer Graphics 7E Addison-Wesley 2015

C P S C 314 S H A D E R S, O P E N G L, & J S RENDERING PIPELINE. Mikhail Bessmeltsev

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

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

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

Exercise Max. Points Total 90

Introduction to Computer Graphics with WebGL

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

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

CS 591B Lecture 9: The OpenGL Rendering Pipeline

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

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

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

Programming with OpenGL Shaders I. Adapted From: Ed Angel Professor of Emeritus of Computer Science University of New Mexico

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

Introduction to Computer Graphics with WebGL

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

Viewing COMPSCI 464. Image Credits: Encarta and

Last week. Machiraju/Zhang/Möller/Fuhrmann

1 Preview. Dr. Scott Gordon Computer Science Dept. CSUS. Virtual Cameras, Viewing Transformations: CSc-155 Advanced Computer Graphics

INF3320 Computer Graphics and Discrete Geometry

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

Transcription:

Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science Laboratory University of New Mexico

WebGL Transformations Ed Angel Professor Emeritus of Computer Science University of New Mexico 2

Objectives Learn how to carry out transformations in WebGL - Rotation - Translation - Scaling Introduce MV.js transformations - Model-view - Projection 3

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

Why Deprecation Functions were based on carrying out the operations on the CPU as part of the fixed function pipeline Current model-view and projection matrices were automatically applied to all vertices using CPU We will use the notion of a current transformation matrix with the understanding that it may be applied in the shaders 5

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 vertices p C CTM p =Cp vertices 6

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 C R Postmultiply by a scaling matrix: C C S 7

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 try again. 8

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 9

CTM in WebGL OpenGL had a model-view and a projection matrix in the pipeline which were concatenated together to form the CTM We will emulate this process 0

Using the ModelView Matrix In WebGL, the model-view matrix is used to - Position the camera Can be done by rotations and translations but is often easier to use the lookat function in MV.js - Build models of objects The projection matrix is used to define the view volume and to select a camera lens Although these matrices are no longer part of the OpenGL state, it is usually a good strategy to create them in our own applications q = P*MV*p

Rotation, Translation, Scaling Create an identity matrix: var m = mat4(); Multiply on right by rotation matrix of theta in degrees where (vx, vy, vz) define axis of rotation var r = rotate(theta, vx, vy, vz) m = mult(m, r); Also have rotatex, rotatey, rotatez Do same with translation and scaling: var s = scale( sx, sy, sz) var t = translate(dx, dy, dz); m = mult(s, t); 2

Example Rotation about z axis by 30 degrees with a fixed point of (.0, 2.0, 3.0) var m = mult(translate(.0, 2.0, 3.0), rotate(30.0, 0.0, 0.0,.0)); m = mult(m, translate(-.0, -2.0, -3.0)); Remember that last matrix specified in the program is the first applied 3

Arbitrary Matrices Can load and multiply by matrices defined in the application program Matrices are stored as one dimensional array of 6 elements by MV.js but can be treated as 4 x 4 matrices in row major order OpenGL wants column major data gl.unifrommatrix4f has a parameter for automatic transpose by it must be set to false. flatten function converts to column major order which is required by WebGL functions 4

Matrix Stacks In many situations we want to save transformation matrices for use later - Traversing hierarchical data structures (Chapter 9) Pre 3. OpenGL maintained stacks for each type of matrix Easy to create the same functionality in JS - push and pop are part of Array object var stack = [ ] stack.push(modelviewmatrix); modelviewmatrix = stack.pop(); 5