CS 445 / 645 Introduction to Computer Graphics Lecture 3 Mathematical Primitives Introduction to Transformations Lecture 3 Mathematical Primitives Introduction.

Slides:



Advertisements
Similar presentations
Today Composing transformations 3D Transformations
Advertisements

CS 691 Computational Photography Instructor: Gianfranco Doretto Image Warping.
UBI 516 Advanced Computer Graphics
Informationsteknologi Wednesday, November 7, 2007Computer Graphics - Class 51 Today’s class Geometric objects and transformations.
MAE152 Computer Graphicsfor Scientists and Engineers Revision of Matrices Relevance to Graphics.
Transformations II Week 2, Wed Jan 17
Image Warping : Computational Photography Alexei Efros, CMU, Fall 2006 Some slides from Steve Seitz
2/7/2001Hofstra University – CSC290B1 Review: Math (Ch 4)
Chapter 4.1 Mathematical Concepts. 2 Applied Trigonometry Trigonometric functions Defined using right triangle  x y h.
Welcome to CSc 830 Advanced Computer Graphics
Image Warping : Computational Photography Alexei Efros, CMU, Fall 2008 Some slides from Steve Seitz
CSCE 590E Spring 2007 Basic Math By Jijun Tang. Applied Trigonometry Trigonometric functions  Defined using right triangle  x y h.
IAT 3551 Computer Graphics Overview Color Displays Drawing Pipeline.
Representation CS4395: Computer Graphics 1 Mohan Sridharan Based on slides created by Edward Angel.
Introduction to Computer Graphics CS 445 / 645 Lecture 5 Transformations Transformations M.C. Escher – Smaller and Smaller (1956)
3D Graphics Goal: To produce 2D images of a mathematically described 3D environment Issues: –Describing the environment: Modeling (mostly later) –Computing.
CS 450: Computer Graphics 2D TRANSFORMATIONS
10/5/04© University of Wisconsin, CS559 Fall 2004 Last Time Compositing Painterly Rendering Intro to 3D Graphics Homework 3 due Oct 12 in class.
2IV60 Computer Graphics Basic Math for CG
HCT.
Transformations Aaron Bloomfield CS 445: Introduction to Graphics
Basics of Rendering Pipeline Based Rendering –Objects in the scene are rendered in a sequence of steps that form the Rendering Pipeline. Ray-Tracing –A.
CS 480/680 Computer Graphics Representation Dr. Frederick C Harris, Jr. Fall 2012.
Geometric Transformation. So far…. We have been discussing the basic elements of geometric programming. We have discussed points, vectors and their operations.
Computer Graphics in Java1 Objects and Viewers Two basic entities (one object seen from two different positions) :
Transformations Dr. Amy Zhang.
Mathematical Foundations Sections A-1 to A-5 Some of the material in these slides may have been adapted from university of Virginia, MIT and Åbo Akademi.
Warping CSE 590 Computational Photography Tamara Berg.
Computer Graphics Raster Devices Transformations Areg Sarkissian.
Intro to 3D Models Angel Angel: Interactive Computer Graphics5E © Addison-Wesley
Foundations of Computer Graphics (Fall 2012) CS 184, Lectures 13,14: Reviews Transforms, OpenGL
Jinxiang Chai Composite Transformations and Forward Kinematics 0.
Geometric Objects and Transformation
10/3/02 (c) 2002 University of Wisconsin, CS 559 Last Time 2D Coordinate systems and transformations.
The Rendering Pipeline CS 445/645 Introduction to Computer Graphics David Luebke, Spring 2003.
16/5/ :47 UML Computer Graphics Conceptual Model Application Model Application Program Graphics System Output Devices Input Devices API Function.
Computer Graphics Chapter 6 Andreas Savva. 2 Interactive Graphics Graphics provides one of the most natural means of communicating with a computer. Interactive.
David Luebke11/14/2015 CS 551 / 645: Introductory Computer Graphics David Luebke
C O M P U T E R G R A P H I C S Guoying Zhao 1 / 52 C O M P U T E R G R A P H I C S Guoying Zhao 1 / 52 Computer Graphics Three-Dimensional Graphics I.
Background Mathematics Aaron Bloomfield CS 445: Introduction to Graphics Fall 2006.
CS559: Computer Graphics Lecture 8: 3D Transforms Li Zhang Spring 2008 Most Slides from Stephen Chenney.
University of Texas at Austin CS384G - Computer Graphics Fall 2008 Don Fussell Affine Transformations.
Jens Krüger & Polina Kondratieva – Computer Graphics and Visualization Group computer graphics & visualization 3D Rendering Praktikum: Shader Gallery The.
CS 551 / 645: Introductory Computer Graphics Mathematical Foundations.
CSE Real Time Rendering Week 5. Slides(Some) Courtesy – E. Angel and D. Shreiner.
Review on Graphics Basics. Outline Polygon rendering pipeline Affine transformations Projective transformations Lighting and shading From vertices to.
Transformations CS 445/645 Introduction to Computer Graphics David Luebke, Spring 2003.
David Luebke1/10/2016 CS 551 / 645: Introductory Computer Graphics David Luebke
3D Transformation A 3D point (x,y,z) – x,y, and z coordinates
Transformations: Projection CS 445/645 Introduction to Computer Graphics David Luebke, Spring 2003.
Computer Graphics Matrices
1 Representation. 2 Objectives Introduce concepts such as dimension and basis Introduce coordinate systems for representing vectors spaces and frames.
David Luebke2/16/2016 CS 551 / 645: Introductory Computer Graphics Mathematical Foundations The Rendering Pipeline.
Rendering Pipeline and Graphics Hardware Aaron Bloomfield CS 445: Introduction to Graphics Fall 2006.
CS559: Computer Graphics Lecture 9: 3D Transformation and Projection Li Zhang Spring 2010 Most slides borrowed from Yungyu ChuangYungyu Chuang.
Recap from Monday DCT and JPEG Point Processing Histogram Normalization Questions: JPEG compression levels Gamma correction.
2/28/2016 CS 551 / 645: Introductory Computer Graphics Framebuffer Mathematical Foundations The Rendering Pipeline.
CS 551 / 645: Introductory Computer Graphics Viewing Transforms.
4. Affine transformations. Reading Required:  Watt, Section 1.1. Further reading:  Foley, et al, Chapter  David F. Rogers and J. Alan Adams,
David Luebke6/12/2016 CS 551 / 645: Introductory Computer Graphics David Luebke
Outline 3D Viewing Required readings: HB 10-1 to 10-10
Transformations. Modeling Transformations  Specify transformations for objects  Allows definitions of objects in own coordinate systems  Allows use.
3D Ojbects: Transformations and Modeling. Matrix Operations Matrices have dimensions: Vectors can be thought of as matrices: v=[2,3,4,1] is a 1x4 matrix.
Transformations University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2016 Tamara Munzner.
Math Fundamentals Maths revisit.
3D Transformations Source & Courtesy: University of Wisconsin,
Introduction to Computer Graphics CS 445 / 645
Modeling 101 For the moment assume that all geometry consists of points, lines and faces Line: A segment between two endpoints Face: A planar area bounded.
(c) 2002 University of Wisconsin, CS 559
(c) University of Wisconsin, CS559
Presentation transcript:

