Download presentation
Presentation is loading. Please wait.
Published byElaine Holmes Modified over 8 years ago
1
Viewing and Projection
2
The topics Interior parameters Projection type Field of view Clipping Frustum… Exterior parameters Camera position Camera orientation
3
World coordinate others Transformation Pipeline Projection Matrix World->Eye Local coordinate Eye coordinate Local->World ModelView Matrix ModelView Matrix Clip coordinate Screen coordinate
4
Projection The projection transforms a point from a high- dimensional space to a low-dimensional space. In 3D, the projection means mapping a 3D point onto a 2D projection plane (or called image plane). There are two basic projection types: Parallel: orthographic, oblique Perspective
5
Orthographic Projection Image Plane Direction of Projection z=k z-axis
6
Orthographic Projection
7
Oblique Projection Image Plane Direction of Projection
8
Properties of Parallel Projection Definition: projection directions are parallel. Doesn’t look real. Can preserve parallel lines Projection Parallel in 3DParallel in 2D
9
Properties of Parallel Projection Definition: projection directions are parallel. Doesn’t look real. Can preserve parallel lines Can preserve ratios Projection
10
Properties of Parallel Projection Definition: projection directions are parallel. Doesn’t look real. Can preserve parallel lines Can preserve ratios CANNOT preserve angles Projection
11
Properties of Parallel Projection Definition: projection directions are parallel. Doesn’t look real. Can preserve parallel lines Can preserve ratios CANNOT preserve angles Often used in CAD, architecture drawings, when images can be used for measurement.
12
Properties of Parallel Projection No foreshortening Image Plane
13
Perspective Projection Perspective projection has foreshortening: Image Plane Center of Projection
14
Perspective Projection Images are mapped onto the image plane in different ways: Image Plane Center of Projection An image (640*640)
15
Perspective Projection Images are mapped onto the image plane in different ways: Image Plane Center of Projection An image (640*640)
16
Perspective Projection Angle of view tells us the mapping from the image to the image plane: Image Plane Center of Projection Angle of view Field of view
17
Perspective Projection Not everything will be displayed. Image Plane Center of Projection Near PlaneFar Plane Frustum
18
Perspective Projection The frustum of perspective projection looks like: Center of Projection Image Plane Near Plane
19
Ortho Projection What’s the frustum of orthographic projection? Image Plane NearFar
20
In general, the homogeneous coordinate system is define as: For example, Homogenous Coordinates In 3D In homogeneous space
21
Both homogenous vectors and matrices are scalable: Homogenous Coordinates
22
Perspective Projection Derivation: Image Plane Z Axis XY Plane
23
Perspective Projection Derivation: Image Plane Z Axis XY Plane
24
Perspective Matrix Derivation: How? The z axis now becomes useless…
25
OpenGL Perspective Matrix In practice, OpenGL uses the z axis for depth test. Its matrix looks like this: The depth value now can be used for depth test. We will discuss this in more details later...
26
Vanishing Point Given a ray: Its projection:
27
Vanishing Point When t goes to infinity: What if there is another ray: Parallel lines meet at the vanishing point.
28
Properties of Perspective Projection Lines are mapped to lines. Parallel lines may not remain parallel. Instead, they may meet at the vanishing point. Ratios are not preserved. It has foreshortening effects. So it looks real. Distances cannot be directly measured, as in parallel projection.
29
Basic OpenGL Projection Everything will be considered in the eye space: Geometry objects have been transformed into the eye coordinate system using the GL_MODELVIEW matrix. You define the projection matrix in GL_PROJECTION, also in the eye space. OpenGL always assume that the viewing direction is the –z direction. OpenGL automatically processes each vertex using GL_PROJECTION: After projection, the frustum is converted into a canonical view volume ( [-1, 1] in all coordinates)
30
OpenGL Orthographic Projection glOrtho(left, right, bottom, top, near, far) (left, bottom, near) X rangeY rangeZ range (right, top, far) (-1, -1, -1) (1, 1, 1)
31
OpenGL Orthographic Projection glOrtho(l, r, b, t, n, f) Translation so that the center is the origin. Scaling so that the size becomes (2, 2, 2).
32
OpenGL Perspective Projection glFrustum(left, right, bottom, top, near, far) Center of Projection Near Plane (Image Plane) Far Plane Frustum (left, right, bottom, top) may not be centered along the axis Always positive, although it’s facing the –z direction
33
OpenGL Perspective Projection gluPerspective(fov, aspect_ratio, near, far) Center of Projection Near Plane (Image Plane) Far Plane Frustum fov ratio=image_width/image_height top: near*ctan(fov/2) right: near*ratio*ctan(fov/2) Always positive, although it’s facing the –z direction
34
OpenGL Perspective Projection glFrustum(…) is less useful than gluPerspective(...). But we can still use it for demonstration purpose next.
35
OpenGL Perspective Projection Projection
36
OpenGL Perspective Projection Projection in (-1, 1) in (-n, -f), why???
37
OpenGL Perspective Projection
38
Projection (l/n, b/n, -1) (r/n, t/n, 1)
39
OpenGL Perspective Projection Transform (l/n, b/n, -1) (r/n, t/n, 1) (-1, -1, -1) (1, 1, 1) TranslationScaling
40
OpenGL Perspective Projection Projection (-1, -1, -1) (1, 1, 1) Original ProjectionTransformation
41
What happens after projection? Clipping Viewport transformation Rasterization clipping (-1, -1) (1, 1) viewport (0, 0) (800, 800) rasterize
42
Depth Test Before rasterization, all processes are done based on vertices. The z coordinate at each vertex is transformed into a new z value (or called the depth value). During rasterization, the z value of each pixel is interpolated from vertices. The z value then stored in the depth buffer, for occlusion tests. (smaller z means closer).
43
Depth Test The depth buffer is part of the frame buffer: To enable or disable the depth buffer: Without the depth test, the occlusion is determined by the drawing order. glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB|GLUT_DEPTH); glEnable(GL_DEPTH_TEST); glDisable(GL_DEPTH_TEST);
44
Common Issues When you set up the perspective matrix: Near ( n ) cannot be zero! f : n cannot be too large! (far cannot be too large, or near cannot be too small.) Why?
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.