Chapter 3 - Basic Mathematics for 3D Computer Graphics

Similar documents
Chapter 2 - Basic Mathematics for 3D Computer Graphics

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

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

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

COMP3421. Introduction to 3D Graphics

MORE OPENGL. Pramook Khungurn CS 4621, Fall 2011

COMP3421. Introduction to 3D Graphics

COMP3421. Introduction to 3D Graphics

COMP3421. Vector geometry, Clipping

Computer Viewing Computer Graphics I, Fall 2008

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

Transforms 1 Christian Miller CS Fall 2011

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

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

Overview. By end of the week:

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

CS354 Computer Graphics Viewing and Modeling

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

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

Three-Dimensional Graphics III. Guoying Zhao 1 / 67

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

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

Fundamental Types of Viewing

Transforms. COMP 575/770 Spring 2013

3D Mathematics. Co-ordinate systems, 3D primitives and affine transformations

GEOMETRIC TRANSFORMATIONS AND VIEWING

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

CSC Graphics Programming. Budditha Hettige Department of Statistics and Computer Science

Computer Graphics Geometric Transformations

Geometric transformations assign a point to a point, so it is a point valued function of points. Geometric transformation may destroy the equation

Transformations. CSCI 420 Computer Graphics Lecture 4

Review of Thursday. xa + yb xc + yd

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

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

Vector Algebra Transformations. Lecture 4

Affine Transformations in 3D

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

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

Today. Today. Introduction. Matrices. Matrices. Computergrafik. Transformations & matrices Introduction Matrices

CS 4204 Computer Graphics

CS380: Computer Graphics Viewing Transformation. Sung-Eui Yoon ( 윤성의 ) Course URL:

CS 4204 Computer Graphics

CS293: Java Graphics with JOGL, Solutions

CT5510: Computer Graphics. Transformation BOCHANG MOON

CS 428: Fall Introduction to. OpenGL primer. Andrew Nealen, Rutgers, /13/2010 1

Viewing Transformation

Computer Graphics. Chapter 10 Three-Dimensional Viewing

An Introduction to 2D OpenGL

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

Fachhochschule Regensburg, Germany, February 15, 2017

S U N G - E U I YO O N, K A I S T R E N D E R I N G F R E E LY A VA I L A B L E O N T H E I N T E R N E T

CSC 470 Computer Graphics

Geometry: Outline. Projections. Orthographic Perspective

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

Math background. 2D Geometric Transformations. Implicit representations. Explicit representations. Read: CS 4620 Lecture 6

2D and 3D Transformations AUI Course Denbigh Starkey

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

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

COMS 4160: Problems on Transformations and OpenGL

JOGL: An OpenGL Based Graphics Domain for PtolemyII Yasemin Demir

Introduction to OpenGL Transformations, Viewing and Lighting. Ali Bigdelou

Specifying Complex Scenes

OpenGL Transformations

Computer Graphics: Geometric Transformations

CIS 636 Interactive Computer Graphics CIS 736 Computer Graphics Spring 2011

Interactive Computer Graphics. Hearn & Baker, chapter D transforms Hearn & Baker, chapter 5. Aliasing and Anti-Aliasing

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

2D/3D Geometric Transformations and Scene Graphs

Linear transformations Affine transformations Transformations in 3D. Graphics 2009/2010, period 1. Lecture 5: linear and affine transformations

Geometric Transformations

Computer Graphics 7: Viewing in 3-D

Transformations. Rotation and Scaling

Graphics and Interaction Transformation geometry and homogeneous coordinates

COMP30019 Graphics and Interaction Transformation geometry and homogeneous coordinates

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

Computer Graphics. Bing-Yu Chen National Taiwan University

Computer Graphics Hands-on

Graphics and Visualization

Order of Transformations

Computer Graphics. Chapter 7 2D Geometric Transformations

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

Lecture 9: Transformations. CITS3003 Graphics & Animation

CSE328 Fundamentals of Computer Graphics: Theory, Algorithms, and Applications

Institutionen för systemteknik

Lecture 4: Transforms. Computer Graphics CMU /15-662, Fall 2016

Advanced Computer Graphics (CS & SE )

Chapter 5-3D Camera & Optimizations, Rasterization

UNIT 2 2D TRANSFORMATIONS

GRAFIKA KOMPUTER. ~ M. Ali Fauzi

