Welcome to CSc 830 Advanced Computer Graphics

Slides:



Advertisements
Similar presentations
Today Composing transformations 3D Transformations
Advertisements

Computer Graphics Lecture 4 Geometry & Transformations.
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
Chapter 4.1 Mathematical Concepts
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.
CS5500 Computer Graphics March 22, Angel: Interactive Computer Graphics 3E © Addison-Wesley 2002 Coordinate-Free Geometry When we learned simple.
CSCE 590E Spring 2007 Basic Math By Jijun Tang. Applied Trigonometry Trigonometric functions  Defined using right triangle  x y h.
3-D Geometry.
Transformations. 2 Angel: Interactive Computer Graphics 3E © Addison-Wesley 2002 Coordinate-Free Geometry When we learned simple geometry, most of us.
CS 450: Computer Graphics 2D TRANSFORMATIONS
Geometric Objects and Transformations Geometric Entities Representation vs. Reference System Geometric ADT (Abstract Data Types)
Mathematical Fundamentals
Computer Graphics: Programming, Problem Solving, and Visual Communication Steve Cunningham California State University Stanislaus and Grinnell College.
HCT.
COS 397 Computer Graphics Svetla Boytcheva AUBG, Spring 2013.
Graphics CSE 581 – Interactive Computer Graphics Mathematics for Computer Graphics CSE 581 – Roger Crawfis (slides developed from Korea University slides)
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.
Chapter 4.1 Mathematical Concepts
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.
CS 445 / 645 Introduction to Computer Graphics Lecture 3 Mathematical Primitives Introduction to Transformations Lecture 3 Mathematical Primitives Introduction.
Intro to 3D Models Angel Angel: Interactive Computer Graphics5E © Addison-Wesley
Mathematics for Graphics. 1 Objectives Introduce the elements of geometry  Scalars  Vectors  Points Develop mathematical operations among them in a.
Week 5 - Wednesday.  What did we talk about last time?  Project 2  Normal transforms  Euler angles  Quaternions.
CS559: Computer Graphics Lecture 9: Projection Li Zhang Spring 2008.
CS 376 Introduction to Computer Graphics 02 / 16 / 2007 Instructor: Michael Eckmann.
Jinxiang Chai CSCE441: Computer Graphics 3D Transformations 0.
Jinxiang Chai Composite Transformations and Forward Kinematics 0.
Geometric Objects and Transformation
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.
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.
CS 551 / 645: Introductory Computer Graphics Mathematical Foundations.
Geometric Transformations
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.
CS 445: Introduction to Computer Graphics David Luebke University of Virginia The Rendering Pipeline.
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.
Affine Geometry.
Computer Graphics Matrices
CSCE 552 Fall 2012 Math By Jijun Tang. Applied Trigonometry Trigonometric functions  Defined using right triangle  x y h.
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.
2/28/2016 CS 551 / 645: Introductory Computer Graphics Framebuffer Mathematical Foundations The Rendering Pipeline.
Jinxiang Chai CSCE441: Computer Graphics 3D Transformations 0.
Geometric Transformations Ceng 477 Introduction to Computer Graphics Computer Engineering METU.
David Luebke6/12/2016 CS 551 / 645: Introductory Computer Graphics David Luebke
Introduction; Mathematical Foundations CS 445/645 Introduction to Computer Graphics David Luebke, Spring 2003.
Modeling Transformation
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.
CA 302 Computer Graphics and Visual Programming
CSCE 441 Computer Graphics 3-D Viewing
Introduction to Computer Graphics CS 445 / 645
Lecture 03: Linear Algebra
CSE 411 Computer Graphics Lecture #2 Mathematical Foundations
CS 551 / 645: Introductory Computer Graphics
CSCE441: Computer Graphics 2D/3D Transformations
Presentation transcript:

Welcome to CSc 830 Advanced Computer Graphics By Ilmi Yoon Based on Lecture note from David Luebke & Pradondet Nilagupta

Where We’re Going Today’s lectures: Mathematical Foundations The graphics pipeline: the big picture Rigid-body transforms Homogeneous coordinates The viewing transform The projection transform

Mathematical Foundations FvD appendix gives good review I’ll give a brief, informal review of some of the mathematical tools we’ll employ Geometry (2D, 3D) Trigonometry Vector and affine spaces Points, vectors, and coordinates Dot and cross products Linear transforms and matrices

