Computer Graphics. Chapter 7 2D Geometric Transformations

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

Computer Graphics. Chapter 10 Three-Dimensional Viewing

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

Lecture 5b. Transformation

CS 4204 Computer Graphics

CSCI E-74. Simulation and Gaming

CSC 470 Computer Graphics

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

GL_MODELVIEW transformation

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

Transformations. CSCI 420 Computer Graphics Lecture 4

CS 591B Lecture 9: The OpenGL Rendering Pipeline

GRAFIKA KOMPUTER. ~ M. Ali Fauzi

Transformation Pipeline

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

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 Geometric Transformations

C OMPUTER G RAPHICS Thursday

Order of Transformations

Modeling with Transformations

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

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

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

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

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

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

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

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

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

Transformations. CSCI 420 Computer Graphics Lecture 5

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

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

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

Transformations Computer Graphics I Lecture 4

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

CS Computer Graphics: Transformations & The Synthetic Camera

Computer Graphics Lighting

Computer Graphics Lighting. Why Do We Care About Lighting?

Introduction to Computer Graphics with WebGL

Computer Viewing Computer Graphics I, Fall 2008

Transformation, Input and Interaction. Hanyang University

Affine Transformations in 3D

COMP Computer Graphics and Image Processing. 5: Viewing 1: The camera. In part 1 of our study of Viewing, we ll look at ˆʹ U ˆ ʹ F ˆʹ S

Fachhochschule Regensburg, Germany, February 15, 2017

CS D Transformation. Junqiao Zhao 赵君峤

Transformations Computer Graphics I Lecture 4

Getting Started. Overview (1): Getting Started (1): Getting Started (2): Getting Started (3): COSC 4431/5331 Computer Graphics.

Prof. Feng Liu. Fall /19/2016

6. Modelview Transformations

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

Computer graphics MN1

3D Viewing Episode 2

Computer Graphics 7: Viewing in 3-D

DH2323 DGI16 Lab2 Transformations

OpenGL Transformations

Computer Science 336 Fall 2017 Homework 2

Viewing with Computers (OpenGL)

Overview of Projections: From a 3D world to a 2D screen.

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

Computer Graphics. Bing-Yu Chen National Taiwan University

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

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

Rendering Pipeline and Coordinates Transforms

Lecture 4 of 41. Lab 1a: OpenGL Basics

Introduction to OpenGL Transformations, Viewing and Lighting. Ali Bigdelou

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

API for creating a display window and using keyboard/mouse interations. See RayWindow.cpp to see how these are used for Assignment3

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

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

Viewing COMPSCI 464. Image Credits: Encarta and

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

CS354 Computer Graphics Viewing and Modeling

Overview. By end of the week:

The OpenGL Mathematics (GLM) Library

Introduction to Computer Graphics 4. Viewing in 3D

This library uses only GL functions but contains code for creating common objects and simplifying viewing.

Precept 2 Aleksey Boyko February 18, 2011

An Interactive Introduction to OpenGL Programming

CIS 636 Interactive Computer Graphics CIS 736 Computer Graphics Spring 2011

Review of Thursday. xa + yb xc + yd

Introduction to OpenGL

Projection: Mapping 3-D to 2-D. Orthographic Projection. The Canonical Camera Configuration. Perspective Projection

CSE 167: Introduction to Computer Graphics Lecture #4: Vertex Transformation

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

Chapter 3: Modeling Transformation

CS 4204 Computer Graphics

OpenGL. Toolkits.

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

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

Viewing/Projections IV. Week 4, Fri Feb 1

Lecture 2 2D transformations Introduction to OpenGL

CSCI 4620/8626. The 2D Viewing Pipeline

UNIT 2 2D TRANSFORMATIONS

CS452/552; EE465/505. Transformations

part 3 Martin Samuelčík Room I4

Overview. Viewing and perspectives. Planar Geometric Projections. Classical Viewing. Classical views Computer viewing Perspective normalization

The OpenGL Mathematics (GLM) Library. What is GLM?

CSE 690: GPGPU. Lecture 2: Understanding the Fabric - Intro to Graphics. Klaus Mueller Stony Brook University Computer Science Department

GEOMETRIC OBJECTS AND TRANSFORMATIONS I

Computer graphics MN1

Transcription:

Computer Graphics Chapter 7 2D Geometric Transformations

Chapter 7 Two-Dimensional Geometric Transformations Part III. OpenGL Functions for Two-Dimensional Geometric Transformations OpenGL Geometric Transformation Programming Examples 2

OpenGL Geometric Transformation Functions Be careful of manipulating the matrix in OpenGL OpenGL uses 4X4 matrix for transformation. The 16 elements are stored as 1D in column-major order OpenGL transform matrix C and C++ store matrices in row-major order If you declare a matrix to be used in OpenGL as GLfloat M[4][4]; to access the element in row i and column j, you need to refer to it by M[j][i]; or, as GLfloat M[16]; and then you need to convert it to conventional rowmajor order. 3

OpenGL Transformations Three types Modeling, Viewing and Projection 4 (From OpenGL Super Bible)

Standard 2D Viewing Pipeline Modeling Transformation Viewing Transformation Normalization Transformation WC VC 5 MC (Local Coor.) To make the viewing process independent of any output device, viewing coordinates is converted to normalized coordinates. Clipping is usually performed in normalized coordinates. NC DC

Modeling Transformations Modeling transformations: to manipulate/create your model and the particular objects within it. Move objects into place, rotates them, and scales them, etc. The final appearance of your scene or object can depend greatly on the order in which the modeling transformations are applied. 6

Viewing Transformation Viewing transformation: to place & point a camera to view the scene. By default, the point of observation is at the origin (0,0,0) looking down the negative z-axis ( into the monitor screen). Objects drawn with positive z values would be behind the observer. You can put the point of observation anywhere you want, and looking in any direction. Transformation demo - Nate 7

Projection and Viewport Transformations 8 Projection transformation: applied to your final Modelview orientation in which way to project. Defines how a constructed scene (after all the modeling is done) is translated to the final 2D image on the viewing plane. Defines the viewing volume and establishes clipping planes. Two types Orthographic Perspective Viewport transformation: maps the 2D projection result of your scene to a window somewhere on your screen.

OpenGL Transformations In OpenGL, all the transformations are described as a multiplication of matrices. The mathematics behind these transformations are greatly simplified by the mathematical notation of the matrix. Each of the transformations can be achieved by multiplying a matrix that contains the vertices, by a matrix that describes the transformation. 9

OpenGL Geometric Transformation Functions OpenGL matrix operation function void glmatrixmode(glenum mode); Specify which matrix is the current matrix mode: GL_MODELVIEW, GL_PROJECTION, GL_TEXTURE; GL_COLOR (if ARB_imaging extension is supported). e.g.: glmatrixmode (GL_MODELVIEW); OpenGL matrix operations glmatrixmode (GL_MODELVIEW); Set up the matrix for geometric transformations glloadidentity (); // assign identity matrix to the current matrix // to apply any transformation matrix to transform your scene 10

Model-View Matrix: GL_MODELVIEW GL_MODELVIEW Store and combine the geometric transformations to models and viewing-coordinate system Combine viewing matrix and modeling matrix into one matrix Viewing transformation For example: glulookat() Modeling transformation: OpenGL transformation functions Translation transformation: m12, m13, m14 Other Euclidean/affine transformations, such as rotation or scaling: (m0, m1, m2), (m4, m5, m6) and (m8, m9, m10) 11

Model-View Matrix: GL_MODELVIEW GL_MODELVIEW M 1.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 1.0 12 glmatrixmode (GL_MODELVIEW); glloadidentity (); These 3 sets // assign identity matrix to the current matrix (m0, m1, m2) : +X axis, left vector, (1, 0, 0) by default (m4, m5, m6) : +Y axis, up vector, (0, 1, 0) by default (m8, m9, m10) : +Z axis, forward vector, (0, 0, 1) by default are actually representing 3 orthogonal axes. glloadmatrix* (elements16); // replace the current matrix by your own

Model-View Matrix: GL_MODELVIEW Example glmatrixmode (GL_MODELVIEW); glloadidentity (); GLfloat elems [16]; GLint k; for (k = 0; k < 16; k++) elems [k] = float (k); glloadmatrixf (elems); M 0.0 1.0 2.0 3.0 4.0 5.0 6.0 7.0 8.0 9.0 10.0 11.0 12.0 13.0 14.0 15.0 glmatrixmode() http://www.opengl.org/sdk/docs/man/ 13

OpenGL Geometric Transformation Functions Basic OpenGL geometric transformations on the matrix: gltranslate* (tx, ty, tz); [ gltranslatef (25.0, -10.0, 0.0); ] for 2D, set tz = 0. - Post-multiplies the current matrix by a matrix that moves the object by the given x-, y-, and z-values glscale* (sx, sy, sz); [ glscalef (2.0, -3.0, 1.0); ] - Post-multiplies the current matrix by a matrix that scales an object about the origin. None of sx, sy or sz is zero. glrotate* (theta, vx, vy, vz); [ glrotatef (90.0, 0.0, 0.0, 1.0); ] - Post-multiplies the current matrix by a matrix that rotates the object in a counterclockwise direction. vector v=(vx, vy, vz) defines the orientation for the rotation axis that passes though the coordinate origin. ( the rotation center is (0, 0, 0) ) 14

OpenGL: Order in Matrix Multiplication glmatrixmode (GL_MODELVIEW); glloadidentity ( ); //Set current matrix to the identity. glmultmatrixf (elemsm2); //Post-multiply identity by matrix M2. glmultmatrixf (elemsm1); //Post-multiply M2 by matrix M1. glbegin (GL_POINTS) glvertex3f (vertex); I(identity), M2, M2 M1 glend( ); Modelview matrix successively contains: The concatenated matrix is: M=M2 M1 The transformed vertex is: M2 (M1 vertex) In OpenGL, a transformation sequence is applied in reverse order of which it is specified. 15

OpenGL: Order in Matrix Multiplication Example // rotate object 30 degrees around Z-axis glrotatef(30.0, 0.0, 0.0, 1.0); // move object to (2.0, 3.0, 0.0) gltranslatef(2.0, 3.0, 0.0); drawobject(); The object will be translated first then rotated. 16

OpenGL Geometric Trans. Programming Examples glmatrixmode (GL_MODELVIEW); //Identity matrix glcolor3f (0.0, 0.0, 1.0); glrecti (50, 100, 200, 150); // Set current color to blue // Display blue rectangle. glcolor3f (1.0, 0.0, 0.0); // Red gltranslatef (-200.0, -50.0, 0.0); // Set translation parameters. glrecti (50, 100, 200, 150); // Display red, translated rectangle. glloadidentity (); // Reset current matrix to identity. glrotatef (90.0, 0.0, 0.0, 1.0); // Set 90-deg, rotation about z axis. glrecti (50, 100, 200, 150); // Display red, rotated rectangle. glloadidentity (); // Reset current matrix to identity. glscalef (-0.5, 1.0, 1.0); // Set scale-reflection parameters. glrecti (50, 100, 200, 150); // Display red, transformed rectangle. 17

Summary Basic 2D geometric transformations Translation Rotation Scaling Reflection, shearing Combination of these transformations Homogeneous coordinate representation OpenGL geometric transformation functions GL_MODELVIEW matrix Order in multiple matrix multiplication Example 18