CS计算机代考程序代写 Viewing Transform

Viewing Transform
1

Intended Learning Outcomes
 Able to set up a camera coordinate system
 Understand the properties of different projection
methods
 Able to set up the required projection matrices and use
appropriate OpenGL commands to realize the projection
 Describe the operation and function of clipping
2

Image generation process
 A camera has its own coordinate system X(VC)-Y(VC)-Z(VC), called the viewer coordinate system
 viewer coordinate system is alternatively called camera coordinate system
 To generate an image, we first need to define a camera, then transforming the 3D scene from world coordinate system (WC) to viewing coordinate system (VC)
X(WC)-Y(WC)-Z(WC) → X(VC)-Y(VC)-Z(VC)
 Then projecting each point to a view plane
3

To specify a viewer coordinate system, we need to specify three vectors
 View Reference Point (VRP): origin of the viewing coordinate system (i.e. physical location of the camera)
 View Plane Normal (VPN): a vector giving the pointing direction of the camera (i.e. +ve Z(VC) axis of the camera
X(VC)-Y(VC)-Z(VC))
 View UP Vector (VUP) : a vector defining what is the upward direction for the film (image)
 Note 1: These vectors do not need to be unit vector
 Note 2: These vectors are in WC
4

YVC
VUP
VUP lies on the upper ZVC – YVC plane
VPN VRP ZVC = |VPN|
ZVC
XVC =|VUPXVPN|
XVC
(unit vector in WC) (unitvectorinWC) (unit vector in WC)
YVC = ZVC × XVC
Note: | | is used in the notes to denote normalization to unit vector
5

Transformation from WC to VC
 P(VC) = MVC←WC P(WC)
 Applying coordinate system transformation method 1:
−1 VRP

X Y
Z
 Note: XVC, YVC, ZVC are unit column vector in WC
MVC←WC = VC VC 
VC  0 0 0 1
6

OpenGL commands
 glMatrixMode (GL_MODELVIEW);
 gluLookAt (x0, y0, z0, xref, yref, zref, Vx, Vy, Vz);
 VRP = (x0, y0, z0)
 VPN = (x0, y0, z0) – (xref, yref, zref)
 VUP = (Vx, Vy, Vz)
 To remember this, it is convenient to remember (x0, y0, z0) as where the camera is placed, (xref, yref, zref) as where the center of the scene is, and (Vx, Vy, Vz) as a vector that tells where it’s up for the camera
7

View Plane
 Also called projection plane or image plane
 It is usually a plane defined by ZVC = constant, i.e.,
parallel to the XVC – YVC plane
 As the name implies, a 3D point (X, Y, Z) in viewer coordinates is projected to a 2D point lying on the view plane
 i.e. 3D becomes 2D
8

Projections : project (X, Y, Z)(VC) to (x, y)(VC)
 Two general types: Parallel and Perspective Projections Parallel projection Perspective projection
all light rays are parallel
all light rays converge on a common point called projection reference point (PRP)
Parallel projection can be considered as the special case of perspective projection when PRP = ∞
9

Different properties
Parallel projection
coordinate positions are transformed to the projection plane along // lines
i.e. center of projection at infinity
preserves relative proportions use in engineering drafting
Perspective Projection
coordinate positions are transformed to the projection plane along lines that converge to a point called the center of projection (Projection Reference Point)
does not preserve use in realistic views
10

Parallel Projections
 Specify a projection vector – a direction vector  Two types:
 Orthographic projection – projection vector ⊥ projection plane
 Oblique projection – projection vector not ⊥ to projection plane
11

Orthographic Projection (α = 90o)
 

 
Two types:
Front elevation, side elevation, rear elevation, plan view – only X-Y, X-Z or Y-Z is shown
Isometric projection – projection vector = (±1, ±1, ±1)
For a cube, each side will be displayed equally
The 8 possibilities corresponds to viewing in the 8 octants
12

Front elevation, side elevation, rear elevation, plan view
front elevation view
13

Isometric projection
14

Oblique Projection (α ≠ 90o)  Two types:
 Cavalier projection – projection vector makes an angle α
of tan-11 with projection plane
 for a cube, length of X axis, Y axis and Z axis will remain the same
 Cabinet projection – projection vector makes an angle α
of tan-12 with projection plane
 for a cube, length of X axis, Y axis will remain the same; length of Z axis will be halved.
15

Cavalier Projection
Cabinet Projection
16

Projection
Parallel Perspective
Orthographic Oblique
Front elevation, Isometric Cavalier Cabinet side elevation, …
17