CS 445 / 645 Introduction to Computer Graphics Lecture 3 Mathematical Primitives Introduction to Transformations Lecture 3 Mathematical Primitives Introduction to Transformations

Show Your Gang Colors Use hand to identify handedness Point thumb, index finger, and middle finger in orthogonal directionsPoint thumb, index finger, and middle finger in orthogonal directions –Thumb = x-axis –Index = y-axis –Middle = z-axis Left and right hands correspond to left and right hand coordinate systemsLeft and right hands correspond to left and right hand coordinate systems Use hand to identify handedness Point thumb, index finger, and middle finger in orthogonal directionsPoint thumb, index finger, and middle finger in orthogonal directions –Thumb = x-axis –Index = y-axis –Middle = z-axis Left and right hands correspond to left and right hand coordinate systemsLeft and right hands correspond to left and right hand coordinate systems

Triangle Arithmetic Consider a triangle, (a, b, c) a,b,c = (x,y,z) tuplesa,b,c = (x,y,z) tuples Surface area = s a = ½ * ||(b –a) X (c-a)|| Unit normal = (1/2s a ) * (b-a) X (c-a) Consider a triangle, (a, b, c) a,b,c = (x,y,z) tuplesa,b,c = (x,y,z) tuples Surface area = s a = ½ * ||(b –a) X (c-a)|| Unit normal = (1/2s a ) * (b-a) X (c-a) a c b

