Presentation is loading. Please wait.

Presentation is loading. Please wait.

3.1si31_2001 SI31 Advanced Computer Graphics AGR Lecture 3 Viewing Transformation Getting Started with OpenGL Introduction to Projections.

Similar presentations


Presentation on theme: "3.1si31_2001 SI31 Advanced Computer Graphics AGR Lecture 3 Viewing Transformation Getting Started with OpenGL Introduction to Projections."— Presentation transcript:

1 3.1si31_2001 SI31 Advanced Computer Graphics AGR Lecture 3 Viewing Transformation Getting Started with OpenGL Introduction to Projections

2 3.2si31_2001 Viewing Transformation

3 3.3si31_2001 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

4 3.4si31_2001 Viewing n Graphics display devices are 2D rectangular screens n Hence we need to understand how to transform our 3D world to a 2D surface n This involves: observer position – selecting the observer position (or camera position) view plane – selecting the view plane (or camera film plane) projection – selecting the type of projection

5 3.5si31_2001 Viewing Co-ordinate System - View Reference Point n In our world co-ordinate system, we need to specify where the camera is view reference point... n We call this the view reference point... n n … and transform the world so that camera is at the origin view co- ordinate system n We call this the view co- ordinate system xWxW yWyW zWzW P0P0

6 3.6si31_2001 Viewing Co-ordinate 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 direction in which the camera is pointing - the normal from the view plane to camera is the view plane normal, N 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 from the ‘look at’ point to the view reference point

7 3.7si31_2001 Viewing Co-ordinate System - View Up Direction upward direction, UP n Next we need to specify the ‘up-direction’ of the camera - this is known as the upward direction, UP n Often we take UP=(0,1,0), the positive y-axis n Both N and UP are normalised - ie unit vectors xWxW yWyW zWzW P0P0 N UP

8 3.8si31_2001 Viewing Co-ordinate System n This gives us a view reference point P 0, and vectors N (view plane normal) and UP (upwards direction) n We now construct a right- handed viewing co-ordinate system as follows: – construct U = UPxN to create a vector orthogonal to N and to UP – construct V = N x U to complete the viewing co-ordinate system: U, V, N xWxW yWyW zWzW P0P0 N UP U V V

9 3.9si31_2001 Interlude: Today’s Puzzle n Why does a mirror reflect left-right and not up-down?

10 3.10si31_2001 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

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

12 3.12si31_2001 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

13 3.13si31_2001 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 3 0 0 0 0 1 where U = (u 1 u 2 u 3 ) T etc

14 3.14si31_2001 Viewing Transformation n Thus the viewing transformation is: ViewMatrix = 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 - to be described later

15 3.15si31_2001 Exercises n Convince yourself that the rotation matrix on ‘Rotation Matrix’ slide will have the required effect n Build the view matrix that results from: – camera at (1,2,3) – looking at (3,2,1) – with up direction (0,1,0)

16 3.16si31_2001 Getting Started with OpenGL

17 3.17si31_2001 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

18 3.18si31_2001 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

19 3.19si31_2001 Modelling, Viewing and Projection 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

20 3.20si31_2001 Modelling n For modelling… set the matrix mode, and create the transformation... n Thus to set a scaling on each axis... glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glScaled(sx,sy,sz);

21 3.21si31_2001 Viewing For viewing, use gluLookAt() to create a view transformation matrix gluLookAt(eyex,eyey,eyez, lookx,looky,lookz, upx,upy,upz) n Thus glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glScaled(sx,sy,sz); gluLookAt(eyex,eyey,eyez, lookx,looky,lookz, upx,upy,upz); creates a model-view matrix

22 3.22si31_2001 OpenGL Utility Library (GLU) OpenGL Utility Toolkit (GLUT) n GLU: – useful set of utility routines written in terms of OpenGL … such as gluLookAt() n GLUT (Appendix D of OpenGL Guide): – Set of routines to provide an interface to the underlying windowing system - plus many useful high-level primitives (even a teapot - glutSolidTeapot() !) – Allows you to write ‘event driven’ applications – you specify call back functions which are executed when an event (eg window resize) occurs

23 3.23si31_2001 How to Get Started n Look at the SI31/AGR resources page: – http://www.comp.leeds.ac.uk/kwb/si31/ resources.html n Points you to: – example programs – information about GLUT – information about OpenGL – information about Mesa 3D – a simple exercise

24 3.24si31_2001 Introduction to Projections

25 3.25si31_2001 Viewing Pipeline So Far n We now should understand the viewing pipeline mod’g co-ords world co-ords viewing co-ords Modelling Transform’n Viewing Transform’n The next stage is the projection transformation…. Projection Transform’n

26 3.26si31_2001 Puzzle from Lecture 2

27 3.27si31_2001 Ames Room n For further reading see: www.illusionworks.com/ html/ames_room.html www.psych.uleth.ca/People/ Douglas/Winter99/01/ Ames.html

28 3.28si31_2001 Another Example

29 3.29si31_2001 Perspective Projections perspectiveparallel n There are two types of projection: perspective and parallel perspective n In a perspective projection, object positions are projected onto the view plane along lines which converge at the observer P1 P2 P1’ P2’ view plane camera

30 3.30si31_2001 Parallel Projection n In a parallel projection, the observer position is at an infinite distance, so the projection lines are parallel P1 P2 view plane

31 3.31si31_2001 Perspective and Parallel Projection n Parallel projection preserves the relative proportions of objects, but does not give a realistic view n Perspective projection gives realistic views, but does not preserve proportions – Projections of distant objects are smaller than projections of objects of the same size which are closer to the view plane

32 3.32si31_2001 Perspective and Parallel Projection perspective parallel


Download ppt "3.1si31_2001 SI31 Advanced Computer Graphics AGR Lecture 3 Viewing Transformation Getting Started with OpenGL Introduction to Projections."

Similar presentations


Ads by Google