Presentation is loading. Please wait.

Presentation is loading. Please wait.

4.1si31_2001 SI31 Advanced Computer Graphics AGR Lecture 4 Projection Clipping Viewport Transformation.

Similar presentations


Presentation on theme: "4.1si31_2001 SI31 Advanced Computer Graphics AGR Lecture 4 Projection Clipping Viewport Transformation."— Presentation transcript:

1 4.1si31_2001 SI31 Advanced Computer Graphics AGR Lecture 4 Projection Clipping Viewport Transformation

2 4.2si31_2001 Interlude n Why does a mirror reflect left-right and not up-down?

3 4.3si31_2001 Projection

4 4.4si31_2001 Viewing Co-ordinate System viewing co-ordinate system n 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 zVzV yVyV xVxV camera direction

5 4.5si31_2001 View Volume zVzV yVyV xVxV camera near plane far plane  We determine the view volume by: - view angle,  - aspect ratio of viewplane - distances to near plane d NP and far plane d FP d NP d FP

6 4.6si31_2001 Projection We shall project on to the near plane. Remember this is at right angles to the z V direction, and has z-coordinate z NP = - d NP zVzV yVyV xVxV camera near plane d NP

7 4.7si31_2001 Perspective Projection Calculation looking down x-axis towards the origin zVzV yVyV xVxV camera near plane d NP z NP zVzV view plane Q camera yVyV z NP zQzQ

8 4.8si31_2001 Perspective Projection Calculation zVzV view plane Q camera yVyV z NP zQzQ P By similar triangles, y P / y Q = ( - z NP ) / ( - z Q ) and so y P = y Q * (- z NP ) / ( - z Q ) or y P = y Q * d NP / ( - z Q ) Similarly for the x-coordinate of P: x P = x Q * d NP / ( - z Q )

9 4.9si31_2001 Using Matrices and Homogeneous Co-ordinates n We can express the perspective transformation in matrix form n Point Q in homogeneous coordinates is (x Q, y Q, z Q, 1) n We shall generate a point H in homogeneous co-ordinates (x H, y H, z H, w H ), where w H is not 1 n But the point (x H /w H, y H /w H, z H /w H, 1) is the same as H in homogeneous space n This gives us the point P in 3D space, ie x P = x H /w H, sim’ly for y P

10 4.10si31_2001 Transformation Matrix for Perspective 1 0 0 0 0 1 0 0 0 0 1 0 0 0 -1/d NP 0 xQyQzQ1xQyQzQ1 xHyHzHwHxHyHzHwH = Thus in Homogeneous co-ordinates: x H = x Q ; y H = y Q ; z H = z Q ; w H = (-1/d NP )z Q In Cartesian co-ordinates: x P = x H / w H = x Q *d NP /(-z Q ); y P similar; z P = -d NP = z NP

11 4.11si31_2001 Exercises n Suppose the camera is not at the origin, but at point z C n Calculate the formulae for perspective projection and work out the resulting transformation matrix in homogeneous co-ordinates n In practice the perspective division is delayed - why might this be done? - what useful information is lost?

12 4.12si31_2001 OpenGL n Perspective projection achieved by: gluPerspective (angle_of_view, aspect_ratio, near, far) – aspect ratio is width/height – near and far are positive distances

13 4.13si31_2001 Vanishing Points vanishing point n 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 view plane vanishing point one-point perspective projection of cube

14 4.14si31_2001 One- and Two-Point Perspective Drawing

15 4.15si31_2001 One-point Perspective Said to be the first painting in perspective This is: Trinity with the Virgin, St John and Donors, by Mastaccio in 1427

16 4.16si31_2001 Two-point Perspective Edward Hopper Lighthouse at Two Lights -see www.postershop.com

17 4.17si31_2001 Parallel Projection - Two types n Orthographic n Orthographic parallel projection has view plane perpendicular to direction of projection n Oblique n Oblique parallel projection has view plane at an oblique angle to direction of projection P1 P2 view plane P1 P2 view plane orthographic projection We shall only consider orthographic projection

18 4.18si31_2001 Parallel Projection Calculation zVzV yVyV xVxV near plane d NP zVzV view plane Q yVyV looking down x-axis z NP zQzQ P y P = y Q similarly x P = x Q

19 4.19si31_2001 Parallel Projection Calculation n So this is much easier than perspective! – x P = x Q – y P = y Q – z P = z NP n The transformation matrix is simply 1 0 0 0 0 1 0 0 0 0 z NP /z Q 0 0 0 0 1

20 4.20si31_2001 Clipping

21 4.21si31_2001 View Frustum and Clipping zVzV yVyV xVxV camera near plane far plane  The view volume is a frustum in viewing co-ordinates - we need to be able to clip objects outside of this region d NP d FP

22 4.22si31_2001 Clipping to View Frustum n It is quite easy to clip lines to the front and back planes (just clip in z).. n.. but it is difficult to clip to the sides because they are ‘sloping’ planes n Instead we carry out the projection first which converts the frustum to a rectangular parallelepiped (ie a cuboid)

23 4.23si31_2001 Clipping for Parallel Projection n In the parallel projection case, the viewing volume is already a rectangular parallelepiped far plane near plane zVzV view volume

24 4.24si31_2001 Normalized Projection Co-ordinates normalize n 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 scale n This is just a scale transformation n Clipping is then carried out against this standard shape

25 4.25si31_2001 Viewing Pipeline So Far n Our pipeline now looks like: mod’g co-ords world co-ords view’g co-ords proj’n co-ords normalized projection co-ordinates NORMALIZATION TRANSFORMATION

26 4.26si31_2001 Viewport Transformation

27 4.27si31_2001 And finally... n The last step is to position the picture on the display surface viewport transformation n This is done by a viewport transformation where the normalized projection co-ordinates are transformed to display co-ordinates, ie pixels on the screen

28 4.28si31_2001 Viewing Pipeline - The End n A final viewing pipeline is therefore: mod’g co-ords world co-ords view’g co-ords proj’n co-ords normalized projection co-ordinates device co-ordinates DEVICE TRANSFORMATION


Download ppt "4.1si31_2001 SI31 Advanced Computer Graphics AGR Lecture 4 Projection Clipping Viewport Transformation."

Similar presentations


Ads by Google