Download presentation
Published byByron Robinson Modified over 8 years ago
0
CSCE 441 Computer Graphics 3-D Viewing
Jinxiang Chai
1
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
2
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
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 Graphics does the same thing for rendering an image for 3D geometric objects
4
Rendering Images Using a Virtual Camera
5
3D Geometry Pipeline Object space World space View space
Rotate and translate the camera Object space World space View space Focal length Aspect ratio & resolution Normalized projection space Screen/Image space 5
6
3D Geometry Pipeline Model space (Object space)
Before being turned into pixels by graphics hardware, a piece of geometry goes through a number of transformations... Model space (Object space)
7
3D Geometry Pipeline World space (Object space)
Before being turned into pixels by graphics hardware, a piece of geometry goes through a number of transformations... World space (Object space)
8
3D Geometry Pipeline Eye space (View space)
Before being turned into pixels by graphics hardware, a piece of geometry goes through a number of transformations... Eye space (View space)
9
Normalized projection space
3D Geometry Pipeline Before being turned into pixels by graphics hardware, a piece of geometry goes through a number of transformations... Normalized projection space
10
Image space, window space, raster space, screen space, device space
3D Geometry Pipeline Before being turned into pixels by graphics hardware, a piece of geometry goes through a number of transformations... Image space, window space, raster space, screen space, device space
11
Normalized project space
Taking Steps Together C M Object space World space View space P V Normalized project space Image space 11
12
OpenGL Codes 12
13
OpenGL Codes 13
14
OpenGL Codes 14
15
Normalized project space
3D Geometry Pipeline Object space World space View space Normalized project space Image space
16
Translate, scale &rotate
3D Geometry Pipeline Translate, scale &rotate Object space World space glTranslate*(tx,ty,tz)
17
Translate, scale &rotate
3D Geometry Pipeline Translate, scale &rotate Object space World space glScale*(sx,sy,sz)
18
Translate, scale &rotate
3D Geometry Pipeline Translate, scale &rotate Object space World space Rotate about r by the angle glRotate*
19
Normalized projection space
3D Geometry Pipeline Object space World space View space Normalized projection space Image space Screen space
20
3D Geometry Pipeline World space View space
Now look at how we would compute the world->eye transformation World space View space
21
3D Geometry Pipeline World space View space
Now look at how we would compute the world->eye transformation Rotate&translate World space View space
22
Camera Coordinate
23
Viewing Trans: gluLookAt
gluLookAt (eyex,eyey,eyez,atx,aty,atz,upx, upy,upz) 23
24
Camera Coordinate Canonical coordinate system
- usually right handed (looking down –z axis) - convenient for project and clipping
25
Camera Coordinate 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
26
Viewing Transformation
We have the camera in world coordinates We want to model transformation T which takes object from world to camera
27
Viewing Transformation
We have the camera in world coordinates We want to model transformation T which takes object from world to camera Trick: find T-1 taking object from camera to world
28
Viewing Transformation
We have the camera in world coordinates We want to model transformation T which takes object from world to camera Trick: find T-1 taking object from camera to world ?
29
Review: 3D Coordinate Trans.
Transform object description from to p
30
Review: 3D Coordinate Trans.
Transform object description from to p 30
31
Review: 3D Coordinate Trans.
Transform object description from camera to world
32
Viewing Transformation
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
33
Viewing Transformation
Trick: find T-1 taking object from camera to world H&B equation (10-4)
34
Viewing Trans: gluLookAt
gluLookAt (eyex,eyey,eyez,atx,aty,atz,upx, upy,upz)
35
Viewing Trans: gluLookAt
Mapping from world to eye coordinates gluLookAt (eyex,eyey,eyez,atx,aty,atz,upx, upy,upz) How to determine ?
36
Viewing Trans: gluLookAt
Mapping from world to eye coordinates gluLookAt (eyex,eyey,eyez,atx,aty,atz,upx, upy,upz) How to determine ?
37
Viewing Trans: gluLookAt
Mapping from world to eye coordinates gluLookAt (eyex,eyey,eyez,atx,aty,atz,upx, upy,upz)
38
Viewing Trans: gluLookAt
Mapping from world to eye coordinates gluLookAt (eyex,eyey,eyez,atx,aty,atz,upx, upy,upz)
39
Viewing Trans: gluLookAt
Mapping from world to eye coordinates gluLookAt (eyex,eyey,eyez,atx,aty,atz,upx, upy,upz) Stop here. H&B equation (10-1)
40
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?
41
3D-3D viewing transformation
3D Geometry Pipeline 3D-3D viewing transformation World space View space
42
Projection General definition
transform points in n-space to m-space (m<n) In computer graphics map 3D coordinates to 2D screen coordinates
43
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?
44
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?
45
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?
46
Camera Obscura The first camera Known to Aristotle
Depth of the room is the focal length Pencil of rays – all rays through a point
47
Perspective Projection
Maps points onto “view plane” along projectors emanating from “center of projection” (COP)
48
Perspective Projection
Maps points onto “view plane” along projectors emanating from “center of projection” (COP) What’s relationship between 3D points and projected 2D points? 48
49
3D->2D Consider the projection of a 3D point on the camera plane
50
3D->2D Consider the projection of a 3D point on the camera plane 50
51
3D->2D Consider the projection of a 3D point on the camera plane
By similar triangles, we can compute how much the x and y coordinates are scaled
52
3D->2D Consider the projection of a 3D point on the camera plane
By similar triangles, we can compute how much the x and y coordinates are scaled
53
Homogeneous Coordinates
Is this a linear transformation?
54
Homogeneous Coordinates
Is this a linear transformation? no—division by z is nonlinear
55
Homogeneous Coordinates
Is this a linear transformation? no—division by z is nonlinear Trick: add one more coordinate: homogeneous image coordinates homogeneous scene coordinates
56
Homogeneous Point Revisited
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: If w=1, nothing happens Sometimes, we call this division step the “perspective divide”
57
The Perspective Matrix
Now we can rewrite the perspective projection equation as matrix-vector multiplications
58
The Perspective Matrix
Now we can rewrite the perspective projection equation as matrix-vector multiplications This becomes a linear transformation!
59
The Perspective Matrix
Now we can rewrite the perspective projection equation as matrix-vector multiplications After the division by w, we have
60
Perspective Effects Distant object becomes small
The distortion of items when viewed at an angle (spatial foreshortening)
61
Perspective Effects Distant object becomes small
The distortion of items when viewed at an angle (spatial foreshortening)
62
Perspective Effects Distant object becomes small
The distortion of items when viewed at an angle (spatial foreshortening)
63
Properties of Perspective Proj.
Perspective projection is an example of projective transformation - lines maps to lines - parallel lines do not necessary remain parallel - ratios are not preserved
64
Properties of Perspective Proj.
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
65
Vanishing Points What happens to parallel lines they are not parallel to the projection plane?
66
Vanishing Points What happens to parallel lines they are not parallel to the projection plane? The equation of the line:
67
Vanishing Points What happens to parallel lines they are not parallel to the projection plane? The equation of the line: After perspective transformation, we have
68
Vanishing Points (cont.)
Letting t go to infinity:
69
Vanishing Points What happens to parallel lines they are not parallel to the projection plane? The equation of the line:
70
Vanishing Points What happens to parallel lines they are not parallel to the projection plane? The equation of the line: How about the line
71
Vanishing Points What happens to parallel lines they are not parallel to the projection plane? The equation of the line: How about the line
72
Vanishing Points What happens to parallel lines they are not parallel to the projection plane? The equation of the line: How about the line Same vanishing point!
73
Vanishing Points 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
74
Vanishing Points 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
75
Parallel Projection Center of projection is at infinity
Direction of projection (DOP) same for all points
76
Orthographic Projection
Direction of projection (DOP) perpendicular to view plane
77
Orthographic Projection
Direction of projection (DOP) perpendicular to view plane
78
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
79
3D->2D Perspective projection from 3D to 2D 79
80
3D->2D Perspective projection from 3D to 2D
But so far, we have not considered the size of film plane! We have also not considered visibility problem 80
81
Normalized project space
3D Geometry Pipeline Object space World space View space z = -1 z = 1 Normalized project space Image space Screen space
82
Perspective Projection Volume
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
83
Perspective Projection Volume
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
84
Perspective Projection Volume
85
Perspective Projection Volume
86
Perspective Projection Volume
87
Perspective Projection Volume
88
OpenGL Perspective-Projection
z = -1 z = 1 Normalized project space View space End here glFrustum(xwmin, xwmax,ywmin, ywmax ,dnear,dfar) gluPerspective(fovy,aspect,dnear, dfar) 88
89
General Perspective-Projection
zfar (xwmax,ywmax,znear) (xwmin,ywmin,Znear) View space glFrustum(xwmin, xwmax,ywmin, ywmax ,dnear,dfar) Six parameters define six clipping planes!
90
General Perspective-Projection
glFrustum(xwmin, xwmax,ywmin, ywmax ,dnear,dfar) near clipping plane
91
General Perspective-Projection
glFrustum(xwmin, xwmax,ywmin, ywmax ,dnear,dfar) far clipping plane
92
General Perspective-Projection
glFrustum(xwmin, xwmax,ywmin, ywmax ,dnear,dfar) The size of the near plane
93
General Perspective-Projection
B’=(1,1,1) B A A’=(-1,-1,-1) H&B equation (10-40)
94
General Perspective-Projection
B’=(1,1,1) B A A’=(-1,-1,-1) View space (right-handed) Normalized project space (left-handed) A maps to A’, B maps to B’ Keep the directions of x and y axes!
95
General Perspective-Projection
B’=(1,1,1) B A A’=(-1,-1,-1) View space (right-handed) Normalized project space (left-handed) dnear=-1, dfar=1 xmin=-1,xmax=1,ymin=-1,ymax=1
96
OpenGL Symmetric Perspective-Projection Function
gluPerspective(fovy,aspect,dnear, dfar) Assume z-axis is the centerline of 3D view frustum!
97
Normalized projection space
3D Geometry Pipeline Object space World space View space Normalized projection space Image space
98
Viewport Transformation
Display window (xvmin,yvmin) Image space-.>Image space glViewport(xvmin, yvmin, width, height)
99
Viewport Transformation
- 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 (xvmin,yvmin) Image space-.>Image space glViewport(xvmin, yvmin, width, height)
100
Viewport Transformation
From normalized projection coordinates to 3D screen coordinates dnear= -1, dfar= 1 xmin= -1,xmax= 1 ymin= -1,ymax= 1 dnear= 0, dfar= 1 xmin= xvmin,xmax= xvmax, ymin= yvmin,ymax= yvmax glViewport(xvmin, yvmin, width, height) xmax=xvmin+width,ymax=yvmin+ height
101
Viewport Transformation
0<=z<=1 B’=(1,1,1) B’’=(xvmax,yvmax,1) -1<=z<=1 Normalized project space A’’=(xvmin,yvmin,0) A’=(-1,-1,-1) Normalized projection space 3D screen space
102
Viewport Transformation
0<=z<=1 B’=(1,1,1) B’’=(xvmax,yvmax,1) -1<=z<=1 Normalized project space A’’=(xvmin,yvmin,0) A’=(-1,-1,-1) Normalized projection space 3D screen space H&B equation (10-42)
103
Summary: 3D Geometry Pipeline
Object space World space View space Normalized projection space Image space
104
Normalized project space
Taking Steps Together C M Object space World space View space P V Normalized project space Image space
105
OpenGL Codes
106
OpenGL Codes 106
107
OpenGL Codes 107
108
Next Lecture: Hidden Surface Removal
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.