Vector Spaces A linear combination of vectors results in a new vector: v =  1 v 1 +  2 v 2 + … +  n v n If the only set of scalars such that  1 v 1 +  2 v 2 + … +  n v n = 0  1 v 1 +  2 v 2 + … +  n v n = 0 is  1 =  2 = … =  3 = 0 is  1 =  2 = … =  3 = 0 then we say the vectors are linearly independent then we say the vectors are linearly independent The dimension of a space is the greatest number of linearly independent vectors possible in a vector set For a vector space of dimension n, any set of n linearly independent vectors form a basis A linear combination of vectors results in a new vector: v =  1 v 1 +  2 v 2 + … +  n v n If the only set of scalars such that  1 v 1 +  2 v 2 + … +  n v n = 0  1 v 1 +  2 v 2 + … +  n v n = 0 is  1 =  2 = … =  3 = 0 is  1 =  2 = … =  3 = 0 then we say the vectors are linearly independent then we say the vectors are linearly independent The dimension of a space is the greatest number of linearly independent vectors possible in a vector set For a vector space of dimension n, any set of n linearly independent vectors form a basis

Vector Spaces: Basis Vectors Given a basis for a vector space: Each vector in the space is a unique linear combination of the basis vectorsEach vector in the space is a unique linear combination of the basis vectors The coordinates of a vector are the scalars from this linear combinationThe coordinates of a vector are the scalars from this linear combination If basis vectors are orthogonal and unit length:If basis vectors are orthogonal and unit length: –Vectors comprise orthonormal basis Best-known example: Cartesian coordinatesBest-known example: Cartesian coordinates Note that a given vector v will have different coordinates for different basesNote that a given vector v will have different coordinates for different bases Given a basis for a vector space: Each vector in the space is a unique linear combination of the basis vectorsEach vector in the space is a unique linear combination of the basis vectors The coordinates of a vector are the scalars from this linear combinationThe coordinates of a vector are the scalars from this linear combination If basis vectors are orthogonal and unit length:If basis vectors are orthogonal and unit length: –Vectors comprise orthonormal basis Best-known example: Cartesian coordinatesBest-known example: Cartesian coordinates Note that a given vector v will have different coordinates for different basesNote that a given vector v will have different coordinates for different bases

Matrices By convention, matrix element M rc is located at row r and column c: By (OpenGL) convention, vectors are columns

Matrices Matrix-vector multiplication applies a linear transformation to a vector: Why do we call this a linear transformation?Why do we call this a linear transformation? Recall how to do matrix multiplication? Matrix-vector multiplication applies a linear transformation to a vector: Why do we call this a linear transformation?Why do we call this a linear transformation? Recall how to do matrix multiplication?

Matrix Transformations A sequence or composition of linear transformations corresponds to the product of the corresponding matrices Note: the matrices to the right affect vector firstNote: the matrices to the right affect vector first Note: order of matrices matters!Note: order of matrices matters! The identity matrix I has no effect in multiplication Some (not all) matrices have an inverse: A sequence or composition of linear transformations corresponds to the product of the corresponding matrices Note: the matrices to the right affect vector firstNote: the matrices to the right affect vector first Note: order of matrices matters!Note: order of matrices matters! The identity matrix I has no effect in multiplication Some (not all) matrices have an inverse:

Matrix Transformations A linear transformation: Maps one vector to anotherMaps one vector to another Preserves linear combinationsPreserves linear combinations Thus behavior of linear transformation is completely determined by what it does to a basis Turns out any linear transform can be represented by a matrix A linear transformation: Maps one vector to anotherMaps one vector to another Preserves linear combinationsPreserves linear combinations Thus behavior of linear transformation is completely determined by what it does to a basis Turns out any linear transform can be represented by a matrix

