3D Viewing - PowerPoint PPT Presentation

1 / 52
About This Presentation
Title:

3D Viewing

Description:

... by {l, r, b, t, n, f} which stands for {left, right, bottom, top, near, far} ... from the box view volume into CVV, or from EC to clip coordinates (CC) ... – PowerPoint PPT presentation

Number of Views:69
Avg rating:3.0/5.0
Slides: 53
Provided by: nichol6
Category:
Tags: cc | does | for | stand | viewing | what

less

Transcript and Presenter's Notes

Title: 3D Viewing


1
3D Viewing
2
Viewing Specification Eye Coordinates
  • Suppose that modeling transformation has been
    done and now all objects are in WC.
  • We need viewing specification or camera
    information.
  • VRP view reference point or eye position.
  • AT a reference point for objects. (AT is a
    reference point toward which the eye is aimed. AT
    is typically somewhere in the middle of the
    scene.)
  • VUP view up vector.
  • VPN view plane normal. (orientation of
    projection point) VRP-AT
  • VRP, u, v, n defines eye coordinates (EC),
    which is also called camera coordinates or view
    coordinates.
  • In EC, camera is at the origin and looks in the
    n direction.

y
y
VUP
v
VRP
AT
u
n
z
z
x
x
VRP
3
Eye Coordinates Teapot Example
  • Lets focus on the teapot centered at WC.

v
u
n
VRP
4
Viewing Transformation
  • We have two coordinates WCO,x,y,z and
    ECVRP,u,v,n.
  • Lets superimpose EC onto WC a translation
    followed by a rotation.
  • Such a transformation (which is a rigid motion)
    simply reinterprets the model from WC into EC,
    and is called viewing transformation.

y
v
u
VRP
n
x
z
5
Viewing Transformation (contd)
  • viewing transformation in a single 4x4 matrix
  • Why from WC to EC? Its for easy projection and
    clipping. You will see pretty soon!
  • Modeling and viewing transformations are often
    combined into a matrix Mmodelview.

viewing transformation
modeling transformation
in WC
in EC
in LC
modelview transformation
in LC
in EC
6
View Volume
  • Thanks to the viewing transformation, all
    vertices are newly defined in ECVRP,u,v,n, and
    we can forget about the WCO,x,y,z.
  • Then, lets use x,y,z and u,v,n
    interchangeably because we are familiar with
    x,y,z.
  • Suppose a huge scene. In general, we cannot see
    all objects in the scene. We need to specify how
    much of the scene we can see. View volume does it.


7
Perspective View Volume
  • We can imagine a window through which we can see
    the world.
  • The window is parallel to xy-plane.
  • Then, for perspective projection, the output
    image is made by the projectors (from COP) that
    pass through the window.
  • Such a perspective view volume makes an infinite
    pyramid.
  • We can bound near and far sides of the infinite
    pyramid.
  • The perspective view volume makes a truncated
    pyramid, frustum.
  • Only the objects inside the frustum are visible.

y
COP
window
z
x
window
near plane
far plane
COP
8
Perspective View Volume (contd)
  • The frustum is defined by l, r, b, t, n, f
    which stands for left, right, bottom, top, near,
    far. We set n and f to be positive such that
    they are the perpendicular distances from COP to
    the two planes.
  • Note that the pyramid is not upright, which is
    unrealizable in the camera model but is useful
    for simulating human stereo vision, etc.
  • We can find that the vector connecting VRP and AT
    is not really the viewing direction. The vector
    is for establishing z-axis of EC.
  • Note that window is implicitly defined through
    the near plane.

-z
z -f
y
far plane
near plane
(r, t, -n)
COP
x
(l, b, -n)
z
9
Viewing Examples Model and EC
  • Given the model in the figure, suppose that
    VRP(0,0,40), AT(0,0,0), and VUP(0,10,0).
  • Lets see some view volume examples with this
    model.

y
10
VUP
vy10
-n-z
AT
10
x
vy
v
20
-20
30
-10
ux10
COP
u
ux
z40
z
n
nz
10
Perspective Projection Example I
(60, 60, -40)
  • ? example 1
  • We got the following image, where the viewport
    corresponds to the view volumes window.

