Hank Childs, University of Oregon Oct. 22 nd, 2014 CIS 441/541: Introduction to Computer Graphics Lecture 7: Arbitrary Camera Positions.

Slides:



Advertisements
Similar presentations
Today Composing transformations 3D Transformations
Advertisements

COMPUTER GRAPHICS 2D TRANSFORMATIONS.
Transformations We want to be able to make changes to the image larger/smaller rotate move This can be efficiently achieved through mathematical operations.
Geometric Transformations
Hank Childs, University of Oregon Oct. 24th, 2014 CIS 441/541: Introduction to Computer Graphics Lecture 8: Arbitrary Camera Positions.
Hank Childs, University of Oregon Oct. 17 th, 2014 CIS 441/541: Introduction to Computer Graphics Lecture 6: Lighting Review, Arbitrary Camera Position.
Hank Childs, University of Oregon November 15 th, 2013 Volume Rendering, Part 2.
8. 2D Coordinate Operations Assoc.Prof.Dr. Ahmet Zafer Şenalp Mechanical Engineering Department Gebze.
Lecture 4: 3D Rendering Pipeline (I) Prof. Hsien-Hsin Sean Lee School of Electrical and Computer Engineering Georgia Institute of Technology.
CS 4731: Computer Graphics Lecture 7: Introduction to Transforms, 2D transforms Emmanuel Agu.
Graphics-1 Gentle Introduction to Computer Graphics (2) Based on: –David Brogan’s “Introduction to Computer Graphics” Course Slides, University of Virginia.
CS5500 Computer Graphics March 22, Angel: Interactive Computer Graphics 3E © Addison-Wesley 2002 Coordinate-Free Geometry When we learned simple.
1 CSCE 441 Computer Graphics: 2D Transformations Jinxiang Chai.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Representation Ed Angel Professor of Computer Science, Electrical and Computer Engineering,
IAT 3551 Computer Graphics Overview Color Displays Drawing Pipeline.
Computer Graphics (Fall 2008) COMS 4160, Lecture 3: Transformations 1
Representation CS4395: Computer Graphics 1 Mohan Sridharan Based on slides created by Edward Angel.
Computer Graphics (Fall 2004) COMS 4160, Lecture 3: Transformations 1
CS 4731: Computer Graphics Lecture 8: 3D Affine transforms Emmanuel Agu.
2D Transformations Unit - 3. Why Transformations? In graphics, once we have an object described, transformations are used to move that object, scale it.
Foundations of Computer Graphics (Fall 2012) CS 184, Lecture 2: Review of Basic Math
COMP 261 Lecture 14 3D Graphics 2 of 2. Doing better than 3x3? Translation, scaling, rotation are different. Awkward to combine them. Use homogeneous.
University of Illinois at Chicago Electronic Visualization Laboratory (EVL) CS 426 Intro to 3D Computer Graphics © 2003, 2004, 2005 Jason Leigh Electronic.
CS 480/680 Computer Graphics Representation Dr. Frederick C Harris, Jr. Fall 2012.
Technology and Historical Overview. Introduction to 3d Computer Graphics  3D computer graphics is the science, study, and method of projecting a mathematical.
Transformations Dr. Amy Zhang.
Lecture Notes: Computer Graphics.
ICS201 Lecture 12 : Gentle Introduction to Computer Graphics II King Fahd University of Petroleum & Minerals College of Computer Science & Engineering.
Hank Childs, University of Oregon
Hank Childs, University of Oregon Nov. 14th, 2014 CIS 441/541: Introduction to Computer Graphics Lecture 13: CW/CCW, constructing geometry.
Hank Childs, University of Oregon Oct. 31st, 2014 CIS 441/541: Introduction to Computer Graphics Lecture 10: Textures.
Hank Childs, University of Oregon October 3, 2014 CIS 441/541: Intro to Computer Graphics Lecture 2: The Scanline Algorithm.
Computer Graphics, KKU. Lecture 51 Transformations Given two frames in an affine space of dimension n, we can find a ( n+1 ) x ( n +1) matrix that.
CS 445 / 645: Introductory Computer Graphics Light.
Geometric Objects and Transformation
Hank Childs, University of Oregon Oct. 10, 2014 CIS 441/541: Introduction to Computer Graphics Lecture 4: Interpolating Colors and the Z-buffer.
1 Computer Graphics Week9 -3D Geometric Transformation.
CO1301: Games Concepts Dr Nick Mitchell (Room CM 226) Material originally prepared by Gareth Bellaby.
CS654: Digital Image Analysis Lecture 6: Basic Transformations.
Review on Graphics Basics. Outline Polygon rendering pipeline Affine transformations Projective transformations Lighting and shading From vertices to.
Hank Childs, University of Oregon Volume Rendering, pt 1.
Written by: Itzik Ben Shabat Technion - Israel Institute of Technology Faculty of Mechanical Engineering Laboratory for CAD & Lifecycle Engineering Lab.
1 Representation. 2 Objectives Introduce concepts such as dimension and basis Introduce coordinate systems for representing vectors spaces and frames.
CS 551 / 645: Introductory Computer Graphics Viewing Transforms.
Revision Sheet Computer Graphics and Human Interaction By Dr. HANY ELSALAMONY1.
CSCE 441 Computer Graphics: 2D Transformations
Hank Childs, University of Oregon
Computer Graphics Overview
CSE 167 [Win 17], Lecture 2: Review of Basic Math Ravi Ramamoorthi
Hank Childs, University of Oregon
Hank Childs, University of Oregon
Hank Childs, University of Oregon
Photorealistic Rendering vs. Interactive 3D Graphics
Hank Childs, University of Oregon
and an introduction to matrices
Graphics Fundamentals
Hank Childs, University of Oregon
Lecture 7 Geometric Transformations (Continued)
Hank Childs, University of Oregon
3D Graphics Rendering PPT By Ricardo Veguilla.
COMP 175: Computer Graphics February 9, 2016
CSC4820/6820 Computer Graphics Algorithms Ying Zhu Georgia State University Transformations.
Hank Childs, University of Oregon
ICG 2018 Fall Homework1 Guidance
Introduction to transformational GEOMETRY
Computer Graphics 4Practical Lesson
Game Programming Algorithms and Techniques
CIS 441/541: Introduction to Computer Graphics Lecture 15: shaders
Transformations with Matrices
Transformations Review
Presentation transcript:

