Download presentation
Presentation is loading. Please wait.
Published byJanel Dixon Modified over 9 years ago
1
Jinxiang Chai CSCE 441 Computer Graphics 3-D Viewing 0
2
Outline 3D Viewing Required readings: HB 10-1 to 10-10 Compile and run the codes in page 388 - opengl three-dimensional viewing program example 1
3
Taking Pictures Using A Real Camera Steps: - Identify interesting objects - Rotate and translate the camera to a desired camera viewpoint - Adjust camera settings such as focal length - Choose desired resolution and aspect ratio, etc. - Take a snapshot
4
Taking Pictures Using A Real Camera Steps: - Identify interesting objects - Rotate and translate the camera to a desired camera viewpoint - Adjust camera settings such as focal length - Choose desired resolution and aspect ratio, etc. - Take a snapshot Graphics does the same thing for rendering an image for 3D geometric objects
5
Image space 3D Geometry Pipeline 4 Normalized projection space View space World spaceObject space Aspect ratio & resolution Focal length Rotate and translate the camera
6
3D Geometry Pipeline Before being turned into pixels by graphics hardware, a piece of geometry goes through a number of transformations... 5 Model space (Object space)
7
3D Geometry Pipeline Before being turned into pixels by graphics hardware, a piece of geometry goes through a number of transformations... 6 World space (Object space)
8
3D Geometry Pipeline Before being turned into pixels by graphics hardware, a piece of geometry goes through a number of transformations... 7 Eye space (View space)
9
3D Geometry Pipeline Before being turned into pixels by graphics hardware, a piece of geometry goes through a number of transformations... 8 Normalized projection space
10
3D Geometry Pipeline Before being turned into pixels by graphics hardware, a piece of geometry goes through a number of transformations... 9 Image space, window space, raster space, screen space, device space
11
3D Geometry Pipeline 10 Normalized project space View space World spaceObject space Image space
12
3D Geometry Pipeline World spaceObject space glTranslate*(t x,t y,t z ) Translate, scale &rotate
13
3D Geometry Pipeline Object space glScale*(s x,s y,s z ) World space Translate, scale &rotate
14
3D Geometry Pipeline Object space glRotate* Rotate about r by the angle World space Translate, scale &rotate
15
Image space 3D Geometry Pipeline 14 Screen space Normalized project space View space World spaceObject space
16
Now look at how we would compute the world->eye transformation 3D Geometry Pipeline View spaceWorld space
17
Now look at how we would compute the world->eye transformation 3D Geometry Pipeline View spaceWorld space Rotate&translate
18
Camera Coordinate 17
19
Viewing Trans: gluLookAt 18 gluLookAt (eye x,eye y,eye z,at x,at y,at z,up x, up y,up z )
20
Canonical coordinate system - usually right handed (looking down –z axis) - convenient for project and clipping Camera Coordinate
21
Mapping from world to eye coordinates - eye position maps to origin - right vector maps to x axis - up vector maps to y axis - back vector maps to z axis Camera Coordinate
22
We have the camera in world coordinates We want to transformation T which takes object from world to camera Viewing Transformation
23
We have the camera in world coordinates We want to transformation T which takes object from world to camera Trick: find T -1 taking object from camera to world Viewing Transformation
24
We have the camera in world coordinates We want to transformation T which takes object from world to camera Trick: find T -1 taking object from camera to world Viewing Transformation ?
25
Review: 3D Coordinate Trans. Transform object description from to p 24
26
Review: 3D Coordinate Trans. Transform object description from to p 25
27
Review: 3D Coordinate Trans. Transform object description from camera to world 26
28
Trick: find T -1 taking object from camera to world - eye position maps to origin - back vector maps to z axis - up vector maps to y axis - right vector maps to x axis Viewing Transformation
29
Trick: find T -1 taking object from camera to world Viewing Transformation H&B equation (10-4)
30
Viewing Trans: gluLookAt 29 gluLookAt (eye x,eye y,eye z,at x,at y,at z,up x, up y,up z )
31
Mapping from world to eye coordinates Viewing Trans: gluLookAt How to determine ? gluLookAt (eye x,eye y,eye z,at x,at y,at z,up x, up y,up z )
32
Mapping from world to eye coordinates Viewing Trans: gluLookAt How to determine ? gluLookAt (eye x,eye y,eye z,at x,at y,at z,up x, up y,up z )
33
Mapping from world to eye coordinates Viewing Trans: gluLookAt gluLookAt (eye x,eye y,eye z,at x,at y,at z,up x, up y,up z )
34
Mapping from world to eye coordinates Viewing Trans: gluLookAt gluLookAt (eye x,eye y,eye z,at x,at y,at z,up x, up y,up z )
35
Mapping from world to eye coordinates Viewing Trans: gluLookAt H&B equation (10-1) gluLookAt (eye x,eye y,eye z,at x,at y,at z,up x, up y,up z )
36
Viewing Trans: gluLookAt Test: gluLookAt( 4.0, 2.0, 1.0, 2.0, 4.0, -3.0, 0, 1.0, 0 ) - What’s the transformation matrix from the world space to the camera reference system?
37
3D Geometry Pipeline View space World space 3D-3D viewing transformation
38
Projection General definition transform points in n-space to m-space (m<n) In computer graphics map 3D coordinates to 2D screen coordinates
39
Projection General definition transform points in n-space to m-space (m<n) In computer graphics map 3D coordinates to 2D screen coordinates How can we project 3d objects to 2d screen space?
40
How Do We See the World? Let’s design a camera: idea 1: put a piece of film in front of camera Do we get a reasonable picture?
41
Pin-hole Camera Add a barrier to block off most of the rays This reduces blurring The opening known as the aperture How does this transform the image?
42
Camera Obscura The first camera Known to Aristotle Depth of the room is the focal length Pencil of rays – all rays through a point
43
Perspective Projection Maps points onto “view plane” along projectors emanating from “center of projection” (COP) 42
44
Perspective Projection Maps points onto “view plane” along projectors emanating from “center of projection” (COP) 43 What’s relationship between 3D points and projected 2D points?
45
Consider the projection of a 3D point on the camera plane 3D->2D 44
46
Consider the projection of a 3D point on the camera plane 3D->2D 45
47
Consider the projection of a 3D point on the camera plane 3D->2D 46 By similar triangles, we can compute how much the x and y coordinates are scaled
48
Consider the projection of a 3D point on the camera plane 3D->2D 47 By similar triangles, we can compute how much the x and y coordinates are scaled
49
Homogeneous Coordinates Is this a linear transformation?
50
Homogeneous Coordinates Is this a linear transformation? –no—division by z is nonlinear
51
Homogeneous Coordinates Is this a linear transformation? Trick: add one more coordinate: homogeneous image coordinates homogeneous scene coordinates –no—division by z is nonlinear
52
Remember how we said 2D/3D geometric transformations work with the last coordinate always set to one What happens if the coordinate is not one We divide all coordinates by w: Homogeneous Point Revisited 51 If w=1, nothing happens Sometimes, we call this division step the “perspective divide”
53
Now we can rewrite the perspective projection equation as matrix-vector multiplications The Perspective Matrix 52
54
Now we can rewrite the perspective projection equation as matrix-vector multiplications The Perspective Matrix 53 This becomes a linear transformation!
55
Now we can rewrite the perspective projection equation as matrix-vector multiplications The Perspective Matrix 54 After the division by w, we have
56
Perspective Effects Distant object becomes small The distortion of items when viewed at an angle (spatial foreshortening)
57
Perspective Effects Distant object becomes small The distortion of items when viewed at an angle (spatial foreshortening)
58
Perspective Effects Distant object becomes small The distortion of items when viewed at an angle (spatial foreshortening)
59
Perspective projection is an example of projective transformation - lines maps to lines - parallel lines do not necessary remain parallel - ratios are not preserved Properties of Perspective Proj.
60
Perspective projection is an example of projective transformation - lines maps to lines - parallel lines do not necessary remain parallel - ratios are not preserved One of advantages of perspective projection is that size varies inversely proportional to the distance- looks realistic Properties of Perspective Proj.
61
What happens to parallel lines they are not parallel to the projection plane? Vanishing Points 60
62
What happens to parallel lines they are not parallel to the projection plane? The equation of the line: Vanishing Points 61
63
What happens to parallel lines they are not parallel to the projection plane? The equation of the line: After perspective transformation, we have Vanishing Points 62
64
Letting t go to infinity: Vanishing Points (cont.) 63
65
What happens to parallel lines they are not parallel to the projection plane? The equation of the line: Vanishing Points 64
66
What happens to parallel lines they are not parallel to the projection plane? The equation of the line: How about the line Vanishing Points 65
67
What happens to parallel lines they are not parallel to the projection plane? The equation of the line: How about the line Vanishing Points 66
68
What happens to parallel lines they are not parallel to the projection plane? The equation of the line: How about the line Vanishing Points 67 Same vanishing point!
69
What happens to parallel lines they are not parallel to the projection plane? Each set of parallel lines intersect at a vanishing point on the PP Vanishing Points
70
What happens to parallel lines they are not parallel to the projection plane? Each set of parallel lines intersect at a vanishing point on the PP Vanishing Points
71
Parallel Projection Center of projection is at infinity Direction of projection (DOP) same for all points
72
Orthographic Projection Direction of projection (DOP) perpendicular to view plane
73
Orthographic Projection Direction of projection (DOP) perpendicular to view plane
74
Properties of Parallel Projection Not realistic looking Good for exact measurement Are actually affine transformation - parallel lines remain parallel - ratios are preserved - angles are often not preserved Most often used in CAD, architectural drawings, etc. where taking exact measurement is important
75
Perspective projection from 3D to 2D 3D->2D 74
76
Perspective projection from 3D to 2D 3D->2D 75 But so far, we have not considered the size of film plane! We have also not considered visibility problem
77
Image space 3D Geometry Pipeline 76 Screen space Normalized project space View space World spaceObject space z = -1 z = 1
78
The center of projection and the portion of projection plane that map to the final image form an infinite pyramid. The sides of pyramid called clipping planes Additional clipping planes are inserted to restrict the range of depths Perspective Projection Volume
79
OpenGL Perspective-Projection 78 Normalized project space View space glFrustum(xw min, xw max,yw min, yw max,d near,d far ) gluPerspective(fovy,aspect,dnear, dfar) z = -1 z = 1
80
View space (xw min,yw min,Z near ) (xw max,yw max,z near ) General Perspective-Projection z far glFrustum(xw min, xw max,yw min, yw max,d near,d far ) Six parameters define six clipping planes!
81
General Perspective-Projection glFrustum(xw min, xw max,yw min, yw max,d near,d far ) Left-vertical clipping plane
82
General Perspective-Projection glFrustum(xw min, xw max,yw min, yw max,d near,d far ) right-vertical clipping plane
83
General Perspective-Projection glFrustum(xw min, xw max,yw min, yw max,d near,d far ) bottom-horizontal clipping plane
84
General Perspective-Projection glFrustum(xw min, xw max,yw min, yw max,d near,d far ) top-horizontal clipping plane
85
General Perspective-Projection glFrustum(xw min, xw max,yw min, yw max,d near,d far ) near clipping plane
86
General Perspective-Projection glFrustum(xw min, xw max,yw min, yw max,d near,d far ) far clipping plane
87
Normalized project space (left-handed) View space (right-handed) B’=(1,1,1) A’=(-1,-1,-1) General Perspective-Projection A maps to A’, B maps to B’ Keep the directions of x and y axes! A B
88
B’=(1,1,1) A’=(-1,-1,-1) General Perspective-Projection H&B equation (10-40) A B
89
OpenGL Symmetric Perspective- Projection Function gluPerspective(fovy,aspect,dnear, dfar) 88 Assume z-axis is the centerline of 3D view frustum!
90
Image space 3D Geometry Pipeline 89 Normalized project space View space World spaceObject space
91
Image space-.>Image space Viewport Transformation 90 glViewport(x min, y min, width, height) (x min,y min ) Display window viewport
92
Image space-.>Image space Viewport Transformation 91 glViewport(x min, y min, width, height) (x min,y min ) - Besides x and y, each pixel has a depth value z, which is stored in depth buffer. -Depth values will be used for visibility testing -The color of the pixel is stored in color buffer
93
92 Image space Normalized project space B’=(1,1,1) A’=(-1,-1,-1) Normalized project space A’’=(xv min,yv min,0) B’’=(xv max,yv max,1) Viewport Transformation -1<=z<=1 0<=z<=1
94
Viewport Transformation 93 Image space Normalized project space B’=(1,1,1) A’=(-1,-1,-1) Normalized project space A’’=(xv min,yv min,0) B’’=(xv max,yv max,1) H&B equation (10-42) -1<=z<=1 0<=z<=1
95
Image space Summary: 3D Geometry Pipeline 94 Normalized project space View space World spaceObject space
96
Taking Steps Together 95 Image space Normalized project space View space World spaceObject space
97
OpenGL Codes 96
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.