2D Geometry Know your high-school geometry: Total angle around a circle is 360° or 2π radians When two lines cross: Opposite angles are equivalent Angles along line sum to 180° Similar triangles: All corresponding angles are equivalent Corresponding pairs of sides have the same length ratio and are separated by equivalent angles Any corresponding pairs of sides have same length ratio

Trigonometry Sine: “opposite over hypotenuse” Cosine: “adjacent over hypotenuse” Tangent: “opposite over adjacent” Unit circle definitions: sin () = x cos () = y tan () = x/y Etc… (x, y)

3D Geometry To model, animate, and render 3D scenes, we must specify: Location Displacement from arbitrary locations Orientation We’ll look at two types of spaces: Vector spaces Affine spaces We will often be sloppy about the distinction

Vector Spaces Two types of elements: Supports two operations: Scalars (real numbers): a, b, g, d, … Vectors (n-tuples): u, v, w, … Supports two operations: Addition operation u + v, with: Identity 0 v + 0 = v Inverse - v + (-v) = 0 Scalar multiplication: Distributive rule: a(u + v) = a(u) + a(v) (a + b)u = au + bu

Vector Spaces A linear combination of vectors results in a new vector: v = a1v1 + a2v2 + … + anvn If the only set of scalars such that a1v1 + a2v2 + … + anvn = 0 is a1 = a2 = … = a3 = 0 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: A Familiar Example Our common notion of vectors in a 2D plane is (you guessed it) a vector space: Vectors are “arrows” rooted at the origin Scalar multiplication “streches” the arrow, changing its length (magnitude) but not its direction Addition uses the “trapezoid rule”: u+v y x u v

Vector Spaces: Basis Vectors Given a basis for a vector space: Each vector in the space is a unique linear combination of the basis vectors The coordinates of a vector are the scalars from this linear combination Best-known example: Cartesian coordinates Draw example on the board Note that a given vector v will have different coordinates for different bases

Vectors And Point We commonly use vectors to represent: Points in space (i.e., location) Displacements from point to point Direction (i.e., orientation) But we want points and directions to behave differently Ex: To translate something means to move it without changing its orientation Translation of a point = different point Translation of a direction = same direction

Affine Spaces To be more rigorous, we need an explicit notion of position Affine spaces add a third element to vector spaces: points (P, Q, R, …) Points support these operations Point-point subtraction: Q - P = v Result is a vector pointing from P to Q Vector-point addition: P + v = Q Result is a new point Note that the addition of two points is not defined Q v P

Affine Spaces Points, like vectors, can be expressed in coordinates The definition uses an affine combination Net effect is same: expressing a point in terms of a basis Thus the common practice of representing points as vectors with coordinates (see FvD) Analogous to equating points and integers in C Be careful to avoid nonsensical operations

Affine Lines: An Aside Parametric representation of a line with a direction vector d and a point P1 on the line: P(a) = Porigin + ad Restricting 0  a produces a ray Setting d to P - Q and restricting 0  a  1 produces a line segment between P and Q

Dot Product The dot product or, more generally, inner product of two vectors is a scalar: v1 • v2 = x1x2 + y1y2 + z1z2 (in 3D) Useful for many purposes Computing the length of a vector: length(v) = sqrt(v • v) Normalizing a vector, making it unit-length Computing the angle between two vectors: u • v = |u| |v| cos(θ) Checking two vectors for orthogonality Projecting one vector onto another v θ u

Cross Product The cross product or vector product of two vectors is a vector: The cross product of two vectors is orthogonal to both Right-hand rule dictates direction of cross product

Linear Transformations A linear transformation: Maps one vector to another Preserves 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

Matrices By convention, matrix element Mrc 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: 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 first Note: order of matrices matters! The identity matrix I has no effect in multiplication Some (not all) matrices have an inverse:

3-D Graphics: A Whirlwind Tour Transform Illuminate Clip Project Rasterize Model & Camera Parameters Rendering Pipeline Framebuffer Display

Model & Camera Parameters The Display You Know Transform Illuminate Clip Project Rasterize Model & Camera Parameters Rendering Pipeline Framebuffer Display

The Framebuffer You Know Transform Illuminate Clip Project Rasterize Model & Camera Parameters Rendering Pipeline Framebuffer Display