Matrix Transformations We hypothesize that all necessary linear transformations can be accomplished with matrix multiplicationWe hypothesize that all necessary linear transformations can be accomplished with matrix multiplication Let’s look at a fewLet’s look at a few –Scaling –Rotation –Translation? We hypothesize that all necessary linear transformations can be accomplished with matrix multiplicationWe hypothesize that all necessary linear transformations can be accomplished with matrix multiplication Let’s look at a fewLet’s look at a few –Scaling –Rotation –Translation?

Scaling Scaling a coordinate means multiplying each of its components by a scalar Uniform scaling means this scalar is the same for all components: Scaling a coordinate means multiplying each of its components by a scalar Uniform scaling means this scalar is the same for all components:  2 2

Non-uniform scaling: different scalars per component: How can we represent this in matrix form? Non-uniform scaling: different scalars per component: How can we represent this in matrix form? Scaling X  2, Y  0.5

Scaling Scaling operation: Or, in matrix form: Scaling operation: Or, in matrix form: scaling matrix

2-D Rotation  (x, y) (x’, y’) x’ = x cos(  ) - y sin(  ) y’ = x sin(  ) + y cos(  )

2-D Rotation x = r cos (  ) y = r sin (  ) x’ = r cos (  +  ) y’ = r sin (  +  ) Trig Identity… x’ = r cos(  ) cos(  ) – r sin(  ) sin(  ) y’ = r sin(  ) sin(  ) + r cos(  ) cos(  ) Substitute… x’ = x cos(  ) - y sin(  ) y’ = x sin(  ) + y cos(  )  (x, y) (x’, y’) 

2-D Rotation This is easy to capture in matrix form: Even though sin(  ) and cos(  ) are nonlinear functions of , x’ is a linear combination of x and yx’ is a linear combination of x and y y’ is a linear combination of x and yy’ is a linear combination of x and y This is easy to capture in matrix form: Even though sin(  ) and cos(  ) are nonlinear functions of , x’ is a linear combination of x and yx’ is a linear combination of x and y y’ is a linear combination of x and yy’ is a linear combination of x and y

Translation What can you do with a 2x2 matrix transformation? Nothing corresponds to translation… What can you do with a 2x2 matrix transformation? Nothing corresponds to translation…

Homogeneous Coordinates Homogeneous coordinates represent coordinates in 2 dimensions with a 3-vectorrepresent coordinates in 2 dimensions with a 3-vector Homogeneous coordinates represent coordinates in 2 dimensions with a 3-vectorrepresent coordinates in 2 dimensions with a 3-vector Homogeneous coordinates seem unintuitive, but they make graphics operations much easier

Homogeneous Coordinates Our transformation matrices are now 3x3:

Homogeneous Coordinates Q: How can we represent translation as a 3x3 matrix? A: Using the rightmost column: Q: How can we represent translation as a 3x3 matrix? A: Using the rightmost column:

Translation Example of translation T x = 2 T y = 1

Total Picture Think about what happens with manipulating transformation matrix a, e = negative?a, e = negative? Changing d and e?Changing d and e? Changing i != 1?Changing i != 1? Think about what happens with manipulating transformation matrix a, e = negative?a, e = negative? Changing d and e?Changing d and e? Changing i != 1?Changing i != 1?

Composing Transformations What if we want to scale and rotate and translate? We can execute transformations one after the otherWe can execute transformations one after the other Ex: Rotate line segment by 45 degrees about endpoint aEx: Rotate line segment by 45 degrees about endpoint a What if we want to scale and rotate and translate? We can execute transformations one after the otherWe can execute transformations one after the other Ex: Rotate line segment by 45 degrees about endpoint aEx: Rotate line segment by 45 degrees about endpoint a aa

