Upload
rafe-davis
View
231
Download
0
Embed Size (px)
Citation preview
12.1Si23_03
SI23Introduction to Computer
Graphics
SI23Introduction to Computer
Graphics
Lecture 12 – 3D Graphics Transformation Pipeline: Projection and Clipping
12.2Si23_03
Viewing Pipeline So FarViewing Pipeline So Far
From the last lecture, we now should understand the viewing pipeline
mod’gco-ords
worldco-ords
viewingco-ords
ModellingTransform’n
ViewingTransform’n
The next stage is the projection transformation….
ProjectionTransform’n
12.3Si23_03
Perspective and Parallel Projection
Perspective and Parallel Projection
perspective parallel
12.4Si23_03
Puzzle from Earlier Lecture
Puzzle from Earlier Lecture
12.5Si23_03
Ames RoomAmes Room
12.6Si23_03
Another ExampleAnother Example
12.7Si23_03
Viewing Co-ordinate System
Viewing Co-ordinate System
The viewing transformation has transformed objects into the viewing co-ordinate systemviewing co-ordinate system, where the camera position is at the origin, looking along the negative z-direction
zV
yV
xV
camera
cameradirection
12.8Si23_03
View VolumeView Volume
zV
yV
xV
camera
nearplane
farplane
We determine the view volume by:- view angle, - aspect ratio of viewplane- distances to near plane dNP and far plane dFP
dNP
dFP
12.9Si23_03
ProjectionProjection
We shall project on to the near plane. Remember this is atright angles to the zV direction, and has z-coordinate zNP = - dNP
zV
yV
xV
camera
nearplane
dNP
12.10Si23_03
Perspective Projection Calculation
Perspective Projection Calculation
looking down x-axis towardsthe origin
zV
yV
xV
camera
nearplane
dNP
zNP
zV
view plane
Q
camera
yV
zNP zQ
12.11Si23_03
Perspective Projection Calculation
Perspective Projection Calculation
zV
view plane
Q
camera
yV
zNP zQ
P
By similar triangles, yP / yQ = ( - zNP) / ( - zQ)and soyP = yQ * (- zNP) / ( - zQ)oryP = yQ * dNP / ( - zQ)
Similarly for thex-coordinate of P:xP = xQ * dNP / ( - zQ)
12.12Si23_03
Using Matrices and Homogeneous Co-
ordinates
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
12.13Si23_03
Transformation Matrix for Perspective
Transformation Matrix for Perspective
1 0 0 0
0 1 0 0
0 0 1 0
0 0 -1/dNP 0
xQ
yQ
zQ
1
xH
yH
zH
wH
=
Thus in Homogeneous co-ordinates: xH = xQ; yH = yQ; zH = zQ; wH = (-1/dNP)zQ
In Cartesian co-ordinates:xP = xH / wH = xQ*dNP/(-zQ); yP similar; zP = -dNP = zNP
12.14Si23_03
OpenGLOpenGL
Perspective projection achieved by:gluPerspective (angle_of_view, aspect_ratio, near, far)
– aspect ratio is width/height– near and far are positive distances
12.15Si23_03
Vanishing PointsVanishing 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 vanishing pointpoint
view plane
vanishing point
one-pointperspectiveprojectionof cube
12.16Si23_03
One- and Two-Point Perspective DrawingOne- and Two-Point Perspective Drawing
12.17Si23_03
One-point PerspectiveOne-point Perspective
Said to be the firstpainting in perspective
This is:Trinity with the Virgin,St John and Donors,by Mastaccio in 1427
12.18Si23_03
Two-point PerspectiveTwo-point Perspective
EdwardHopperLighthouseat Two Lights
-seewww.postershop.com
12.19Si23_03
Parallel Projection - Two types
Parallel Projection - Two types
OrthographicOrthographic parallel projection has view plane perpendicular to direction of projection
ObliqueOblique parallel projection has view plane at an oblique angle to direction of projection
P1
P2
view plane
P1
P2
view plane
We shall only consider orthographic projectionorthographic projection
12.20Si23_03
Parallel Projection Calculation
Parallel Projection Calculation
zV
yV
xV
nearplane
dNP
zV
view plane
Q
yV
looking down x-axis
zNPzQ
P
yP = yQ
similarly xP= xQ
12.21Si23_03
Parallel Projection Calculation
Parallel Projection Calculation
So this is much easier than perspective!– xP = xQ
– yP = yQ
– zP = zNP
The transformation matrix is simply1 0 0 0
0 1 0 00 0 zNP/zQ 00 0 0 1
12.22Si23_03
Clipping
12.23Si23_03
View Frustum and ClippingView Frustum and Clipping
zV
yV
xV
camera
nearplane
farplane
The view volume is a frustum in viewing co-ordinates - we need tobe able to clip objects outside of this region
dNP
dFP
12.24Si23_03
Clipping to View FrustumClipping 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
12.25Si23_03
Clipping for Parallel Projection
Clipping for Parallel Projection
In the parallel projection case, the viewing volume is already a rectangular parallelepiped
farplane
nearplane
zV
view volume
12.26Si23_03
Normalized Projection Co-ordinates
Normalized Projection Co-ordinates
Final step before clipping is to normalizenormalize 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 scalescale transformation
Clipping is then carried out against this standard shape
12.27Si23_03
Viewing Pipeline So FarViewing Pipeline So Far
Our pipeline now looks like:
mod’gco-ords
worldco-ords
view’gco-ords
proj’nco-ords
normalizedprojectionco-ordinatesNORMALIZATION
TRANSFORMATION
12.28Si23_03
Viewport Transformation
12.29Si23_03
And finally...And finally...
The last step is to position the picture on the display surface
This is done by a viewport viewport transformation transformation where the normalized projection co-ordinates are transformed to display co-ordinates, ie pixels on the screen
12.30Si23_03
Viewing Pipeline - The EndViewing Pipeline - The End
A final viewing pipeline is therefore:
mod’gco-ords
worldco-ords
view’gco-ords
proj’nco-ords
normalizedprojectionco-ordinates
deviceco-ordinates
DEVICETRANSFORMATION