4 x 4 Transform for Parallel Projection
P(VC) = (X, Y, Z)
P(im) = (xp, yp, zvp)
(xp, yp, zVP)
α
Projection Vector Vp=(Vpx, Vpy, Vpz)
Z = zvp (x, y, zVP)
zvp is a constant
All quantities in this slide are already in VC
View plane
(X, Y, Z)
α = 90o Orthographic projection α ≠ 90o Oblique projection 18
(X, Y) = (x, y)

By similar triangles,
xp −X=Vpx zvp−Z Vpz
yp −Y =Vpy zvp−Z Vpz
Rearranging,
xp =X+(zvp −Z)Vpx
(1)
Vpz
yp =Y+(zvp −Z)Vpy Vpz
19

P(im) =(xp,yp,zvp,1) P(VC) =(X,Y,Z,1)  P(im) = Mparallel P(VC)
 Vpx 1 0 −V
Vpx  zvpV 
Vpz  Mparallel =0 1 − py zvp py 
 Vpz
 Vpz Vpz  000 zvp 000 1
20

 Verify that the first two rows implement eqn (1) above
 The third row is such that the projected point is at Z = zvp. However, this is not maintained; in OpenGL, p(im) = (xp, yp, Z), i.e. the original Z is kept for depth tests
 Third row of eqn (10-13), pg. 350 of text is set to
0 0 1 0, which achieves the same effect as maintaining the original Z.
21

Perspective Projection
 ALL light rays goes through the Projection Reference Point (PRP), also called center of projection.
22

(X, Y, Z)
(xp, yp, zVP)
View plane Z = zvp
PRP
23

Example:
i) PRP = VRP
ii) Z = zvp is the view plane
By similar triangles,
zxp =XZ zyp =YZ vp vp
Multiplying each side by zvp yields xp=zvp⋅X= X (2)
Z Z / zvp
yp=zvp⋅Y= Y
Z Z / zvp
24

P(VC) =(X,Y,Z,1)
 P(im) = Mperspective P(VC)
1 0 0 0 0 1 0 0
M perspective = 0 0 1 0
0 0 1/zvp 0 
25

 Verify that the first two rows and the fourth row implements eqn (2) above using homogeneous coordinates operation
 Note that the fourth row is not 0 0 0 1 anymore
 The third row is such that the projected point is at Z = zvp. However, this is not maintained; in OpenGL, p(im) = (xp, yp, Z), i.e. the original Z is kept for depth tests
26

Clipping
 Any object not within the clipping volume does not need to be processed – this eliminates most of the objects at one go
 For a convex clipping volume bounded by planes, one can check whether a point is inside by checking the signs of the plane equations (see Lecture 2).
27

OpenGL – first set matrix mode
 glMatrixMode (GL_PROJECTION);
 Note: GL_PROJECTION is used as it deals with projection
 There are two 4 x 4 composite transformation matrices: GL_MODELVIEW and GL_PROJECTION
 A point is pre-multiplied by [GL_PROJECTION] [GL_MODELVIEW]
 glOrtho and gluPerspective commands may be used
28

OpenGL – Orthographic projection
 glOrtho (xwmin, xwmax, ywmin, ywmax, dnear, dfar)
 Projection vector Vp = (0, 0, 1)
 Clipping planes: Z = -dnear Z = -dfar
 Near clipping plane Z = -dnear also serve as the view plane
 Only points whose X and Y are in |xwmin, xwmax| and |ywmin, ywmax| respestively are displayed
 Clipping volume is a rectangular box
29

Z = -dnear
Z = -dfar
(xwmin, ywmin, -dnear)
(xwmax – xwmin)
(ywmax – ywmin)
Only objects inside the rectangular shaped clipping volume is further processed
30

OpenGL – Perspective projection  gluPerspective (theta, aspect, dnear, dfar)
 PRP = VRP
 Z = -dnear is the view plane (note the –ve sign)
 dnear and dfar define the near and far clipping planes Z = -dnear and Z = -dfar respectively
 theta is the angle of view
 aspect = (width /height)
 theta and aspect together determines size of image window
 clipping volume is a frustum 31

Z = -dnear
Z = -dfar
θ
VRP
aspect = width /height of the blue plane
Only objects inside the frustum shaped clipping volume is further processed 32

References
 Text : Ch. 10.2–10.7 discusses the viewing transform and the various types of projection
 Text : Ch. 10.8 discusses general perspective projection and then discusses the special case. We only discuss the special case here
 Text : Ch. 10.9–10.10 discusses the OpenGL commands
33