Download presentation

Presentation is loading. Please wait.

Published byLeslie Jenkins Modified over 2 years ago

1
1GR2-00 GR2 Advanced Computer Graphics AGR Lecture 4 Viewing Pipeline Getting Started with OpenGL

2
2GR2-00 The Story So Far...Lecture 2 local co-ordinate representation world co-ordinate system n We have seen how we can model objects, by transforming them from their local co-ordinate representation into a world co-ordinate system modelling co-ordinates world co-ordinates MODELLING TRANSFORMATION

3
3GR2-00 The Story So Far...Lecture 3 special viewing co- ordinate system projection co-ordinate system n And we have seen how we can transform from a special viewing co- ordinate system (camera on z-axis pointing along the axis) into a projection co-ordinate system viewing co-ordinates projection co-ordinates PROJECTION TRANSFORMATION

4
4GR2-00 Completing the Pipeline - Lecture 4 n We now need to fill in the missing part to get world co-ordinates viewing co-ordinates VIEWING TRANSFORMATION modg co-ords world co-ords viewg co-ords projn co-ords

5
5GR2-00 Viewing Coordinate System - View Reference Point view reference point - n In our world co-ordinate system, we need to specify a view reference point - this will become the origin of the view co-ordinate system n This can be any convenient point, along the camera direction from the camera position camera position – indeed one possibility is the camera position itself xWxW yWyW zWzW P0P0

6
6GR2-00 Viewing Coordinate System - View Plane Normal xWxW yWyW zWzW P0P0 N xWxW yWyW zWzW P0P0 Q view plane normal, N n Next we need to specify the view plane normal, N - this will give the camera direction, or z-axis direction n Some graphics systems require you to specify N... look at n... others (including OpenGL) allow you to specify a look at point, Q, from which N is calculated as direction to the look at point from the view reference point

7
7GR2-00 Viewing Coordinate System - View Up Direction view-up direction, V n Finally we need to specify the view-up direction, V - this will give the y-axis direction xWxW yWyW zWzW P0P0 N V

8
8GR2-00 Viewing Co-ordinate System n This gives us a view reference point P 0,and vectors N (corresponding to z V ) and V (corresponding to y V ) n We can construct a vector U perpendicular to both V and N, and this will correspond to the x V axis n How? xWxW yWyW zWzW P0P0 N V U

9
9GR2-00 Transformation from World to Viewing Co-ordinates n Given an object with positions defined in world co-ordinates, we need to calculate the transformation to viewing co-ordinates n The view reference point must be transformed to the origin, and lines along the U, V, N directions must be transformed to lie along the x, y, z directions

10
10GR2-00 Transformation from World to Viewing Co-ordinates n Translate so that P 0 lies at the origin xWxW yWyW zWzW P0P0 - apply translation by (-x 0, -y 0, -z 0 ) (x 0, y 0, z 0 ) T = x y z V U N

11
11GR2-00 Transformation from World to Viewing Co-ordinates n Apply rotations so that the U, V and N axes are aligned with the x W, y W and z W directions n This involves three rotations Rx, then Ry, then Rz – first rotate around x W to bring N into the x W -z W plane – second, rotate around y W to align N with z W – third, rotate around z W to align V with y W n Composite rotation R = Rz. Ry. Rx

12
12GR2-00 Rotation Matrix n Fortunately there is an easy way to calculate R, from U, V and N: R =u 1 u 2 u 3 0 v 1 v 2 v 3 0 n 1 n 2 n where U = (u 1 u 2 u 3 ) T etc

13
13GR2-00 Viewing Transformation n Thus the viewing transformation is: M = R. T n This transforms object positions in world co-ordinates to positions in the viewing co-ordinate system.... with camera pointing along negative z-axis at a view plane parallel to x-y plane n We can then apply the projection transformation

14
14GR2-00 Viewing Pipeline So Far n We now should understand this viewing pipeline modg co-ords world co-ords viewg co-ords projn co-ords

15
15GR2-00 Clipping n Next we need to understand how the clipping to the view volume is performed n Recall that with perspective projection we defined a view frustum outside of which we wanted to clip points and lines, etc n The next slide is from lecture 3...

16
16GR2-00 View Frustum - Perspective Projection view window back plane front plane camera view frustum zVzV

17
17GR2-00 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)

18
18GR2-00 Clipping for Parallel Projection n In the parallel projection case, the viewing volume is already a rectangular parallelepiped view window back plane front plane zVzV view volume

19
19GR2-00 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

20
20GR2-00 Viewing Pipeline So Far n Our pipeline now looks like: modg co-ords world co-ords viewg co-ords projn co-ords normalized projection co-ordinates NORMALIZATION TRANSFORMATION

21
21GR2-00 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

22
22GR2-00 Viewing Pipeline - The End n A final viewing pipeline is therefore: modg co-ords world co-ords viewg co-ords projn co-ords normalized projection co-ordinates device co-ordinates DEVICE TRANSFORMATION

23
23GR2-00 Interlude n Why does a mirror reflect left-right and not up-down?

24
24GR2-00 OpenGL - Getting Started

25
25GR2-00 What is OpenGL? n OpenGL provides a set of routines (API) for advanced 3D graphics – derived from Silicon Graphics GL – acknowledged industry standard, even on PCs (OpenGL graphics cards available) – integrates 3D drawing into X (and other window systems such as Windows NT) – draws simple primitives (points, lines, polygons) but NOT complex primitives such as spheres – provides control over transformations, lighting, etc – Mesa is publically available equivalent

26
26GR2-00 Geometric Primitives n Defined by a group of vertices - for example to draw a triangle: glBegin (GL_POLYGON); glVertex3i (0, 0, 0); glVertex3i (0, 1, 0); glVertex3i (1, 0, 1); glEnd(); n See Chapter 2 of the OpenGL Programming Guide

27
27GR2-00 Viewing n OpenGL maintains two matrix transformation modes – MODELVIEW to specify modelling transformations, and transformations to align camera – PROJECTION to specify the type of projection (parallel or perspective) and clipping planes n See Chapter 3 of OpenGL Programming Guide

28
28GR2-00 OpenGL Utility Library (GLU) n Useful set of higher level utility routines to make some tasks easier – written in terms of OpenGL and provided with the OpenGL implementation – for example, gluLookAt() is a way of specifying the viewing transformation n Described within the OpenGL Programming Guide – eg gluLookAt() is described in Chap 3, pp19-21

29
29GR2-00 OpenGL Utility Toolkit (GLUT) Set of routines to provide an interface to the underlying windowing system - plus many useful high-level primitives (even a teapot - glutSolidTeapot() !) n See Appendix D of OpenGL Guide n Allows you to write event driven applications – you specify call back functions which are executed when an event (eg window resize) occurs

30
30GR2-00 How to Get Started n Look at the GR2/AGR resources page: – resources.html n Points you to: – example programs – information about GLUT – information about OpenGL – a simple exercise

Similar presentations

© 2016 SlidePlayer.com Inc.

All rights reserved.

Ads by Google