Multiplication Order – Wrong Way Our line is defined by two endpoints Applying a rotation of 45 degrees, R(45), affects both pointsApplying a rotation of 45 degrees, R(45), affects both points We could try to translate both endpoints to return endpoint a to its original position, but by how much?We could try to translate both endpoints to return endpoint a to its original position, but by how much? Our line is defined by two endpoints Applying a rotation of 45 degrees, R(45), affects both pointsApplying a rotation of 45 degrees, R(45), affects both points We could try to translate both endpoints to return endpoint a to its original position, but by how much?We could try to translate both endpoints to return endpoint a to its original position, but by how much? T(-3), R(45), T(3) WrongCorrect T(-3) R(45) T(3) R(45) a a

Multuplication Order - Correct Isolate endpoint a from rotation effects First translate line so a is at origin: T (-3)First translate line so a is at origin: T (-3) Then rotate line 45 degrees: R(45)Then rotate line 45 degrees: R(45) Then translate back so a is where it was: T(3)Then translate back so a is where it was: T(3) Isolate endpoint a from rotation effects First translate line so a is at origin: T (-3)First translate line so a is at origin: T (-3) Then rotate line 45 degrees: R(45)Then rotate line 45 degrees: R(45) Then translate back so a is where it was: T(3)Then translate back so a is where it was: T(3) a a a a

Will this sequence of operations work? Result of first multiply with vector Will this sequence of operations work? Result of first multiply with vector Compositing Matrices

Order of multiplication matters Short answer: the transformations, in order, are written from right to left In other words, the first matrix to affect the vector goes next to the vector, the second next to the first, etc.In other words, the first matrix to affect the vector goes next to the vector, the second next to the first, etc. Order of multiplication matters Short answer: the transformations, in order, are written from right to left In other words, the first matrix to affect the vector goes next to the vector, the second next to the first, etc.In other words, the first matrix to affect the vector goes next to the vector, the second next to the first, etc.

Compositing Matrices After correctly ordering the matrices Multiply matrices together What results is one matrix – store it! Multiply this matrix by the vector of each vertex All vertices easily trasformed with one matrix multiply After correctly ordering the matrices Multiply matrices together What results is one matrix – store it! Multiply this matrix by the vector of each vertex All vertices easily trasformed with one matrix multiply

Frame Buffers A frame buffer may be thought of as computer memory organized as a two-dimensional array with each (x,y) addressable location corresponding to one pixel. Bit Planes or Bit Depth is the number of bits corresponding to each pixel. A typical frame buffer resolution might be 640 x 480 x x 1024 x x 1024 x 24 A frame buffer may be thought of as computer memory organized as a two-dimensional array with each (x,y) addressable location corresponding to one pixel. Bit Planes or Bit Depth is the number of bits corresponding to each pixel. A typical frame buffer resolution might be 640 x 480 x x 1024 x x 1024 x 24

1-Bit Memory, Monochrome Display (Bitmap Display)

3-Bit Color Display

True Color Display Red Blue bitplanes, 8 bits per color gun = 16,777,216

Color Map Look-Up Tables Extends the number of colors that can be displayed by a given number of bit-planes RG B RED GREEN BLUE Pixel displayed at x', y' Pixel in bit map at x', y' 0 x 0 y x max y Frame bufferLook-up tableDisplay

Pseudo color 2 8 x 24 Color Map LUT

Rendering 3D Scenes Transform Illuminate Transform Clip Project Rasterize Model & Camera Parameters Rendering Pipeline FramebufferDisplay

The Rendering Pipeline Transform Illuminate Transform Clip Project Rasterize Model & Camera Parameters Rendering Pipeline FramebufferDisplay

Rendering: Transformations We’ve learned about transformations But they are used in three ways: Modeling transformsModeling transforms Viewing transforms (Move the camera)Viewing transforms (Move the camera) Projection transforms (Change the type of camera)Projection transforms (Change the type of camera) We’ve learned about transformations But they are used in three ways: Modeling transformsModeling transforms Viewing transforms (Move the camera)Viewing transforms (Move the camera) Projection transforms (Change the type of camera)Projection transforms (Change the type of camera)