Hank Childs, University of Oregon Oct. 22 nd, 2014 CIS 441/541: Introduction to Computer Graphics Lecture 7: Arbitrary Camera Positions

What am I missing?  1C redux submission  1D redux  ???

Grading  All 1B’s graded  Rubrics:  I really intend for you to get “0 pixels difference”  Anything less than that can be very problematic to grade.  Looks like some submissions with >0 pixels  I will be contacting people about these

Upcoming Schedule  IEEE Vis Nov 8-13  Class canceled Nov 12  Class held Nov 14  SuperComputer Nov  Midterm Nov 19  Class held Nov 21  HiPC Dec. 10+  Get Final projects in on time  Final late policy: 20% off for 1 day late, 50% off thereafter

Project #1E (7%), Due Mon 10/27  Goal: add Phong shading  Extend your project1D code  File proj1e_geometry.vtk available on web (9MB)  File “reader1e.cxx” has code to read triangles from file.  No Cmake, project1e.cxx

Changes to data structures class Triangle { public: double X[3], Y[3], Z[3]; double colors[3][3]; double normals[3][3]; };  reader1e.cxx will not compile until you make these changes  reader1e.cxx will initialize normals at each vertex

More comments  New: more data to help debug  I will make the shading value for each pixel available.  I will also make it available for ambient, diffuse, specular.  Don’t forget to do two-sided lighting  This project in a nutshell:  LERP normal to a pixel You all are great at this now!!  Add method called “CalculateShading”. My version of CalculateShading is about ten lines of code.  Modify RGB calculation to use shading.

Outline  Review: Basic Transformations  Arbitrary Camera Positions Note: Ken Joy’s graphics notes are fantastic

Outline  Review: Basic Transformations  Arbitrary Camera Positions

Starting easy … two-dimensional (a b) (x) (a*x + b*y) (c d) X (y) = (c*x + d*y) MP = P’ Matrix M transforms point P to make new point P’. M takes point (x,y) to point (a*x+b*y, c*x+d*y) M takes point (x,y) to point (a*x+b*y, c*x+d*y)

(1 0) (x) (x) (0 1) X (y) = (y) MP = P’ Matrix M transforms point P to make new point P. Identity Matrix

(2 0) (x) (2x) (0 1) X (y) = (y) MP = P’ Matrix M transforms point P to make new point P. Scale in X, not in Y (x,y) (2x,y)

(s 0) (x) (sx) (0 t) X (y) = (ty) MP = P’ Matrix M transforms point P to make new point P. Scale in both dimensions (x,y) (sx,ty)

(0 1) (x) (y) (1 0) X (y) = (x) MP = P’ Matrix M transforms point P to make new point P. Switch X and Y (x,y) (y,x)

(0 1) (x) (y) (-1 0) X (y) = (-x) MP = P’ Matrix M transforms point P to make new point P. Rotate 90 degrees clockwise (x,y) (y,-x)

(0 -1) (x) (-y) (1 0) X (y) = (x) MP = P’ Matrix M transforms point P to make new point P. Rotate 90 degrees counter- clockwise (x,y) (-y,x)

(cos(a) sin(a)) (x) (cos(a)*x+sin(a)*y)) (-sin(a) cos(a)) X (y) = (-sin(a)*x+cos(a)*y) MP = P’ Matrix M transforms point P to make new point P. Rotate “a” degrees counter- clockwise (x,y) (x’, y’) a

Combining transformations  How do we rotate by 90 degrees clockwise and then scale X by 2?  Answer: multiply by matrix that multiplies by 90 degrees clockwise, then multiply by matrix that scales X by 2.  But can we do this efficiently? (0 1) (2 0) (0 1) (-1 0) X (0 1) = (-2 0)

Reminder: matrix multiplication (a b) (e f) (a*e+b*g a*f+b*h) (c d) X (g h) = (c*e+d*g c*f+d*h)

Combining transformations  How do we rotate by 90 degrees clockwise and then scale X by 2?  Answer: multiply by matrix that rotates by 90 degrees clockwise, then multiply by matrix that scales X by 2.  But can we do this efficiently? (0 1) (2 0) (0 1) (-1 0) X (0 1) = (-2 0)

Combining transformations  How do we scale X by 2 and then rotate by 90 degrees clockwise?  Answer: multiply by matrix that scales X by 2, then multiply by matrix that rotates 90 degrees clockwise. (2 0) (0 1) (0 2) (0 1) X (-1 0) = (-1 0) (0 1) (2 0) (0 1) (-1 0) X (0 1) = (-2 0) Multiply then scale Order matters!!

Translations  Translation is harder: (a) (c) (a+c) (b) + (d) = (b+d) But this doesn’t fit our nice matrix multiply model… What to do??

Outline  Review: Basic Transformations  Arbitrary Camera Positions Note: Ken Joy’s graphics notes are fantastic

Our goal World space: Triangles in native Cartesian coordinates Camera located anywhere O Camera space: Camera located at origin, looking down -Z Triangle coordinates relative to camera frame O Image space: All viewable objects within -1 <= x,y,z <= +1 x y z Screen space: All viewable objects within -1 <= x, y <= +1 Device space: All viewable objects within 0<=x<=width, 0 <=y<=height

Our goal World space: Triangles in native Cartesian coordinates Camera located anywhere O Camera space: Camera located at origin, looking down -Z Triangle coordinates relative to camera frame O Image space: All viewable objects within -1 <= x,y,z <= +1 x y z Screen space: All viewable objects within -1 <= x, y <= +1 Device space: All viewable objects within 0<=x<=width, 0 <=y<=height

World Space  World Space is the space defined by the user’s coordinate system.  This space contains the portion of the scene that is transformed into image space by the camera transform.  It is normally left to the user to specify the bounds on this space.

Our goal World space: Triangles in native Cartesian coordinates Camera located anywhere O Camera space: Camera located at origin, looking down -Z Triangle coordinates relative to camera frame O Image space: All viewable objects within -1 <= x,y,z <= +1 x y z Screen space: All viewable objects within -1 <= x, y <= +1 Device space: All viewable objects within 0<=x<=width, 0 <=y<=height Camera Transform

Our goal World space: Triangles in native Cartesian coordinates Camera located anywhere O Camera space: Camera located at origin, looking down -Z Triangle coordinates relative to camera frame O Image space: All viewable objects within -1 <= x,y,z <= +1 x y z Screen space: All viewable objects within -1 <= x, y <= +1 Device space: All viewable objects within 0<=x<=width, 0 <=y<=height View Transform

World Space  World Space is the space defined by the user’s coordinate system.  This space contains the portion of the scene that is transformed into image space by the camera transform.  It is normally left to the user to specify the bounds on this space.

Our goal World space: Triangles in native Cartesian coordinates Camera located anywhere O Camera space: Camera located at origin, looking down -Z Triangle coordinates relative to camera frame O Image space: All viewable objects within -1 <= x,y,z <= +1 x y z Screen space: All viewable objects within -1 <= x, y <= +1 Device space: All viewable objects within 0<=x<=width, 0 <=y<=height

How do we specify a camera? The “viewing pyramid” or “view frustum”. Frustum: In geometry, a frustum (plural: frusta or frustums) is the portion of a solid (normally a cone or pyramid) that lies between two parallel planes cutting it.

Our goal World space: Triangles in native Cartesian coordinates Camera located anywhere O Camera space: Camera located at origin, looking down -Z Triangle coordinates relative to camera frame O Image space: All viewable objects within -1 <= x,y,z <= +1 x y z Screen space: All viewable objects within -1 <= x, y <= +1 Device space: All viewable objects within 0<=x<=width, 0 <=y<=height

Image Space  Image Space is the three-dimensional coordinate system that contains screen space.  It is the space where the camera transformation directs its output.  The bounds of Image Space are 3-dimensional cube. {(x,y,z) : − 1≤x≤1, − 1≤y≤1, − 1≤z≤1}

Image Space Diagram Up X=1 X = -1 Y=1 Y = -1 Z=1 Z = -1

Our goal World space: Triangles in native Cartesian coordinates Camera located anywhere O Camera space: Camera located at origin, looking down -Z Triangle coordinates relative to camera frame O Image space: All viewable objects within -1 <= x,y,z <= +1 x y z Screen space: All viewable objects within -1 <= x, y <= +1 Device space: All viewable objects within 0<=x<=width, 0 <=y<=height

Screen Space  Screen Space is the intersection of the xy-plane with Image Space.  Points in image space are mapped into screen space by projecting via a parallel projection, onto the plane z = 0.  Example:  a point (0, 0, z) in image space will project to the center of the display screen

Screen Space Diagram X +1 Y +1

Our goal World space: Triangles in native Cartesian coordinates Camera located anywhere O Camera space: Camera located at origin, looking down -Z Triangle coordinates relative to camera frame O Image space: All viewable objects within -1 <= x,y,z <= +1 x y z Screen space: All viewable objects within -1 <= x, y <= +1 Device space: All viewable objects within 0<=x<=width, 0 <=y<=height

Device Space  Device Space is the lowest level coordinate system and is the closest to the hardware coordinate systems of the device itself.  Device space is usually defined to be the n × m array of pixels that represent the area of the screen.  A coordinate system is imposed on this space by labeling the lower-left-hand corner of the array as (0,0), with each pixel having unit length and width.

Device Space Example

Device Space With Depth Information  Extends Device Space to three dimensions by adding z-coordinate of image space.  Coordinates are (x, y, z) with 0 ≤ x ≤ n 0 ≤ y ≤ m z arbitrary (but typically -1 ≤ z ≤ +1)

Easiest Transform World space: Triangles in native Cartesian coordinates Camera located anywhere O Camera space: Camera located at origin, looking down -Z Triangle coordinates relative to camera frame O Image space: All viewable objects within -1 <= x,y,z <= +1 x y z Screen space: All viewable objects within -1 <= x, y <= +1 Device space: All viewable objects within 0<=x<=width, 0 <=y<=height

Image Space to Device Space  (x, y, z)  ( x’, y’, z’), where  x’ = n*(x+1)/2  y’ = m*(y+1)/2  z’ = z  (for an n x m image)  Matrix: (x’ 0 0 0) (0 y’ 0 0) (0 0 z’ 0) ( )

(a little more review)

