Presentation is loading. Please wait.

Presentation is loading. Please wait.

Transformations and Projections (Some slides adapted from Amitabh Varshney)

Similar presentations


Presentation on theme: "Transformations and Projections (Some slides adapted from Amitabh Varshney)"— Presentation transcript:

1 Transformations and Projections (Some slides adapted from Amitabh Varshney)

2 Transformation of lines/normals 2D. Line is set of points (x,y) for which (a,b,c).(x,y,1) T =0. Suppose we rotate points by R. Notice that: (a,b,c)R T R(x,y,1) T So, (a,b,c)R T is the rotation of the line (a,b,c). Surface normals are similar, except they are defined by (a,b,c).(x,y,z) T = 0

3 Rotation about a known axis Suppose we want to rotate about u. Find R so that u will be the new z axis. –u is third row of R. –Second row is anything orthogonal to u. –Third row is cross-product of first two. –Make sure matrix has determinant 1. Then rotate about (new) z axis. Then apply inverse of first rotation.

4 OpenGL Transformation Support Three matrices –GL_MODELVIEW, GL_PROJECTION, GL_TEXTURE – glMatrixMode( mode ) specifies the active matrix glLoadIdentity( ) –Set the active matrix to identity glLoadMatrix{fd}(TYPE *m) –Set the 16 values of the current matrix to those specified by m glMultMatrix{fd}(TYPE *m) –Multiplies the current active matrix by m m 1 m 5 m 9 m 13 m 2 m 6 m 10 m 14 m 3 m 7 m 11 m 15 m 4 m 8 m 12 m 16 m =

5 Transformation Example glMatrixMode(GL_MODELVIEW); glLoadIdentity( ); // matrix = I glMultMatrix(N); // matrix = N glMultmatrix(M); // matrix = NM glMultMatrix(L); // matrix = NML glBegin(GL_POINTS); glVertex3f(v); // v will be transformed: NMLv glEnd( );

6 OpenGL Transformations glTranslate{fd}(TYPE x, TYPE y, TYPE z) –Multiply the current matrix by the translation matrix glRotate{fd}(TYPE angle, TYPE x, TYPE y, TYPE z) –Multiply the current matrix by the rotation matrix that rotates an object about the axis from (0,0,0) to (x, y, z) glScale{fd}(TYPE x, TYPE y, TYPE z) –Multiply the current matrix by the scale matrix

7 Examples glMatrixMode(GL_MODELVIEW); glRecti(50,100,200,150); glTranslatef(-200.0, -50.0, 0.0); glRecti(50,100,200,150); glLoadIdentity(); glRotatef(90.0, 0.0, 0.0, 1.0); glRecti(50,100,200,150); glLoadIdentity(); glscalef(-.5, 1.0, 1.0) glRecti(50,100,200,150);

8 Hierarchical Transformations in OpenGL Stacks for Modelview and Projection matrices glPushMatrix( ) –push-down all the matrices in the active stack one level –the top-most matrix is copied (the top and the second- from-top matrices are initially the same). glPopMatrix( ) –pop-off and discard the top matrix in the active stack Stacks used during recursive traversal of the hierarchy. Typical depths of matrix stacks: –Modelview stack = 32 (aggregating several transformations) –Projection Stack = 2 (eg: 3D graphics and 2D help- menu)

9 Viewing in 3D World (3D)  Screen (2D) Orienting Eye coordinate system in World coordinate system – View Orientation Matrix Specifying viewing volume and projection parameters for  n  d (d < n) – View Mapping Matrix

10 World to Eye Coordinates (Images Removed)

11 World to Eye Coordinates We need to transform from the world coordinates to the eye coordinates The eye coordinate system is specified by: –View reference point (VRP) ( VRP x, VRP y, VRP z ) –Direction of the axes: eye coordinate system U = ( u x, u y, u z ) V = ( v x, v y, v z ) N = ( n x, n y, n z )

12 World to Eye Coordinates There are two steps in the transformation (in order) –Translation –Rotation

13 World to Eye Coordinates Translate World Origin to VRP 1 0 0 -VRP x 0 1 0 -VRP y 0 0 1 -VRP z 0 0 0 1 x y z 1 a b c 1 =

14 World to Eye Coordinates Rotate World X, Y, Z to the Eye coordinate system u, v, n, also known as the View Reference Coordinate system a b c 1 x’ y’ z’ 1 = u x u y u z 0 v x v y v z 0 n x n y n z 0 0 0 0 1

15 Camera Analogy (Images Removed)

16 Specifying 3D View (Camera Analogy) Center of camera (x, y, z) : 3 parameters Direction of pointing ( ,  ) : 2 parameters Camera tilt (  ) : 1 parameter Area of film (w, h) : 2 parameters Focus (f) : 1 parameter

17 Specifying 3D View Center of camera (x, y, z) : View Reference Point (VRP) Direction of pointing ( ,  ) : View Plane Normal (VPN) Camera tilt (  ) : View Up (VUP) Area of film (w, h) : Aspect Ratio (w/h), Field of view (fov) Focus (f) : Will consider later

