Title: SI31 Advanced Computer Graphics AGR
1SI31Advanced Computer GraphicsAGR
- Lecture 4
- Projection
- Clipping
- Viewport Transformation
2Interlude
- Why does a mirror reflect left-right and not
up-down?
3 4Viewing 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
5View Volume
yV
zV
near plane
far plane
camera
q
xV
dFP
We determine the view volume by - view angle,
q - aspect ratio of viewplane - distances to near
plane dNP and far plane dFP
6Projection
We shall project on to the near plane. Remember
this is at right angles to the zV direction, and
has z-coordinate zNP - dNP
7Perspective Projection Calculation
zNP
looking down x-axis towards the origin
8Perspective Projection Calculation
P
By similar triangles, yP / yQ ( - zNP) / ( -
zQ) and so yP yQ (- zNP) / ( - zQ) or yP yQ
dNP / ( - zQ)
Similarly for the x-coordinate of P xP xQ
dNP / ( - zQ)
9Using 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, simly for yP
10Transformation Matrix for Perspective
Thus in Homogeneous co-ordinates xH xQ yH
yQ zH zQ wH (-1/dNP)zQ
In Cartesian co-ordinates xP xH / wH
xQdNP/(-zQ) yP similar zP -dNP zNP
11Exercises
- Suppose the camera is not at the origin, but at
point zC - Calculate the formulae for perspective projection
and work out the resulting transformation matrix
in homogeneous co-ordinates - In practice the perspective division is delayed -
why might this be done? -what useful information
is lost?
12OpenGL
- Perspective projection achieved by
- gluPerspective (angle_of_view, aspect_ratio,
near, far) - aspect ratio is width/height
- near and far are positive distances
13Vanishing 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
14One- and Two-Point Perspective Drawing
15One-point Perspective
This is Trinity with the Virgin, St John and
Donors, by Mastaccio in 1427
Said to be the first painting in perspective
16Two-point Perspective
Edward Hopper Lighthouse at Two
Lights -see www.postershop.com
17Parallel Projection - Two types
- Orthographic parallel projection has view plane
perpendicular to direction of projection
- Oblique parallel projection has view plane at an
oblique angle to direction of projection
P1
P1
P2
P2
view plane
view plane
We shall only consider orthographic projection
18Parallel Projection Calculation
looking down x-axis
Q
P
yV
zQ
zNP
zV
view plane
yP yQ similarly xP xQ
19Parallel Projection Calculation
- So this is much easier than perspective!
- xP xQ
- yP yQ
- zP zNP
- The transformation matrix is simply
1 0 0 0 0 1 0 0 0
0 zNP/zQ 0 0 0 0 1
20 21View Frustum and Clipping
yV
zV
near plane
far plane
camera
q
xV
dFP
The view volume is a frustum in viewing
co-ordinates - we need to be able to clip objects
outside of this region
22Clipping 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)
23Clipping for Parallel Projection
- In the parallel projection case, the viewing
volume is already a rectangular parallelepiped
far plane
view volume
near plane
zV
24Normalized 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
25Viewing Pipeline So Far
- Our pipeline now looks like
NORMALIZATIONTRANSFORMATION
26 27And 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
28Viewing Pipeline - The End
- A final viewing pipeline is therefore
device co-ordinates
DEVICETRANSFORMATION