Download z Q

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
SI23
Introduction to Computer
Graphics
Lecture 12 – 3D Graphics Transformation
Pipeline: Projection and Clipping
Si23_03
12.1
Viewing Pipeline So Far

mod’g
co-ords
From the last lecture, we now should
understand the viewing pipeline
Modelling
Transform’n
world
co-ords
Viewing
Transform’n
viewing
co-ords
Projection
Transform’n
The next stage is the projection transformation….
Si23_03
12.2
Perspective and Parallel
Projection
perspective
Si23_03
parallel
12.3
Puzzle from Earlier Lecture
Si23_03
12.4
Ames Room
Si23_03
12.5
Another Example
Si23_03
12.6
Viewing Co-ordinate System

The viewing transformation has
transformed objects into the viewing
co-ordinate system, where the
camera position is at the origin,
looking along the negative z-direction
yV
zV
camera
camera
direction
Si23_03
xV
12.7
View Volume
yV
zV
camera
near
plane
far
plane
q
xV
dNP
dFP
Si23_03
We determine the view volume by:
- view angle, q
- aspect ratio of viewplane
- distances to near plane dNP and far plane dFP
12.8
Projection
yV
zV
near
plane
camera
xV
dNP
We shall project on to the near plane. Remember this is at
right angles to the zV direction, and has z-coordinate
zNP = - dNP
Si23_03
12.9
Perspective Projection
Calculation
zV
yV
near
plane
camera
zNP
xV
looking down x-axis towards
the origin
dNP
Q
yV
zV
camera
zNP
zQ
view plane
Si23_03
12.10
Perspective Projection
Calculation
Q
yV
zV
camera
P
zNP
zQ
view plane
By similar triangles,
yP / yQ = ( - zNP) / ( - zQ)
and so
yP = yQ * (- zNP) / ( - zQ)
or
yP = yQ * dNP / ( - zQ)
Si23_03
Similarly for the
x-coordinate of P:
xP = xQ * dNP / ( - zQ)
12.11
Using Matrices and
Homogeneous Co-ordinates
We can express the perspective
transformation in matrix form
 Point Q in homogeneous coordinates
is (xQ, yQ, zQ, 1)
 We shall generate a point H in
homogeneous co-ordinates (xH, yH, zH,
wH), where wH is not 1
 But the point (xH/wH, yH/wH, zH/wH, 1) is
the same as H in homogeneous space
 This gives us the point P in 3D space, ie
xP = xH/wH, sim’ly for yP

Si23_03
12.12
Transformation Matrix for
Perspective
1
0
0
0
xQ
yH
0
1
0
0
yQ
zH
0
0
1
0
zQ
wH
0
0 -1/dNP
0
1
xH
=
Thus in Homogeneous co-ordinates:
xH = xQ; yH = yQ; zH = zQ; wH = (-1/dNP)zQ
Si23_03
In Cartesian co-ordinates:
xP = xH / wH = xQ*dNP/(-zQ);
yP similar;
zP = -dNP = zNP
12.13
OpenGL

Perspective projection achieved by:
gluPerspective (angle_of_view,
aspect_ratio, near, far)
– aspect ratio is width/height
– near and far are positive distances
Si23_03
12.14
Vanishing Points

When a 3D object is projected onto a
view plane using perspective, parallel
lines in object NOT parallel to the view
plane converge to a vanishing point
vanishing point
one-point
perspective
projection
of cube
view plane
Si23_03
12.15
One- and Two-Point
Perspective Drawing
Si23_03
12.16
One-point Perspective
This is:
Trinity with the Virgin,
St John and Donors,
by Mastaccio in 1427
Said to be the first
painting in perspective
Si23_03
12.17
Two-point Perspective
Edward
Hopper
Lighthouse
at Two Lights
-see
www.postershop.com
Si23_03
12.18
Parallel Projection - Two types

Orthographic parallel
projection has view
plane perpendicular to
direction of projection

P1
P2
Oblique parallel
projection has view plane
at an oblique angle to
direction of projection
P1
P2
view plane
Si23_03
We shall only consider orthographic projection
view plane
12.19
Parallel Projection Calculation
zV
yV
near
plane
looking down x-axis
xV
dNP
yV
zV
Si23_03
yP = y Q
similarly xP= xQ
P
zNP
Q
zQ
view plane
12.20
Parallel Projection Calculation

So this is much easier than
perspective!
– xP = xQ
– yP = yQ
– zP = zNP

The transformation matrix is simply
1
0
0
0
Si23_03
0
1
0
0
0
0
0
0
zNP/zQ 0
0
1
12.21
Clipping
Si23_03
12.22
View Frustum and Clipping
yV
zV
camera
near
plane
far
plane
q
xV
dNP
dFP
The view volume is a frustum in viewing co-ordinates - we need to
be able to clip objects outside of this region
Si23_03
12.23
Clipping to View Frustum
It is quite easy to clip lines to the front and
back planes (just clip in z)..
 .. but it is difficult to clip to the sides
because they are ‘sloping’ planes
 Instead we carry out the projection first
which converts the frustum to a
rectangular parallelepiped (ie a cuboid)

Retain the
Z-coord
Si23_03
12.24
Clipping for Parallel Projection

In the parallel projection case, the
viewing volume is already a
rectangular parallelepiped
far
plane
view volume
near
plane
Si23_03
zV
12.25
Normalized Projection
Co-ordinates

Final step before clipping is to
normalize the co-ordinates of the
rectangular parallelepiped to some
standard shape
– for example, in some systems, it is the
cube with limits +1 and -1 in each
direction
This is just a scale transformation
 Clipping is then carried out against this
standard shape

Si23_03
12.26
Viewing Pipeline So Far

mod’g
co-ords
Si23_03
Our pipeline now looks like:
world
co-ords
NORMALIZATION
TRANSFORMATION
view’g
co-ords
proj’n
co-ords
normalized
projection
co-ordinates
12.27
Viewport Transformation
Si23_03
12.28
And finally...
The last step is to position the picture
on the display surface
 This is done by a viewport
transformation where the normalized
projection co-ordinates are
transformed to display co-ordinates, ie
pixels on the screen

Si23_03
12.29
Viewing Pipeline - The End

mod’g
co-ords
A final viewing pipeline is therefore:
world
co-ords
normalized
projection
co-ordinates
Si23_03
view’g
co-ords
proj’n
co-ords
device
co-ordinates
DEVICE
TRANSFORMATION
12.30