The Rendering Pipeline Why do we call it a pipeline? Transform Illuminate Clip Project Rasterize Model & Camera Parameters Rendering Pipeline Framebuffer Display

Model & Camera Parameters 2-D Rendering You Know Transform Illuminate Clip Project Rasterize Model & Camera Parameters Rendering Pipeline Framebuffer Display

The Rendering Pipeline: 3-D Transform Illuminate Clip Project Rasterize Model & Camera Parameters Rendering Pipeline Framebuffer Display

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

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

Rendering: Transformations So far, discussion has been in screen space But model is stored in model space (a.k.a. object space or world space) Three sets of geometric transformations: Modeling transforms Viewing transforms Projection transforms

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

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

Rendering: Transformations Projection transform Apply perspective foreshortening Distant = small: the pinhole camera model View coordinates  screen coordinates

Rendering: Transformations All these transformations involve shifting coordinate systems (i.e., basis sets) That’s what matrices do… Represent coordinates as vectors, transforms as matrices Multiply matrices = concatenate transforms!

Rendering: Transformations Homogeneous coordinates: represent coordinates in 3 dimensions with a 4-vector Denoted [x, y, z, w] Note that typically w = 1 in model coordinates To get 3-D coordinates, divide by w: [x’, y’, z’] = [x/w, y/w, z/w] Transformations are 4x4 matrices Why? To handle translation and projection

Rendering: Transformations OpenGL caveats: All modeling transforms and the viewing transform are concatenated into the modelview matrix A stack of modelview matrices is kept The projection transform is stored separately in the projection matrix See Chapter 3 of the OpenGL book

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

Rendering: Lighting Illuminating a scene: coloring pixels according to some approximation of lighting Global illumination: solves for lighting of the whole scene at once Local illumination: local approximation, typically lighting each polygon separately Interactive graphics (e.g., hardware) does only local illumination at run time

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

Rendering: Clipping Clipping a 3-D primitive returns its intersection with the view frustum: See Foley & van Dam section 19.1

Rendering: Clipping Clipping is tricky! In: 3 vertices Out: 6 vertices In: 1 polygon Out: 2 polygons Clip

The Rendering Pipeline: 3-D Transform Illuminate Clip Project Rasterize Model & Camera Parameters Rendering Pipeline Framebuffer Display

Modeling: The Basics Common interactive 3-D primitives: points, lines, polygons (i.e., triangles) Organized into objects Collection of primitives, other objects Associated matrix for transformations Instancing: using same geometry for multiple objects 4 wheels on a car, 2 arms on a robot

Modeling: The Scene Graph The scene graph captures transformations and object-object relationships in a DAG Objects in black; blue arrows indicate instancing and each have a matrix Robot Head Body Mouth Eye Leg Trunk Arm

Modeling: The Scene Graph Traverse the scene graph in depth-first order, concatenating transformations Maintain a matrix stack of transformations Robot Visited Head Body Unvisited Mouth Eye Leg Trunk Arm Matrix Stack Active Foot

Modeling: The Camera Finally: need a model of the virtual camera Can be very sophisticated Field of view, depth of field, distortion, chromatic aberration… Interactive graphics (OpenGL): Pinhole camera model Field of view Aspect ratio Near & far clipping planes Camera pose: position & orientation

Modeling: The Camera These parameters are encapsulated in a projection matrix Homogeneous coordinates  4x4 matrix! See OpenGL Appendix F for the matrix The projection matrix premultiplies the viewing matrix, which premultiplies the modeling matrices Actually, OpenGL lumps viewing and modeling transforms into modelview matrix

Rigid-Body Transforms Goal: object coordinatesworld coordinates Idea: use only transformations that preserve the shape of the object Rigid-body or Euclidean transforms Includes rotation, translation, and scale To reiterate: we will represent points as column vectors:

Vectors and Matrices Vector algebra operations can be expressed in this matrix form Dot product: Cross product: Note: use right-hand rule!

Translations For convenience we usually describe objects in relation to their own coordinate system Solar system example We can translate or move points to a new position by adding offsets to their coordinates: Note that this translates all points uniformly

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

2-D Rotations Rotations in 2-D are easy: 3-D is more complicated Need to specify an axis of rotation Common pedagogy: express rotation about this axis as the composition of canonical rotations Canonical rotations: rotation about X-axis, Y-axis, Z-axis