60
l 0, r 6 b 0, t 6 n 4, f 40
far plane
40
20
y10
viewport
x10
20
40
60
near plane
-20
(r, t, -n) (6, 6, -4)
COP
(l, b, -n) (0, 0, -4)
11
Perspective Projection Example II
(60, 60, -40)
  • example 2
  • What if the window size is reduced by 1/4?
  • We got the following image.

60
l 0, r 3 b 0, t 3 n 4, f 40
40
(30, 30, -40)
20
viewport
20
40
60
-20
(6, 6, -4)
COP
(3, 3, -4)
12
Perspective Projection Example III
(60, 60, -40)
60
  • example 3
  • What if the far plane moves towards COP?
  • ? We got the following image.

l 0, r 6 b 0, t 6 n 4, f 15
40
20
viewport
20
40
60
-20
(6, 6, -4)
COP
13
Parallel Projection Oblique vs. Orthographic
  • Recall that view plane and window are parallel to
    xy-plane.
  • Lets consider the cross-section of EC (seen
    along y direction).
  • Orthographic projection is a special parallel
    projection where the view plane is orthogonal to
    DOP.
  • Dont get confused with parallel projection
    where COP is at ? and COP as EC origin. COP is
    basically for defining EC, and the parallel
    projection is inherently unrealistic.

x
  • ? perspective
  • ? parallel
  • - orthographic
  • - oblique

z
Assuming the DOP is parallel to xz-plane.
x
x
x
DOP
DOP
DOP
z
orthographic
oblique
z
z
14
Parallel View Volume
  • In parallel projection, the view volume is an
    infinite parallelepiped (not necessarily a box),
    which is parallel to DOP.
  • We can also bound near and far sides of the
    infinite parallelepiped to make the parallel view
    volume. (Imagine that the window slides along DOP
    to make both planes.)
  • Only the objects inside the view volume are
    visible.

window
near plane
far plane
15
Parallel View Volume (contd)
  • Oblique projection is much less common, and so
    lets consider only orthographic projection where
    DOP is orthogonal to the view plane.
  • Note that DOP is along the z-axis.
  • Then, the view volume has to be aligned with
    xyz-axes.
  • Two end points in a diagonal are enough to define
    the view volume.
  • As in the perspective projection, we set n and f
    to be positive.
  • Note that the view volume is defined by l, r, b,
    t, n, f for both perspective projection and
    orthographic projection. Of course, the set l,
    r, b, t, n, f has different semantics in the two
    cases.

(r, t, -f)
DOP
y
parallel view volume
(l, b, -n)
x
z
16
Orthographic Projection Examples
  • Lets use the same example.
  • example 2

l 0, r 20 b 0, t 20 n 15, f 40
  • example 3

l 5, r 20 b 5, t 20 n 15, f 40
  • example 4
  • example 1

l 5, r 20 b 5, t 20 n 25, f 40
l 0, r 20 b 0, t 20 n 4, f 40
17
Culling Clipping
  • Where are we now?
  • Objects are defined in EC through modeling and
    viewing transformations.
  • Projection type (parallel or perspective) is
    specified.
  • View volume is given as l, r, b, t, n, f in EC.
  • The view volume specifies how much of the scene
    we can see. So, polygons completely inside the
    view volume are processed for display.
  • How about the scene outside the view volume?
  • Polygons completely outside the view volume are
    culled.
  • Polygons intersecting the boundary of the view
    volume are clipped against the boundary, and then
    processed for display.

18
Clipping Teapot Example
  • Suppose that, in orthographic projection, we have
    a view volume intersecting the teapot.

clipped polygon mesh to be rendered
19
Projection Transformation
  • OK, we just specified the view volume l, r, b,
    t, n, f in EC. The next step is projection
    transformation.
  • Lets first tackle the orthographic projection.
  • Operations such as clipping can be easily
    implemented in canonical view volume(CVV), which
    is defined as a 2x2x2 cube with its center at the
    origin, i.e. xyz-1,1.
  • Projection transformation or specifically
    orthographic transformation transforms the box
    view volume into CVV.

20
Projection Transformation (contd)
  • Obviously we need scaling. However, scaling is
    about origin.
  • As the 1st step, lets translate the view
    volumes center to the origin.
  • We know that the view volumes center is
    ((lr)/2,(bt)/2,-(nf )/2)).
  • So, the translation is Tpar T(-(lr)/2,-(bt)/2,
    (nf )/2))

