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

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

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

Order of Transformations

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

CSC 470 Computer Graphics

CS D Transformation. Junqiao Zhao 赵君峤

Introduction to Computer Graphics with WebGL

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

CS452/552; EE465/505. Transformations

CS 4204 Computer Graphics

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

Introduction to Computer Graphics with WebGL

C OMPUTER G RAPHICS Thursday

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

Computer Graphics CS 543 Lecture 4 (Part 2) Building 3D Models (Part 2)

Interaction. CSCI 480 Computer Graphics Lecture 3

Interaction Computer Graphics I Lecture 3

Computer graphics MN1

Vertex Buffer Objects and Transformations Week 4

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

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

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 (4731) Lecture 4: 2D Graphics Systems (Drawing Polylines, tiling, & Aspect Ratio)

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

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

Comp 410/510 Computer Graphics Spring Programming with OpenGL Part 4: Three Dimensions

CS 543 Lecture 1 (Part 3) Prof Emmanuel Agu. Computer Science Dept. Worcester Polytechnic Institute (WPI)

Computer graphics MN1

Transformation, Input and Interaction. Hanyang University

Project Sketchpad. Ivan Sutherland (MIT 1963) established the basic interactive paradigm that characterizes interactive computer graphics:

Computer Graphics (CS 543) Lecture 2b: 2D Graphics Systems (Drawing Polylines, tiling, & Aspect Ratio)

Computer Graphics (CS 543) Lecture 1 (Part 2): Introduction to OpenGL/GLUT (Part 1)

Recall: Indexing into Cube Map

Computer Graphics. Chapter 7 2D Geometric Transformations

Computer Graphics. Bing-Yu Chen National Taiwan University

Books, OpenGL, GLUT, GLUI, CUDA, OpenCL, OpenCV, PointClouds, and G3D

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

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

OpenGL/GLUT Intro. Week 1, Fri Jan 12

Precept 2 Aleksey Boyko February 18, 2011

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

Comp 410/510 Computer Graphics Spring Input & Interaction

Programming with OpenGL Part 3: Three Dimensions

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

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

Computer Graphics (CS 4731) OpenGL/GLUT(Part 1)

Lecture 3 Advanced Computer Graphics (CS & SE )

Computer Graphics (CS 543) Lecture 3b: Shader Setup & GLSL Introduction

Recall: Function Calls to Create Transform Matrices

Ulf Assarsson Department of Computer Engineering Chalmers University of Technology

Lecture 3. Understanding of OPenGL programming

Books, OpenGL, GLUT, CUDA, OpenCL, OpenCV, PointClouds, G3D, and Qt

To Do. Computer Graphics (Fall 2008) Course Outline. Course Outline. Methodology for Lecture. Demo: Surreal (HW 3)

Transformations Computer Graphics I Lecture 4

Computer Graphics (CS 543) Lecture 4a: Linear Algebra for Graphics (Points, Scalars, Vectors)

Input and Interaction. 1. Interaction. Chapter 3. Introduction: - We now turn to the development of interactive graphics programs.

SOURCES AND URLS BIBLIOGRAPHY AND REFERENCES


Using OpenGL with CUDA

// double buffering and RGB glutinitdisplaymode(glut_double GLUT_RGBA); // your own initializations

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

CS Computer Graphics: Transformations & The Synthetic Camera

Transformations. CSCI 420 Computer Graphics Lecture 4

Ulf Assarsson Department of Computer Engineering Chalmers University of Technology

Computer Graphics Geometric Transformations

QUESTION 1 [10] 2 COS340-A October/November 2009

Transformations Computer Graphics I Lecture 4

FAKULTI TEKNOLOGI MAKLUMAT DAN KOMUNIKASI BITM INTERACTIVE COMPUTER GRAPHICS LAB SESSION 4. C++ - OpenGL

CGT520 Transformations

CS452/552; EE465/505. Models & Viewing

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