3-D Rotations Basic idea: Objections: Using rotations about X, Y, Z axes, rotate model until desired axis of rotation coincides with Z-axis Perform rotation in the X-Y plane (i.e., about Z-axis) Reverse the initial rotations to get back into the initial frame of reference Objections: Difficult & error prone Ambiguous: several combinations about the canonical axis give the same result

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

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

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

2-D Rotation This is easy to capture in matrix form: 3-D is more complicated Need to specify an axis of rotation Simple cases: rotation about X, Y, Z axes

3-D Rotation What does the 3-D rotation matrix look like for a rotation about the Z-axis? Build it coordinate-by-coordinate

3-D Rotation What does the 3-D rotation matrix look like for a rotation about the Y-axis? Build it coordinate-by-coordinate

3-D Rotation What does the 3-D rotation matrix look like for a rotation about the X-axis? Build it coordinate-by-coordinate

3-D Rotation General rotations in 3-D require rotating about an arbitrary axis of rotation Deriving the rotation matrix for such a rotation directly is difficult But possible, see McMillan’s lectures Standard approach: express general rotation as composition of canonical rotations Rotations about X, Y, Z

Composing Canonical Rotations Goal: rotate about arbitrary vector A by  Idea: we know how to rotate about X,Y,Z So, rotate about Y by  until A lies in the YZ plane, Then rotate about X by  until A coincides with +Z, Then rotate about Z by  Then reverse the rotation about X (by -) Then reverse the rotation about Y (by -)

Composing Canonical Rotations First: rotating about Y by  until A lies in YZ Draw it… How exactly do we calculate ? Project A onto XZ plane Find angle  to X:  = -(90° - ) =  - 90 ° Second: rotating about X by  until A lies on Z How do we calculate ?

Composing Canonical Rotations Why are we slogging through all this tedium? A: Because you’ll have to do it on the test

3-D Rotation Matrices So an arbitrary rotation about A composites several canonical rotations together We can express each rotation as a matrix Compositing transforms == multiplying matrices Thus we can express the final rotation as the product of canonical rotation matrices Thus we can express the final rotation with a single matrix!

Compositing Matrices So we have the following matrices: p: The point to be rotated about A by  Ry : Rotate about Y by  Rx  : Rotate about X by  Rz : Rotate about Z by  Rx  -1: Undo rotation about X by  Ry-1 : Undo rotation about Y by  In what order should we multiply them?

Compositing Matrices 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. So in our case: p’ = Ry-1 Rx  -1 Rz Rx  Ry p

Rotation Matrices Notice these two matrices: Rx  : Rotate about X by  Rx  -1: Undo rotation about X by  How can we calculate Rx  -1?

Rotation Matrices Notice these two matrices: Rx  : Rotate about X by  Rx  -1: Undo rotation about X by  How can we calculate Rx  -1? Obvious answer: calculate Rx (-) Clever answer: exploit fact that rotation matrices are orthonormal

Rotation Matrices Notice these two matrices: Rx  : Rotate about X by  Rx  -1: Undo rotation about X by  How can we calculate Rx  -1? Obvious answer: calculate Rx (-) Clever answer: exploit fact that rotation matrices are orthonormal What is an orthonormal matrix? What property are we talking about?

Rotation Matrices Orthonormal matrix: orthogonal (columns/rows linearly independent) Columns/rows sum to 1 The inverse of an orthogonal matrix is just its transpose:

Translation Matrices? We can composite scale matrices just as we did rotation matrices But how to represent translation as a matrix? Answer: with homogeneous coordinates

Homogeneous Coordinates Homogeneous coordinates: represent coordinates in 3 dimensions with a 4-vector (Note that typically w = 1 in object coordinates)

Homogeneous Coordinates Homogeneous coordinates seem unintuitive, but they make graphics operations much easier Our transformation matrices are now 4x4:

Homogeneous Coordinates Homogeneous coordinates seem unintuitive, but they make graphics operations much easier Our transformation matrices are now 4x4:

Homogeneous Coordinates Homogeneous coordinates seem unintuitive, but they make graphics operations much easier Our transformation matrices are now 4x4:

Homogeneous Coordinates Homogeneous coordinates seem unintuitive, but they make graphics operations much easier Our transformation matrices are now 4x4:

Homogeneous Coordinates How can we represent translation as a 4x4 matrix? A: Using the rightmost column: