Download presentation
Presentation is loading. Please wait.
Published byMadilyn Munford Modified over 9 years ago
1
Hank Childs, University of Oregon Oct. 22 nd, 2014 CIS 441/541: Introduction to Computer Graphics Lecture 7: Arbitrary Camera Positions
2
What am I missing? 1C redux submission 1D redux ???
3
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
4
Upcoming Schedule IEEE Vis Nov 8-13 Class canceled Nov 12 Class held Nov 14 SuperComputer Nov 15-20 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
5
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
6
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
7
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.
8
Outline Review: Basic Transformations Arbitrary Camera Positions Note: Ken Joy’s graphics notes are fantastic
9
Outline Review: Basic Transformations Arbitrary Camera Positions
10
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)
11
(1 0) (x) (x) (0 1) X (y) = (y) MP = P’ Matrix M transforms point P to make new point P. Identity Matrix
12
(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)
13
(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)
14
(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)
15
(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)
16
(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)
17
(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
18
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)
19
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)
20
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)
21
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!!
22
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??
23
Outline Review: Basic Transformations Arbitrary Camera Positions Note: Ken Joy’s graphics notes are fantastic
24
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
25
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
26
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.
27
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
28
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
29
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.
30
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
31
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.
32
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
33
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}
34
Image Space Diagram Up X=1 X = -1 Y=1 Y = -1 Z=1 Z = -1
35
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
36
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
37
Screen Space Diagram X +1 Y +1
38
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
39
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.
40
Device Space Example
41
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)
42
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
43
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) (0 0 0 1)
44
(a little more review)
45
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
46
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
47
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
48
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)
49
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)?
50
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)
51
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??
52
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.
53
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.
54
(now new content)
55
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
56
Interpretation of Homogeneous Coordinates 4D points: (x, y, z, w) Our typical frame: (x, y, z, 1)
57
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?
58
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
59
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
60
So what is Q? Similar triangles argument: x’ = x/w y’ = y/w z’ = z/w
61
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
62
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
63
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
64
What is the up axis? Up axis is the direction from the base of your nose to your forehead Up
65
What is the up axis? Up axis is the direction from the base of your nose to your forehead + =
66
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) + =
67
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
68
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
69
Camera frame summarized O = camera position v1 = Up x (O-focus) v2 = (O-focus) x v1 v3 = O-focus
70
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
71
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
72
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.
73
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
74
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]
75
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]
76
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!!
77
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?: http://www.idav.ucdavis.edu/education/ GraphicsNotes/Camera-Transform/Camera- Transform.html
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.