Introduction to Computer Graphics. Hardware Acceleration Review

Computer graphics MN1

Computer Graphics (CS 543) Lecture 4a: Introduction to Transformations

CS 432 Interactive Computer Graphics

C++ is Fun Part 13 at Turbine/Warner Bros.! Russell Hanson

Comp 410/510 Computer Graphics Spring Programming with OpenGL Part 2: First Program

CS559: Computer Graphics. Lecture 12: OpenGL Li Zhang Spring 2008

Transformations. CSCI 420 Computer Graphics Lecture 5

Intro to OpenGL III. Don Fussell Computer Science Department The University of Texas at Austin

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

Working with Callbacks

Introduction to 3D Graphics with OpenGL. Z-Buffer Hidden Surface Removal. Binghamton University. EngiNet. Thomas J. Watson

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

Introduction to OpenGL

Lecture 2 CISC440/640 Spring Department of Computer and Information Science

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

Visualizing Molecular Dynamics

OpenGL refresher. Advanced Computer Graphics 2012

Computer Graphics (CS 4731) OpenGL/GLUT (Part 2)

1) Program to display a set of values {fij} as a rectangular mesh. #include<gl/glut.h> #define maxx 20. #define maxy 20. #define dx 15.

Erik Anchondo cse 520 lab 4

Input, Interaction and Animation Week 2

Graphics Programming

Hidden Surface Removal. 3D Graphics with OpenGL. Back-Face Culling

CS 432 Interactive Computer Graphics

Cameras (and eye) Ideal Pinhole. Real Pinhole. Real + lens. Depth of field

Fourier Series. Given a periodic function, x(t), (-T <t <T): + b n sin n t T. a n cos n t T. 2 a 0 + Z T. a n = 1 T. x(t) cos n t T. b n = 1 T.

Transcription:

Computer Graphics CS 543 Lecture 5 (Part 2) Implementing Transformations Prof Emmanuel Agu Computer Science Dept. Worcester Polytechnic Institute (WPI)

Objectives Learn how to implement transformations in OpenGL Rotation Translation Scaling Introduce mat,h and vec.h transformations Model view Projection

Pre 3.OpenGL Matrices In 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);

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

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

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

CTM in OpenGL Previously, OpenGL had a model view and a projection matrix in the pipeline that were concatenated together to form the CTM Useful!! So, we will emulate this process in our application

Rotation, Translation, Scaling Create an identity matrix: mat4 m = Identity(); Multiply on right by rotation matrix of theta in degrees where (vx, vy, vz) define axis of rotation mat4 r = Rotate(theta, vx, vy, vz) m = m*r; Do same with translation and scaling: mat4 s = Scale( sx, sy, sz) mat4 t = Transalate(dx, dy, dz); m = m*s*t;

Transformation matrices Formed? Converts all transforms (translate, scale, rotate) to 4x4 matrix Put 4x4 transform matrix into modelview matrix How? multiplies current modelview matrix by 4x4 matrix Example mat4 m = Identity(); CTM Matrix

Transformation matrices Formed? mat4 m = Identity(); mat4 t = Translate(3,6,4); m = m*t; CTM Matrix * 4 6 3 4 6 3 Translation Matrix Identity Matrix

Transformation matrices Formed? Then what? mat4 m = Identity(); mat4 t = Translate(3,6,4); m = m*t; colorcube( ); CTM Matrix 4 6 3 Each vertex of cube is multiplied by CTM matrix to get translated vertex * 5 7 4 Original vertex Transformed vertex

Transformation matrices Formed? Consider following code snipet mat4 m = Identity(); mat4 s = Scale(,2,3); m = m*s; CTM Matrix 3 2 3 2 Scaling Matrix Identity Matrix

Transformation matrices Formed? Then what? mat4 m = Identity(); mat4 s = Scale(,2,3); m = m*s; colorcube( ); CTM Matrix Each vertex of cube is multiplied by modelview matrix to get scaled vertex position * 3 2 Original vertex Transformed vertex 3 2