y
x-1,1 y-1,1 z-1,1
xl,r yb,t z-n,-f
x
z
y
x
Tpar makes ?
z
21
Projection Transformation (contd)
  • Note that the CVV has the size of 2x2x2. So,
    lets scale!
  • Width along x r - l should be scaled into 2.
  • So, scaling factor along x direction Sx 2/(r-l)
  • Similarly, Sy 2/(t-b) and Sz 2/(f-n)
  • MorthoSpar Tpar is the orthographic
    (projection) transformation from the box view
    volume into CVV, or from EC to clip coordinates
    (CC).
  • After orthographic transformation, clipping is
    done. Then, the clipped model is within CVV whose
    dimensions are all 1 along ?x/?y/?z axes. Its
    called that the model is in normalized device
    coordinates(NDC).
  • Some people say we have a 3D film (generated by
    projection).

y
x
z
r - l
22
Projection Transformation (contd)
  • Orthographic transformation with teapot example.

v
u
n
translation
scaling
CVV in NDC
23
Projection Transformation (contd)
  • Given l, r, b, t, n, f, the orthographic
    transformation Mortho is computed as Spar Tpar.
  • Mortho can be simply rewritten as follows.

x? (2/(r-l))x - (rl)/(r-l) y? (2/(t-b))y -
(tb)/(t-b) z? (2/(f-n))z (fn)/(f-n)
24
Projection Transformation (contd)
  • Some systems such as OpenGL use -z direction (0 0
    -1) as DOP. (Compare this with positive-z
    projection direction in EC.) For this purpose, 3D
    reflection is required.

reflection wrt xy-plane
25
Window Coordinates and Viewport
  • A window at your screen (not the window
    associated with the view volume) is associated
    with window coordinates (WdC).
  • A viewport is defined at WdC.
  • The viewport is not necessarily the entire
    window, and is defined by its lower left corner
    (xmin ymin), width, and height.
  • Viewport transformation transforms the x- and
    y-coordinates of CVV to coincide with the
    viewport.

viewport
window
height
(xmin,ymin)
width
26
Viewport Transformation
  • The viewport transformation is a scaling followed
    by a translation.
  • For scaling, Sxwidth/2 and Syheight/2.
  • Translation moves the center at the origin to the
    viewport center (ox,oy)(xminwidth/2,
    yminheight/2).
  • So, Mviewport T(ox,oy,0) S(Sx, Sy,1). Simply,
    x?x(width/2)ox and y?y(height/2)oy. Dont
    do matrix multiplication.

translation
scaling
27
Viewport Transformation (contd)
  • WdC is 3D. WdC is also called 3D screen
    coordinates.
  • In some systems such as OpenGL, Mviewport encodes
    z-coordinates. However, we simply preserve the
    z-coordinates. Either way, the z-coordinates are
    necessary for hidden line/surface removal, etc.
    You will see soon. Be patient. ?
  • In sumary, Mviewport Mortho Mmodelview
    transforms an LC point into WdC. All done!!!!

viewport
y

oy
Mviewport
ymin
x
ox
z
xmin
28
Viewport Transformation (contd)
  • Viewport transformation with teapot example
  • Final images

CVV
29
Orthographic Projection Summary
  • The modeling transformation moves from LC to WC.
  • Viewing specifies the location/orientation of the
    viewer or camera, and viewing transformation
    moves from WC to EC.
  • The two transformations are combined into
    Mmodelview.
  • The view volume is defined by l, r, b, t, n, f.
  • The orthographic transformation Mortho changes
    the view volume into CVV. Its said the model is
    then in clip coordinates(CC).
  • Clipping is done.
  • The viewport transformation Mviewport transforms
    vertices in CVV into 3D points in WdC.

orthographic transformation
modeling viewing transformation
in EC
in LC
viewport transformation
in CC
in WdC
clipping
in NDC
30
Projection Transformation for Perspective
Projection
  • Now, lets tackle the perspective projection
  • Note that the modelview transformation does not
    depend on the projection type. What distinguishes
    the perspective projection from the parallel
    projection is the projection transformation.
  • Perspective projection transformation from the
    frustum to CVV.
  • It is often simply called a perspective
    transformation.