New terms  Coordinate system:  A system that uses coordinates to establish position  Example: (3, 4, 6) really means…  3x(1,0,0)  4x(0,1,0)  6x(0,0,1)  Since we assume the Cartesian coordinate system

New terms  Frame:  A way to place a coordinate system into a specific location in a space  Cartesian example: (3,4,6)  It is assumed that we are speaking in reference to the origin (location (0,0,0)).  A frame F is a collection (v1, v2, …, vn, O) is a frame over a space if (v1, v2, … vn) form a basis over that space.  What is a basis??  linear algebra term

What does it mean to form a basis?  For any vector v, there are unique coordinates (c1, …, cn) such that v = c1*v1 + c2*v2 + … + cn*vn

What does it mean to form a basis?  For any vector v, there are unique coordinates (c1, …, cn) such that v = c1*v1 + c2*v2 + … + cn*vn  Consider some point P.  The basis has an origin O  There is a vector v such that O+v = P  We know we can construct v using a combination of vi’s  Therefore we can represent P in our frame using the coordinates (c1, c2, …, cn)

Example of Frames  Frame F = (v1, v2, O)  v1 = (0, -1)  v2 = (1, 0)  O = (3, 4)  What are F’s coordinates for the point (6, 6)?

Example of Frames  Frame F = (v1, v2, O)  v1 = (0, -1)  v2 = (1, 0)  O = (3, 4)  What are F’s coordinates for the point (6, 6)?  Answer: (-2, 3)

Translations  Translation is harder: (a) (c) (a+c) (b) + (d) = (b+d) But this doesn’t fit our nice matrix multiply model… What to do??

Homogeneous Coordinates (1 0 0) (x) (x) (0 1 0) X (y) = (y) (0 0 1) (1) = (1) Add an extra dimension. A math trick … don’t overthink it.

Homogeneous Coordinates (1 0 dx) (x) (x+dx) (0 1 dy) X (y) = (y+dy) (0 0 1) (1) (1) Translation We can now fit translation into our matrix multiplication system.

(now new content)

Homogeneous Coordinates  Defined: a system of coordinates used in projective geometry, as Cartesian coordinates are used in Euclidean geometry  Primary uses:  4 × 4 matrices to represent general 3-dimensional transformations  it allows a simplified representation of mathematical functions – the rational form – in which rational  We only care about the first  I don’t really even know what the second use means

Interpretation of Homogeneous Coordinates  4D points: (x, y, z, w)  Our typical frame: (x, y, z, 1)

Interpretation of Homogeneous Coordinates  4D points: (x, y, z, w)  Our typical frame: (x, y, z, 1) Our typical frame in the context of 4D points So how to treat points not along the w=1 line?

Projecting back to w=1 line  Let P = (x, y, z, w) be a 4D point with w != 1  Goal: find P’ = (x’, y’, z’, 1) such P projects to P’  (We have to define what it means to project)  Idea for projection:  Draw line from P to origin.  If Q is along that line (and Q.w == 1), then Q is a projection of P

Projecting back to w==1 line  Idea for projection:  Draw line from P to origin.  If Q is along that line (and Q.w == 1), then Q is a projection of P

So what is Q?  Similar triangles argument:  x’ = x/w  y’ = y/w  z’ = z/w

Our goal World space: Triangles in native Cartesian coordinates Camera located anywhere O Camera space: Camera located at origin, looking down -Z Triangle coordinates relative to camera frame O -Z  Need to construct a Camera Frame  Need to construct a matrix to transform points from Cartesian Frame to Camera Frame  Transform triangle by transforming its three vertices

Basis pt 2 (more linear algebra-y this time)  Camera frame must be a basis:  Spans space … can get any point through a linear combination of basis functions  Every member must be linearly independent

Camera frame construction  Must choose (v1,v2,v3,O)  O = camera position  v3 = O-focus  Not “focus-O”, since we want to look down -Z Camera space: Camera located at origin, looking down -Z Triangle coordinates relative to camera frame O -Z

What is the up axis?  Up axis is the direction from the base of your nose to your forehead Up

What is the up axis?  Up axis is the direction from the base of your nose to your forehead + =

What is the up axis?  Up axis is the direction from the base of your nose to your forehead  (if you lie down while watching TV, the screen is sideways) + =