2D transformations: An introduction to the maths behind computer graphics

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

Android and OpenGL. Android Smartphone Programming. Matthias Keil. University of Freiburg

Computer Science 336 Fall 2017 Homework 2

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

Linear and Affine Transformations Coordinate Systems

Computer Graphics. Transformations. CSC 470 Computer Graphics 1

CS4620/5620. Professor: Kavita Bala. Cornell CS4620/5620 Fall 2012 Lecture Kavita Bala 1 (with previous instructors James/Marschner)

Computer Vision cmput 428/615

Object Representation Affine Transforms. Polygonal Representation. Polygonal Representation. Polygonal Representation of Objects

UNIT 4 GEOMETRIC OBJECTS AND TRANSFORMATIONS-1

Transcription:

Chapter 3 - Basic Mathematics for 3D Computer Graphics Three-Dimensional Geometric Transformations Affine Transformations and Homogeneous Coordinates OpenGL Matrix Logic

Translation Add a vector t Geometrical meaning: Shifting Inverse operation? Neutral operation? + y t t 2 t 3 + t + t 2 + t 3 z x 2

Uniform Scaling Multiply with a scalar s Geometrical meaning: Changing size of object How to scale objects which are not at the origin? ' s y ' s ' s ' s z x 3

Non-Uniform Scaling Multiply with three scalars One for each dimension Geometrical meaning? s 0 0 0 s 2 0 0 0 s 3 ' ' s ' s 2 ' s 3 y z x 4

Reflection Mirroring) Special case of scaling s s 2 s 3 < 0 Example: s, s, s 2 3 s 0 0 0 s 2 0 0 0 s 3 ' y ' s ' s 2 ' s 3 z x 5

Rotation about X Axis ) y x coordinate value remains constant Rotation takes place in y/z-plane 2D) How to compute new x and z coordinates from old ones? y z x z r z old y old sin z old r cos y old r z old r sin y old r cos 6

Rotation about X Axis 2) z z new r y old r cos z old r sin y y new cos +) y new r y new r cos +) r cosa cos r sin sin cos y old sin z old sin +) z new r z new r sin +) r sina cos + r cos sin sin y old + cos z old 7

Rotation about X Axis 3) 0 0 0 cos sin 0 sin cos ) ' ' cos ) sin ) sin ) + cos ) ' y Special cases, e.g. 90 degrees, 80 degrees? How to rotate about other axes? z x 8

Elementary rotations Combine to express arbitrary rotation 0 0 0 cos sin 0 sin cos ) ' ' cos ) sin ) sin ) + cos ) ' This is not always intuitive Order matters a lot) Likely source of bugs cos 0 sin 0 0 sin 0 cos cos sin 0 sin cos 0 0 0 ) ' ) ' ' ' cos ) + sin ) cos ) sin ) cos * ) sin ) sin ) + cos ) ' ' 9

Shearing along X Axis + m ' ' ' m 0 0 0 0 0 ' ' ' ' ' Only x coordinate values are modified Modification depends linearly on y coordinate value Areas and volume remain the same Generalization to other axes and arbitrary axis? z y x 0

Transformation of Coordinate Systems Applying a geometric transformation......to all points of a single object: Transforming the object within its world...to all points of all objects of the world : Transforming the reference coordinates Geometric transformations can be used to modify an object...place an object within a reference coordinate system...switch to different reference coordinates

Transformation from 3D to 2D: Projection Many different projections exist see later) Projection onto x/y plane: Forget the z coordinate value Other projections? Other viewpoints? y y 0 0 0 0 ' z x x 2

Chapter 3 - Basic Mathematics for 3D Computer Graphics Three-Dimensional Geometric Transformations Affine Transformations and Homogeneous Coordinates OpenGL Matrix Logic 3

Affine Transformation Mathematically: A transformation preserving collinearity Points lying on a line before are on a line after transformation Ratios of distances are preserved e.g. midpoint of a line segment) Parallel lines remain parallel Angles and lengths are not preserved Basic transformations: translation, rotation, scaling and shearing All combinations of these are affine transformations again Combination is associative, but not commutative General form of computation: New coordinate values are defined by linear function of the old values p' p' 2 p' 3 a a 2 a 3 a 2 a 22 a 23 a 3 a 32 a 33 + t t 2 t 3 Ap + t 4