-z
z-f
y
far plane
(r, t, -n)
near plane
COP
x
(l, b, -n)
z
31
3D Shearing
  • Lets see the frustum along -y direction
  • So, shearing along x is needed. OK, but is that
    it? No

-z
z-f
y
far plane
(r, t, -n)
near plane
COP
x
(l, b, -n)
z
32
3D Shearing (contd)
y
  • Similarly, let us see along -x.
  • H?xy(p,q) makes the vector CC, which connects COP
    and the near planes center ((lr)/2, (bt)/2,
    -n), be (0, 0, -n).

-z
-z
z-f
y
far plane
near plane
(r, t, -n)
COP
x
(l, b, -n)
z
xpz
x
0
p
0
1
H?xy(p,q)
in summary z unaffected x? x pz y? y qz
yqz
y
0
q
1
0

z
z
0
1
0
0
1
1
1
0
0
0
33
3D Shearing (contd)
  • Lets compute p and q.
  • If the frustum happens to be upright, CCxCCy0,
    and so pq0, which means that H?xy(p,q) I and
    shearing has no effect.

CC near-plane-center - COP
should be
34
Understanding 3D Shearing
  • Shear a coordinate value with respect to another
    coordinate.
  • Six basic shearing matrices Hxy(s), Hxz(s),
    Hyx(s), Hyz(s), Hzx(s), and Hzy(s).
  • Commonly used is shearing two coordinates values
    wrt the remaining.
  • Determinant of any shearing matrix H1, and so
    shearing is volume-preserving. (No scaling!)

35
Shearing followed by Scaling
  • 3D shearing has made the skewed frustum upright.
  • Now, lets make the frustums side faces be of
    45 slope.
  • Such a task can be performed by scaling.

y
y
y
To be done!
45
Done!
-z
-z
-z
original frustum
upright frustum
45-slope frustum
36
Scaling
  • Note that shearing does not change the size of
    the near plane.
  • Both (r-l)/2 and (t-b)/2 should be the same as n
    for making a 45-slope frustum. We then need
    scaling!
  • Sx n/(r-l)/2 2n/(r-l)
  • Sy n/(t-b)/2 2n/(t-b)
  • Sz 1.

(r-l)/2
-z
y
(t-b)/2
near plane
n
x
COP
z
37
Shearing Scaling Teapot Example
scaling
shearing
38
Distortion
  • From the 45 frustum into CVV Lets represent
    (x2 y2 z2) in terms of (x1 y1 z1).


y
p
-z1
y
z-f
1
n
(x1,y1,z1)
(x2,y2,z2)
z
z
1
-1
z1
-n
z-n
-1
The point p (whose y value is -z1) should go to
y1. ? -z11 y1 y2 ? y2 -y1/z1 Similarly,
x2 -x1/z1
39
Distortion (contd)
  • We found that x2 -x1/z1 and y2 -y1/z1 .
  • How about z2?
  • Note that a triangle in the frustum should be
    transformed also into a triangle in CVV.
  • The triangle in CVV is on a plane axbyczd0.
  • and so
  • OK, we found that z2AB/z1.
  • Lets compute A and B.

should be for the formula to be planar
plane
40
Distortion (contd)
  • Lets compute A and B for z2AB/z1.
  • Note that z1-f, -n and z2-1,1.
  • So, if z1 -f, then z2 -1. Similarly, if z1 -n,
    then z21.
  • Solving the two equations, we get A(nf)/(n-f)
    and B2nf/(n-f).
  • (x2 y2 z2 1) (-x1/z1 -y1/z1 AB/z1 1)
    (x1 y1 -Az1-B -z1)
  • Multiplying every component by -z1, we can
    represent the distortion transformation by a
    matrix multiplication.
  • Its possible thanks to homogeneous coordinate
    system.

called Mdistort
not (0 0 0 1) !!
41
Why called Distortion?
  • Mdistort distorts the model, and is not affine in
    the sense that parallelism is not preserved.
  • Distortion transformation moves COP to the ?
    position of z-axis.
  • The model is distorted, but leads to a correct
    image as we are now in (orthographic) CVV.