The Rendering Pipeline: 3-D Result: All vertices of scene in shared 3-D “world” coordinate system All vertices of scene in shared 3-D “world” coordinate system Vertices shaded according to lighting model Vertices shaded according to lighting model Scene vertices in 3-D “view” or “camera” coordinate system Scene vertices in 3-D “view” or “camera” coordinate system Exactly those vertices & portions of polygons in view frustum Exactly those vertices & portions of polygons in view frustum 2-D screen coordinates of clipped vertices 2-D screen coordinates of clipped vertices Scene graph Object geometry Lighting Calculations Clipping Modeling Transforms Viewing Transform Projection Transform

The Rendering Pipeline: 3-D Modeling Transforms Scene graph Object geometry Lighting Calculations Viewing Transform Clipping Projection Transform Result: All vertices of scene in shared 3-D “world” coordinate system All vertices of scene in shared 3-D “world” coordinate system

Rendering: Transformations Modeling transforms Size, place, scale, and rotate objects and parts of the model w.r.t. each otherSize, place, scale, and rotate objects and parts of the model w.r.t. each other Object coordinates -> world coordinatesObject coordinates -> world coordinates Modeling transforms Size, place, scale, and rotate objects and parts of the model w.r.t. each otherSize, place, scale, and rotate objects and parts of the model w.r.t. each other Object coordinates -> world coordinatesObject coordinates -> world coordinates Z X Y X Z Y

Modeling Transforms Scene graph Object geometry Lighting Calculations Viewing Transform Clipping Projection Transform Result: Scene vertices in 3-D “view” or “camera” coordinate system Scene vertices in 3-D “view” or “camera” coordinate system The Rendering Pipeline: 3-D

Rendering: Transformations Viewing transform Rotate & translate the world to lie directly in front of the cameraRotate & translate the world to lie directly in front of the camera –Typically place camera at origin –Typically looking down -Z axis World coordinates  view coordinatesWorld coordinates  view coordinates Viewing transform Rotate & translate the world to lie directly in front of the cameraRotate & translate the world to lie directly in front of the camera –Typically place camera at origin –Typically looking down -Z axis World coordinates  view coordinatesWorld coordinates  view coordinates

Modeling Transforms Scene graph Object geometry Lighting Calculations Viewing Transform Clipping Projection Transform Result: 2-D screen coordinates of clipped vertices 2-D screen coordinates of clipped vertices The Rendering Pipeline: 3-D

Rendering: Transformations Projection transform Apply perspective foreshorteningApply perspective foreshortening –Distant = small: the pinhole camera model View coordinates  screen coordinatesView coordinates  screen coordinates Projection transform Apply perspective foreshorteningApply perspective foreshortening –Distant = small: the pinhole camera model View coordinates  screen coordinatesView coordinates  screen coordinates

Perspective Camera Orthographic Camera Perspective Camera Orthographic Camera Rendering: Transformations

Introducing OpenGL mid-level, device-independent, portable graphics subroutine package developed primarily by SGI 2D/3D graphics, lower-level primitives (polygons) does not include low-level I/O management basis for higher-level libraries/toolkits mid-level, device-independent, portable graphics subroutine package developed primarily by SGI 2D/3D graphics, lower-level primitives (polygons) does not include low-level I/O management basis for higher-level libraries/toolkits

Introducing OpenGL Recall the rendering pipeline: Transform geometry (object  world, world  eye)Transform geometry (object  world, world  eye) Apply perspective projection (eye  screen)Apply perspective projection (eye  screen) Clip to the view frustumClip to the view frustum Perform visible-surface processing (Z-buffer)Perform visible-surface processing (Z-buffer) Calculate surface lightingCalculate surface lighting Implementing all this is a lot of work OpenGL provides a standard implementation So why study the basics?So why study the basics? Recall the rendering pipeline: Transform geometry (object  world, world  eye)Transform geometry (object  world, world  eye) Apply perspective projection (eye  screen)Apply perspective projection (eye  screen) Clip to the view frustumClip to the view frustum Perform visible-surface processing (Z-buffer)Perform visible-surface processing (Z-buffer) Calculate surface lightingCalculate surface lighting Implementing all this is a lot of work OpenGL provides a standard implementation So why study the basics?So why study the basics?