Camera frame construction  Must choose (v1,v2,v3,O)  O = camera position  v3 = O-focus  v2 = up  v1 = up x (O-focus) Camera space: Camera located at origin, looking down -Z Triangle coordinates relative to camera frame O -Z

But wait … what if dot(v2,v3) != 0?  We can get around this with two cross products:  v1 = Up x (O-focus)  v2 = (O-focus) x v1 O-focus Up

Camera frame summarized  O = camera position  v1 = Up x (O-focus)  v2 = (O-focus) x v1  v3 = O-focus

Our goal World space: Triangles in native Cartesian coordinates Camera located anywhere O Camera space: Camera located at origin, looking down -Z Triangle coordinates relative to camera frame O -Z  Need to construct a Camera Frame  ✔  Need to construct a matrix to transform points from Cartesian Frame to Camera Frame  Transform triangle by transforming its three vertices

The Two Frames of the Camera Transform  Our two frames:  Cartesian:   (0,0,0)  Camera:  v1 = up x (O-focus)  v2 = (O-focus) x u  v3 = (O-focus)  O

The Two Frames of the Camera Transform  Our two frames:  Cartesian:   (0,0,0)  Camera:  v1 = up x (O-focus)  v2 = (O-focus) x u  v3 = (O-focus)  O Camera is a Frame, so we can express any vector in Cartesian as a combination of v1, v2, and v3.

Converting From Cartesian Frame To Camera Frame  The Cartesian vector can be represented as some combination of the Camera basis functions v1, v2, v3:  = e1,1 * v1 + e1,2 * v2 + e1,3 * v3  So can the Cartesian vector  = e2,1 * v1 + e2,2 * v2 + e2,3 * v3  So can the Cartesian vector  = e3,1 * v1 + e3,2 * v2 + e3,3 * v3  So can the vector: Cartesian origin – Camera origin  (0,0,0) - O = e4,1 * v1 + e4,2 * v2 + e4,3 * v3   (0,0,0) = e4,1 * v1 + e4,2 * v2 + e4,3 * v3 + O

Putting Our Equations Into Matrix Form  = e1,1 * v1 + e1,2 * v2 + e1,3 * v3  = e2,1 * v1 + e2,2 * v2 + e2,3 * v3  = e3,1 * v1 + e3,2 * v2 + e3,3 * v3  (0,0,0) = e4,1 * v1 + e4,2 * v2 + e4,3 * v3 + O   [ ] [e1,1 e1,2 e1,3 0] [v1]  [ ] [e2,1 e2,2 e2,3 0] [v2]  [ ] = [e3,1 e3,2 e3,3 0] [v3]  (0,0,0) [e4,1 e4,2 e4,3 1] [O]

Here Comes The Trick…  Consider the meaning of Cartesian coordinates (x,y,z): [x y z 1][ ] [ ] = (x,y,z) [ ] [(0,0,0)] But: [ ] [e1,1 e1,2 e1,3 0] [v1] [ ] [e2,1 e2,2 e2,3 0] [v2] [ ] = [e3,1 e3,2 e3,3 0] [v3] (0,0,0) [e4,1 e4,2 e4,3 1] [O]

Here Comes The Trick… But: [ ] [e1,1 e1,2 e1,3 0] [v1] [x y z 1][ ] [x y z 1] [e2,1 e2,2 e2,3 0] [v2] [ ] = [e3,1 e3,2 e3,3 0] [v3] [(0,0,0)] [e4,1 e4,2 e4,3 1] [O] Coordinates of (x,y,z) with respect to Cartesian frame. Coordinates of (x,y,z) with respect to Camera frame. So this matrix is the camera transform!!

Solving the Camera Transform [e1,1 e1,2 e1,3 0] [v1.x v2.x v3.x 0] [e2,1 e2,2 e2,3 0] [v1.y v2.y v3.y 0] [e3,1 e3,2 e3,3 0] = [v1.z v2.z v3.z 0] [e4,1 e4,2 e4,3 1] [v1. t v2. t v3. t 1] Where t = (0,0,0)-O How do we know?: Cramer’s Rule + simplifications Want to derive?: GraphicsNotes/Camera-Transform/Camera- Transform.html