Combining Multiple Transformations Rotation, scaling and shearing are expressed as matrices Associative, hence can all be combined into one matrix Many of these operations can also be combined into one matrix Translation is expressed by adding a vector Adding vectors is also associative Many translations can be combined into a single vector Combination of Translation with other operations? Series of matrix multiplications and vector additions, difficult to combine How about using a matrix multiplication to express translation?? 5

Homogeneous Coordinates Usage of a representation of coordinate-positions with an extra dimension Extra value is a scaling factor 3D position x, y, z) is represented by xh, yh, zh, h) such that x x h h, y y h h, z z h h Simple choice for scaling factor h is the value In special cases other values can be used 3D position x, y, z) is represented by x, y, z, ) 6

Translation Expressed in Homogeneous Coordinates p' p' 2 p' 3 + t t 2 t 3 + t + t 2 + t 3 p' p' 2 p' 3 0 0 t 0 0 t 2 0 0 t 3 0 0 0 + t + t 2 + t 3 7

Scaling Expressed in Homogeneous Coordinates p' p' 2 p' 3 s 0 0 0 s 2 0 0 0 s 3 s s 2 s 3 p' p' 2 p' 3 s 0 0 0 0 s 2 0 0 0 0 s 3 0 0 0 0 s s 2 s 3 8

Rotation Expressed in Homogeneous Coordinates p' p' 2 p' 3 0 0 0 cos' sin' 0 sin' cos' cos' ) sin' ) sin' ) + cos' ) p' p' 2 p' 3 0 0 0 0 cos' sin' 0 0 sin' cos' 0 0 0 0 cos' ) sin' ) sin' ) + cos' ) 9

Shearing Expressed in Homogeneous Coordinates p' p' 2 p' 3 m 0 0 0 0 0 + m ' z y x p' p' 2 p' 3 m 0 0 0 0 0 0 0 0 0 0 0 + m ' 20

Shearing: General Case p' p' 2 p' 3 m 2 m 3 0 m 2 m 23 0 m 3 m 32 0 0 0 0 + m 2 ' + m 3 ' + m 2 ' + m 23 ' + m 3 ' + m 32 ' 2

Computational Complexity for 3D Transformations p' p' 2 p' 3 a a 2 a 3 t a 2 a 22 a 23 t 2 a 3 a 32 a 33 t 3 0 0 0 a ' + a 2 ' + a 3 ' + t a 2 ' + a 22 ' + a 23 ' + t 2 a 3 ' + a 32 ' + a 33 ' + t 3 Operations needed: 9 multiplications 9 additions for an arbitrarily complex affine 3D transformation Runtime complexity improved by pre-calculation of composed transformation matrices Hardware implementations in graphics processors 22

Chapter 3 - Basic Mathematics for 3D Computer Graphics Three-Dimensional Geometric Transformations Affine Transformations and Homogeneous Coordinates OpenGL Matrix Logic 23

OpenGL Matrix Modes OpenGL maintains a storage of matrices for runtime computation of object properties Identical operations used for all matrices Selection of current matrix mode by void GL2.glMatrixMode int mode); Four matrix modes are supported: Modelview GL2.GL_MODELVIEW) Projection GL2.GL_PROJECTION) Texture Color Always switch to the right mode before applying a matrix operation 24

OpenGL Matrix Stacks Matrices are frequently re-used in graphics programs Copying a whole matrix is often supported by hardware OpenGL supports a stack of matrices, one per matrix mode Stack depth at least 2 in all implementations Stack depth for modelview al least 32 in all implementations Current matrix is top of the stack Initializing a matrix with identity matrix: glloadidentity) Stack operations: glpushmatrix) glpopmatrix) 25

OpenGL Affine Transformations Basic affine transformations are available as methods gltranslate*x, y, z) glrotate*alpha, x, y, z) glscale*sx, sy, sz) Other transformations can be created using general matrix operations glloadmatrix* ) glmultmatrix* ) Parameter is matrix, represented as 6-value array matrix as vector) All transformation matrices are right-multiplied onto current matrix 26

OpenGL Camera Viewpoint as Transformation Modelview matrix is a hybrid between model transformations, e.g. for transforming objects view transformation : The transformation resulting from the viewpoint of the camera Camera viewpoint specification in JOGL GLU utility function lookateyex, eyey, eyez, atx, aty, atz, upx, upy, upz) Results in an affine transformation translation/rotation) Effectively multiplies a matrix onto current modelview matrix 27

Investigating JOGL s Internal Modelview Matrix JOGL code to print out the current modelview matrix adapted from http://www.cs.rutgers.edu/~decarlo/428/jogl.html) public void printmvmatrixgl2 gl) { } double[] curmat new double[6]; // Get the current matrix on the MODELVIEW stack gl.glgetdoublevgl2.gl_modelview_matrix, curmat, 0); // Print out the contents of this matrix in OpenGL format for int row 0; row < 4; row++) for int col 0; col < 4; col++) System.out.format7.3fc, curmat[row+col*4], col3? '\n':' '); After glloadidentity):.000 0.000 0.000 0.000 0.000.000 0.000 0.000 0.000 0.000.000 0.000 0.000 0.000 0.000.000 28

View Matrix Generated by Camera Position ) gl.glloadidentity); glu.glulookat0, 0, 3, 0, 0, 0, 0,, 0); System.out.printlnView matrix lookat)); printmvmatrixgl); View matrix lookat).000 0.000 0.000 0.000 0.000.000 0.000 0.000 0.000 0.000.000-3.000 0.000 0.000 0.000.000 Which viewpoint is taken here? What is the default camera position in OpenGL? Which kind of affine transformation dows this result to? 29

View Matrix Generated by Camera Position 2) gl.glloadidentity); glu.glulookat0, 0, -3, 0, 0, 0, 0,, 0); System.out.printlnView matrix lookat)); printmvmatrixgl); View matrix lookat) -.000 0.000 0.000 0.000 0.000.000 0.000 0.000 0.000 0.000 -.000-3.000 0.000 0.000 0.000.000 Which camera viewpoint is taken here? Which kind of affine transformation does this result to? Where are the differences to the preceding case? 30

Simple Translation in JOGL gl.glloadidentity); glu.glulookat0, 0, 3, 0, 0, 0, 0,, 0); gl.gltranslated0.5, 0.5, -0.5); System.out.printlnAfter translate); printmvmatrixgl); After translate.000 0.000 0.000 0.500 0.000.000 0.000 0.500 0.000 0.000.000-3.500 0.000 0.000 0.000.000 What has happened here mathematically? 3

Multiplication of Modelview Matrices in JOGL 0 0 0 0 0 0 0 0-3 0 0 0 ' 0 0 0.5 0 0 0.5 0 0 0.5 0 0 0 0 0 0.5 0 0 0.5 0 0 3.5 0 0 0 Viewpoint matrix Translation matrix Pre-multiplication is right-multiplication of matrices Application order when applied to a point: A A 2 ) p A A 2 p) Transformations are applied for rendering in inverse order as computed in OpenGL program code Example: Translation is applied first, then viewpoint transformation 32

JOGL Example for Modelview Matrix Stack ) Assume: We want to display an object which was transformed by affine transformations We also want to display the coordinate axes of course in original non-transformed) view public void displayglautodrawable drawable) { GL2 gl drawable.getgl).getgl2);... GLU glu new GLU); // utility library object gl.glmatrixmodegl2.gl_modelview); gl.glloadidentity); glu.glulookat0, 0, 3, 0, 0, 0, 0,, 0); gl.glpushmatrix); gl.gltranslated0.5, 0.5, -0.5); gl.glrotated45, 0,, ); gl.glscaled0.5, 0.75,.0); gl.glbegingl2.gl_line_loop); // draw front side gl.glvertex3d-, -, );... 33

JOGL Example for Modelview Matrix Stack 2) } gl.glbegingl2.gl_line_loop); // draw... gl.glend); gl.glpopmatrix); gl.glcolor3d, 0, 0); //draw in red gl.glbegingl2.gl_lines); // show x axis in red gl.glvertex3d3, 0, 0); gl.glvertex3d-2, 0, 0); gl.glend);... 34

JOGL Example for Modelview Matrix Stack 3) We are drawing also the z axis: gl.glcolor3d0, 0, ); //draw in blue gl.glbegingl2.gl_lines); // show z axis in blue gl.glvertex3d0, 0, 3); gl.glvertex3d0, 0, -2); gl.glend); Why isn t there a blue line? How can we make it visible? 35