into CVV
model distortion
42
Distortion Teapot Example
43
Perspective Division
  • In homogeneous coordinates, each vertex should be
    divided by its w-component to get a corresponding
    Cartesian coordinates.
  • Its called perspective division.
  • An example
  • n1
  • f2

A(nf)/(n-f) B2nf/(n-f).
y
Q(0 3/2 3/2)
Q?(0 1 -1/3)
P?(0 1 1)
3/2 1 1/2
P(0 1 -1)
-z
-2
R(0 1/2 3/2)
R?(0 1/3 -1/3)
44
Perspective Division (contd)
  • The distortion transformation converts (x y z 1)
    into (x y -Az-B -z), and the perspective division
    is done by w-z, which actually represents the
    distance from the eye.
  • As the distance from the eye increases, 1/w
    approaches 0, and so x/w and y/w also approach 0.
    This is how foreshortening is achieved.

a
b
model distortion
b
a
45
Perspective Division (contd)
  • Observe that Q and R are at the center of the
    frustum along z-axis but Q? and R? are not at
    the center of CVV.
  • As the transformed z-coordinates move farther
    away from the near plane, the locations become
    increasingly less precise. Such a non-linearity
    caused by perspective division leads to some
    problem for hidden-surface removal. Lets revisit
    this later.

Q?(0 1 -1/3)
y
Q(0 3/2 3/2)
P?(0 1 1)
3/2 1 1/2
P(0 1 -1)
-z
-2
R(0 1/2 3/2)
R?(0 1/3 -1/3)
46
Perspective Transformation
  • Below are the steps we have followed.
  • The perspective transformation MpersMdistortSper
    s H?xy(p,q) transforms the perspective view
    volume into CVV.
  • We could do clipping after perspective
    transformation perspective division are done.
  • Mmodelview ? Mpers ? perspective division ?
    Mviewporttransforms an LC point into WdC. We
    already derived Mviewport and Mmodelview. All
    done!!!!

y
y
y
y
45
H?xy(p,q)
Mdistort
Spers
-z
-z
-z
-z
45-slope frustum
upright frustum
original frustum
CVV
47
Perspective Transformation (contd)
  • Perspective transformation Mpers
    MdistortSpers H?xy(p,q)
  • Given l, r, b, t, n, f, Mpers is computed as
    follows

x? (2n/(r-l))x ((rl)/(r-l))z y?
(2n/(t-b))y ((tb)/(t-b))z z?
-((nf)/(n-f))z - 2nf/(n-f) w? -z
48
Perspective Transformation (contd)
  • As we discussed in orthographic transformation,
    some systems such as OpenGL includes 3D
    reflection for perspective transformation.

49
Perspective Transformation (contd)
  • A 3D affine transformation is represented by a
    3x4 matrix, where its 3x3 sub-matrix is for
    linear transformation and the 4th column is for
    translation. The 4th row is just (0 0 0 1).
  • Perspective transformations 4th row is not any
    more (0 0 0 1), and is not an affine
    transformation.
  • However, orthographic projection is an affine
    transformation.

50
Viewport Transformation Teapot Example
  • Viewport transformation for perspective
    projection is same as that for orthographic
    projection.
  • Final images

CVV
51
Perspective Projection Summary
  • The modeling transformation moves from LC to WC.
  • Viewing specifies the location/orientation of the
    viewer or camera, and viewing transformation
    moves from WC to EC.
  • The two transformations are combined into
    Mmodelview.
  • The frustum is defined by l, r, b, t, n, f.
  • The perspective transformation Mpers transforms
    the perspective view volume into (parallel) CVV.
  • Do clipping and then perspective division. (We
    will see.)
  • Finally, the viewport transformation Mviewport
    transforms vertices in CVV into 3D points in WdC.

projection transformation
modeling viewing transformation
in EC
in CC
in LC
perspective division
viewport transformation
in CC
clipping
in WdC
in NDC
52
Orthographic Projection vs. Perspective Projection
orthographic projection
modeling viewing transformation
viewport transformation
orthographic transformation
WdC
clipping
LC
EC
NDC
CC
perspective division
perspective transformation
clipping
CC
CC
perspective projection
Write a Comment
User Comments (0)
About PowerShow.com