Transformation matrices Formed? What of gltranslate, then scale, then. Just multiply them together. Evaluated in reverse order!! E.g: mat4 m = Identity(); mat4 s = Scale(,2,3); mat4 t = Translate(3,6,4); m = m*s*t; Translate Matrix 3 2 4 6 3 2 3 2 2 3 Final CTM Matrix Scale Matrix Identity Matrix

Transformation matrices Formed? Then what? mat4 m = Identity(); mat4 s = Scale(,2,3); mat4 t = Translate(3,6,4); m = m*s*t; colorcube( ); Modelview Matrix 3 2 2 3 2 4 4 5 Original vertex Transformed vertex Each vertex of cube is multiplied by modelview matrix to get scaled vertex position

Example Rotation about z axis by 3 degrees about a fixed point (., 2., 3.) mat 4 m = Identity(); m = Translate(., 2., 3.)* Rotate(3.,.,.,.)* Translate(-., -2., -3.); Remember last matrix specified in program (i.e. translate matrix in example) is first applied

Arbitrary Matrices Can multiply by matrices from transformation commands (Translate, Rotate, Scale) defined in the application program Can also load CTM with arbitrary 4x4 matrices Matrices are stored as one dimensional array of 6 elements that are components of desired 4 x 4 matrix

Matrix Stacks In many situations we want to save transformation matrices for use later Traversing hierarchical data structures (Chapter 8) Avoiding state changes when executing display lists Pre 3. OpenGL maintained stacks for each type of matrix Easy to create the same functionality with a simple stack class

Reading Back State Can also access OpenGL variables (and other parts of the state) by query functions glgetintegerv glgetfloatv glgetbooleanv glgetdoublev glisenabled

Using Transformations Example: use idle function to rotate a cube and mouse function to change direction of rotation Start with program that draws cube as before Centered at origin Sides aligned with axes

main.c void main(int argc, char **argv) { glutinit(&argc, argv); glutinitdisplaymode(glut_double GLUT_RGB GLUT_DEPTH); glutinitwindowsize(5, 5); glutcreatewindow("colorcube"); glutreshapefunc(myreshape); glutdisplayfunc(display); glutidlefunc(spincube); glutmousefunc(mouse); glenable(gl_depth_test); glutmainloop(); }

Idle and Mouse callbacks void spincube() { theta[axis] += 2.; if( theta[axis] > 36. ) theta[axis] -= 36.; glutpostredisplay(); } void mouse(int btn, int state, int x, int y) { if(btn==glut_left_button && state == GLUT_DOWN) axis = ; if(btn==glut_middle_button && state == GLUT_DOWN) axis = ; if(btn==glut_right_button && state == GLUT_DOWN) axis = 2; }

Display callback We can form matrix (CTM) in application and send to shader and let shader do the rotation or we can send the angle and axis to the shader and let the shader form the transformation matrix and then do the rotation More efficient than transforming data in application and resending the data void display() { glclear(gl_color_buffer_bit GL_DEPTH_BUFFER_BIT); gluniform( ); //or gluniformmatrix gldrawarrays( ); glutswapbuffers(); }

Using the Model view Matrix In OpenGL the model view matrix is used to Position camera (using LookAt function) Transform 3D models The projection matrix used to define view volume and select a camera lens Although these matrices no longer part of OpenGL state, good to create them in our applications

3D? Interfaces One of the major problems in interactive computer graphics is how to use two dimensional devices such as a mouse to interface with three dimensional obejcts Example: how to form an instance matrix? Some alternatives Virtual trackball 3D input devices such as the spaceball Use areas of the screen Distance from center controls angle, position, scale depending on mouse button depressed

GLUI User Interface Library by Paul Rademacher Provides sophisticated controls and menus Not used in this class/optional Virtual trackball

References Angel and Shreiner, Chapter 3 Hill and Kelley, appendix 4