Upload
juniper-murphy
View
215
Download
2
Embed Size (px)
Citation preview
3D Viewing(From 3D to 2D)
Some of the material in these slides have been adapted from the lecture notes of Prof. Tao Ju from Washington University in St. Louis
2
Outline
● 3D Viewing● Perspective projection● Computing Projection● Our Virtual Camera Model● Camera parameters● Compute viewing transformation● Clipping against the canonical volume● Projecting to viewport
3
3D viewing
● Inherently more complex than 2D case.■ Extra dimension (!)■ Many display devices are only 2D.
● Need to use a projection to transform 3D object or scene to 2D display device.
● Need to clip against a 3D view volume.■ Six planes.■ View volume probably truncated pyramid.
4
Coordinate SystemsObject coordinate systems.
World coordinates.
View Volume
Screen coordinates.
Raster
Transform
Project
Clip
Rasterize
5
Projections
● Transforms points in a coordinate system of dimension n into points in one of less than n.
● The projection is defined by straight lines called projectors.● Projectors emanate from a centre of projection, pass through
every point in the object and intersect a projection surface to form the 2D projection.
6
Projections
● In graphics we only deal with planar projections – where the projection surface is a plane.
■ Most cameras employ a planar film plane.■ But… the retina is not a plane.
● Only deal with geometric projections – the projectors are straight lines.
■ Many projections used in cartography are either non-geometric or non-planar.
● Exception – Image-based rendering.
7
Projections
● Henceforth refer to planar geometric projections as just: projections.● Two classes of projections :
■ Perspective.■ Parallel.
A
B
A
B
A
B
A
B
Centre ofProjection.
Centre of Projectionat infinity
Parallel
Perspective
8
A Taxonomy of projections
Planar geometric projections.
Parallel Perspective
Orthographic Oblique 1 point
2 point
3 point
Axonometric
Isometric
CavalierCabinet
Elevations
9
Perspective projections
● Defined by projection plane and centre of projection.● Visual effect is termed perspective foreshortening.
■ The size of the projection of an object varies inversely with distance from the centre of projection.
■ Similar to a camera - Looks realistic !● Not useful for metric information.
■ Parallel lines do not in general project as parallel.■ Angles only preserved on faces parallel to the projection plane.■ Distances not preserved.
10
Perspective
The first ever painting (Trinity with the Virgin, St. John and Donors) done in perspective by Masaccio, in 1427.
The first ever painting (Trinity with the Virgin, St. John and Donors) done in perspective by Masaccio, in 1427.
11
Perspective projections
• A set of lines not parallel to the projection plane converge at a vanishing point.– Can be thought of in 3D as
the projection of a point at infinity.
– Homogeneous coordinate is 0 (x,y,0)
13
1-point projection
Projection plane cuts 1 axis only.
14
1-point perspective
A painting (The Piazza of St. Mark, Venice) done by Canaletto in 1735-45 in one-point perspective.
15
2-point perspective
y
z x
Projection plane
16
2-point perspective
Painting in two point perspective by Edward Hopper The Mansard Roof 1923 (240 Kb); Watercolor on paper, 13 3/4 x 19 inches; The Brooklyn Museum, New York
17
3-point perspective
Adds little beyond 2-point perspective.
y
z x
Projection plane
A painting (City Night, 1926) by Georgia O'Keefe, that is approximately in three-point perspective.
18
Computing Projection
● How to perform projection in the computer? Or, given a point in 3D, where do I draw it on the 2D computer screen?
● World Coordinate Screen Coordinate● {xw, yw, zw} {xs, ys}
19
Virtual Camera
● Programmer’s reference model for specifying 3D view projection parameters to the computer
● General parameters– position of camera– orientation– field of view (wide angle, normal…)– Focal distance (Will be omitted in our simplified camera model)
– Tilt of view/film plane (for oblique views) (Will be omitted in our simplified camera model)
– depth of field (near distance, far distance)– perspective or parallel projection?
20
View Volume
● Contains everything visible from the view point– Cone-shaped
● Possible shapes of the cone’s cross-section:– Circular: approximates how eyes work
○ Does not fit rectangular viewports○ Expensive math when performing clipping against cone’s surface
– Rectangular: fits windows viewport, easy to clip○ Called the “Frustum”
21
Our Camera Model
22
Position
● From where the camera is looking■ Like a photographer choosing the vantage point to shoot a
photo
● Any 3D point■ The (OpenGL) world’s coordinate system: right hand rule
○ Align right hand fingers with +X axis○ Curl fingers towards +Y axis○ Your thumb points towards +Z axis
P
23
Orientation – Up Vector
● How the camera is rotated around the look vector■ If you are holding the camera horizontally or vertically, or
in between.
● Any 3D vector U = {ux, uy, uz}■ Up-right direction is determined by the projection of U on
the plane normal to L
24
Default Position
● (OpenGL) Camera at origin, looking down –Z axis, and in upright pose
25
Viewing Angle
● Describes the field of view■ Like choosing a specific type of lens, e.g., a wide-angle
lens or telephoto lens
● Width and height angles
26
Viewing Angle (cont.)
● Determines amount of perspective distortion■ Small angles result in near-parallel projectors, hence little
distortion. Example: telephoto lens■ Large angles result in widely varying projectors with large
distortion. Example: wide-angle lens
27
Viewing Angle (cont.)
● Aspect Ratio■ Ratio of width over height of the screen
○ 1:1 (square)○ 4:3 (NTSC)○ 16:9 (HDTV)○ 2.35:1 (Widescreen Films)
● Represent viewing angles as aspect ratio and height angle■ Compute width angle:
28
Clipping Planes
● Restricts visible volume between near and far clipping planes■ Objects outside the frustum are not drawn■ Objects intersecting the frustum are clipped
● Defined as distances dn , df from camera along look vector
29
Clipping Planes (cont.)
● Why do we need near plane■ Avoid drawing things too close to camera
○ They will appear with large distortion, and may block view
■ Avoid drawing things behind the camera○ They will appear upside-down and inside-out
● Why do we need far plane■ Avoid drawing things too far away
○ They will complicate the scene○ They appear small on the screen anyway○ Saving rendering time
30
Perspective Camera Model
● View frustum: a truncated pyramid region that the camera can “see”
● 2D view of 3D frustum can be created by projecting onto a film plane
31
Orthographic Camera Model
● Width and height replaces viewing angles■ Both width angle and height angle are effectively zero
32
Coordinate SystemsObject coordinate systems.
World coordinates.
View Volume
Screen coordinates.
Raster
Transform
Project
Clip
Rasterize
33
Canonical View Volume
34
Canonical View Volume
● Canonical view volume makes things easy:■ Easy clipping: Clip against the coordinates range
−1 ≤ x ≤ 1, −1 ≤ y ≤ 1, 0 ≤ z ≤ 1
■ Easy projecting: drop the z coordinate! (because viewing plane is the xy plane, and projectors are parallel to z axis)
{xc, yc, zc} {xc, yc}
Coordinates in the Projected 2D coordinates
canonical volume
35
Viewing Transform
● For any viewing volume: transform it into the canonical volume!■ The transformation brings the blue box into the red box■ The same transformation brings world coordinates
{xw,yw,zw} into canonical coordinates within the canonical volume {xc,yc,zc}
■ Clip and project
36
Camera Coordinate System
● Three orthogonal axes setting up the camera’s world■ – u (right) v (straight-up) n (negative look)
○ Unit vectors forming an orthonormal basis
■ Observing the right-hand rule
37
Camera Coordinate System
● Computing n■ Opposite to look vector L, normalized
38
Camera Coordinate System
● Computing v■ Projection of up vector U onto the camera plane,
normalized
+
39
Camera Coordinate System
● Computing u
40
CCS - Summary
● Three axes, computed from look vector L and up vector U:
● They are unit vectors● u,v,n follow the right-hand rule
+
+
41
Computing Viewing Transformation
● Two steps■ Step 1: aligning camera coordinate system P,u,v,n with
world coordinate system O,x,y,z■ Step 2: scale and stretch the viewing volume to the cuboid
42
Step 1
● First, translate the eye point P to the origin■ Homogenous coordinates! Easy to compose transformation
as matrix product
43
Step 1 (cont.)
● Rotate the three axes u,v,n to x,y,z■ First, set up the equation to solve for the rotation matrix R:
we know that vectors u,v,n are rotated to three canonical vectors, and the original stays put.
■ In matrix form:
44
Step 1 (cont.)
● Simplify our notation:
● Solve for the rotation matrix■ M is ortho-normal, meaning Therefore,
45
After Step 1
● Eye point at origin, looking down negative z axis
46
Step 2
● Scale the viewing volume to the correct size■ Here is a look down the Y axis■ First, force width/height angle to be right angles
(width=height)○ Scaling in x,y coordinates
Use the Matlab demo
47
Step 2 (cont.)
● Scale the viewing volume to the correct size■ Next, push the far plane to the xy plane at z=-1■ Scaling in all three coordinates■ Thus far plan has the right size but still its Z needs adjustment.
48
Step 2 (cont.)
● Now, the far plane corners are at {±1, ±1, −1}
49
Step 2 (cont.)
● Perspective transformation■ Stretching the truncated pyramid to the cuboid
○ Stretch in XY plane: Non-uniform stretching based on z○ Change Z range:
50
Step 2 (cont.)
51
Step 2 (cont.)
● Perspective transformation■ Stretching the truncated pyramid to the cuboid
○ Stretch in XY plane: Non-uniform stretching based on z○ Change Z range:
Note that far plan is at z=-1 so it will not be scaled, only its Z is adjusted
52
Putting Together
53
Clipping
● After transformation into the canonical volume, each object will be clipped against 6 cuboid faces.■ Point clipping: checking coordinates range
−1 ≤ x ≤ 1, −1 ≤ y ≤ 1, 0 ≤ z ≤ 1■ Edge clipping: computing line/plane intersections
■ Triangle clipping: Need to consider face/face intersections
54
Line Clipping
55
Line Clipping
56
Object Clipping
57
Projecting
● Dropping z coordinate■ Resulting points have range:
−1 ≤ x ≤ 1, −1 ≤ y ≤ 1
58
Viewport Transform
● Get viewport (pixel) coordinates■ Viewport coordinate {0,0} is at top-left corner■ If the viewport is a pixels wide and b pixels high, the pixel
coordinates for a projected point {x,y} is
Thus (-1,1) (0,0) while (1,-1)(a,b)
59
Summary
● To compute projection■ Set up camera parameters■ Compute viewing transformation■ Clipping against the canonical volume■ Projecting to viewport