18 Eye Coordinate System View Reference Point (VRP) View Plane Normal (VPN) View Up (VUP) VRP (origin) VUP (Y-axis) VPN (Z-axis) Viewing Plane VUP  VPN (X-axis)

19 World to Eye Coordinates Translate World Origin to VRP Rotate World X, Y, Z to the Eye coordinate system, also known as the View Reference Coordinate system, VRC = (VUP  VPN, VUP, VPN), respectively: ( VUP  VPN ) 0 ( VUP ) 0 ( VPN ) 0 0 0 0 1

20 Eye Coordinate System (OpenGL/GLU library) gluLookAt (eye x, eye y, eye z, lookat x, lookat y, lookat z, up x, up y, up z ); In our terminology: eye = VRP lookat = VRP + VPN up = VUP gluLookAt also works even if: –lookat is any point along the VPN –VUP is not perpendicular to VPN

21 gluLookAt() Image from: Interactive Computer Graphics by Ed Angel (Images Removed)

22 Eye Coordinate System (OpenGL/GLU library) This how the gluLookAt parameters are used to generate the eye coordinate system parameters: VRP = eye VPN = (lookat - eye) /  lookat - eye)   VUP = VPN  (up  VPN) The eye coordinate system parameters are then used in translation T(VRP) and rotation R(XYZ  VRC) to get the view-orientation matrix

23 http://www.acmi.net.au/AIC/CAMERA_OBSCURA.htmlhttp://www.acmi.net.au/AIC/CAMERA_OBSCURA.html (Russell Naughton) Camera Obscura "When images of illuminated objects... penetrate through a small hole into a very dark room... you will see [on the opposite wall] these objects in their proper form and color, reduced in size... in a reversed position, owing to the intersection of the rays". Da Vinci

24 Used to observe eclipses (eg., Bacon, 1214-1294) By artists (eg., Vermeer).

25 http://brightbytes.com/cosite/collection2.htmlhttp://brightbytes.com/cosite/collection2.html (Jack and Beverly Wilgus) Jetty at Margate England, 1898.

26 Pinhole cameras Abstract camera model - box with a small hole in it Pinhole cameras work in practice (Forsyth & Ponce)

27 The equation of projection (Forsyth & Ponce)

28 The equation of projection Cartesian coordinates: –We have, by similar triangles, that (x, y, z) -> (f x/z, f y/z, f) –Ignore the third coordinate, and get

29 Perspective Projection Homogenize (divide by w’’= z / f) to get: –x’ = x / (z / f) = x’’/ w’’ –y’ = y / (z / f) = y’’/ w’’ –z’ = z / (z / f) = z’’/ w’’ = f 1 0 0 0 0 1 0 0 0 0 1 0 0 0 1/f 0 x y z 1 x’’ y’’ z’’ w’’ =

30 Distant objects are smaller (Forsyth & Ponce)

31 For example, consider one line segment from (x,0,z) to (x,y,z), and another from (x,0,2z) to (x,y,2z). These are the same length. These project in the image to a line from (fx/z,0) to (fx/z, fy/z) and from (fx/z,0) to (fx/2z, fy/2z), where we can rewrite the last point as: (1/2)(fx/z,fy/z). The second line is half as long as the first.

32 Parallel lines meet Common to draw image plane in front of the focal point. Moving the image plane merely scales the image. (Forsyth & Ponce)

33 Vanishing points Each set of parallel lines meets at a different point –The vanishing point for this direction Sets of parallel lines on the same plane lead to collinear vanishing points. –The line is called the horizon for that plane

34 For example, let’s consider a line on the floor. We describe the floor with an equation like: y = -1. A line on the floor is the intersection of that equation with x = az + b. Or, we can describe a line on the floor as: (a, -1, b) + t(c, 0, d) (Why is this correct, and why does it have more parameters than the first way?) As a line gets far away, z -> infinity. If (x,-1,z) is a point on this line, its image is f(x/z,-1/z). As z -> infinity, -1/z - > 0. What about x/z? x/z = (az+b)/z = a + b/z -> a. So a point on the line appears at: (a,0). Notice this only depends on the slope of the line x = az + b, not on b. So two lines with the same slope have images that meet at the same point, (a,0), which is on the horizon.

35 Properties of Projection Points project to points Lines project to lines Planes project to the whole image Angles are not preserved Degenerate cases –Line through focal point projects to a point. –Plane through focal point projects to line –Plane perpendicular to image plane projects to part of the image (with horizon).

36 Weak perspective (scaled orthographic projection) Issue –perspective effects, but not over the scale of individual objects –collect points into a group at about the same depth, then divide each point by the depth of its group (Forsyth & Ponce)

37 The Equation of Weak Perspective s is constant for all points. Parallel lines no longer converge, they remain parallel.

38 Parallel Projection Project on the plane, z = 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 x y z 1 x’ y’ z’ 1 =

39 Cameras with Lenses (Forsyth & Ponce)

40 OpenGL for Projection Projection specifies clipping windows. glMatrixMode(GL_PROJECTION) glOrtho(xmin,xmax,ymin,ymax,dnear,dfar) gluPerspective(theta,aspect,dnear,dfar)


Download ppt "Transformations and Projections (Some slides adapted from Amitabh Varshney)"

Similar presentations


Ads by Google