Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS 551 / 645: Introductory Computer Graphics Viewing Transforms.

Similar presentations


Presentation on theme: "CS 551 / 645: Introductory Computer Graphics Viewing Transforms."— Presentation transcript:

1 CS 551 / 645: Introductory Computer Graphics Viewing Transforms

2 Administrivia l Assignment 2 is online - get started this weekend l Midterm will be before reading break - Oct 19 l Today’s reading material: FvD, Chapter 6

3 Translations l Moving an object is called a translation. We translate a point by adding to the x and y coordinates, respectively, the amount the point should be shifted in the x and y directions. We translate an object by translating each vertex in the object. x new = x old + t x ; y new = y old + t y tyty txtx

4 Scaling l Changing the size of an object is called a scale. We scale an object by scaling the x and y coordinates of each vertex in the object. s x =w new /w old s y =h new /h old x new = s x x old y new = s y y old w old w new h old h new

5 Rotation about the Origin l To rotate a line or polygon, we must rotate each of its vertices. l We want to rotate point (x 1,y 1 ) to point (x 2,y 2 ) through angle B From the illustration we know that: sin (A + B) = y 2 /rcos (A + B) = x 2 /r sin A = y 1 /rcos A = x 1 /r x-axis (x1,y1) (x2,y2) A B r (0,0) y-axis

6 Rotation about the origin (cont.) From the double angle formulas:sin (A + B) = sinAcosB + cosAsinB Substituting:y 2 /r = (y 1 /r)cosB + (x 1 /r)sinB Therefore: y 2 = y 1 cosB + x 1 sinB We have x 2 = x 1 cosB - y 1 sinB y 2 = x 1 sinB + y 1 cosB

7 Transformations as matrices Scale: x new = s x x old y new = s y y old Rotation: x 2 = x 1 cos  - y 1 sin  y 2 = x 1 sin  + y 1 cos  Translation: x new = x old + t x y new = y old + t y

8 Homogeneous Coordinates In order to represent a translation as a matrix multiplication operation we use 3 x 3 matrices and pad our points to become 3 x 1 matrices. This coordinate system (using three values to represent a 2D point) is called homogeneous coordinates.

9 Composite Transformations Suppose we wished to perform multiple transformations on a point: Remember: Matrix multiplication is associative, not commutative! Transform matrices must be pre-multiplied The first transformation you want to perform will be at the far right, just before the point

10 Composite Transforms - Scaling (cont.) l If we scale a line between (0,0) & (2,0) to twice its length, the left-hand endpoint does not move. (0,0) is known as a fixed point for the basic scaling transformation. We can use composite transformations to create a scale transformation with different fixed points. 012345678910 Before After 012345678910

11 Fixed Point Scaling Scale by 2 with fixed point = (2,1) l Translate the point (2,1) to the origin l Scale by 2 Translate origin to point (2,1) 0123456789100123456789 Before After

12 Rotation about a Fixed Point Rotation Of  Degrees About Point (x,y) l Translate (x,y) to origin l Rotate l Translate origin to (x,y)

13 Shears Original Datay Shearx Shear

14 Reflections Reflection about the y-axisReflection about the x-axis

15 More Reflections Reflection about the originReflection about the line y=x ? ?

16 Transformations as a change in coordinate system l All transformations we have looked at involve transforming points in a fixed coordinate system (CS). l Can also think of them as a transformation of the CS itself

17 Transforming the CS - examples Translate(4,4) Rotate(180°)

18 Why transform the CS? l Objects often defined in a “natural” or “convenient” CS l To draw objects transformed by T, we could: –Transform each vertex by T, then draw –Or, draw vertices in a transformed CS (2,2)

19 Drawing in transformed CS l Tell system once how to draw the object, then draw in a transformed CS to transform the object House drawn in a CS that’s been translated, rotated, and scaled M = S x,y R d T x,y

20 Projecting 3-D into 2-D l Rotations and translations are sufficient to convert 3D to 2D l We frequently map from world space (3D) into eye space (2D) l Create a special class of transformations for this mapping: viewing transformations

21 A 3D Scene l Notice the presence of the camera, the projection plane, and the world coordinate axes l Viewing transformations define how to acquire the image on the projection plane

22 Viewing Transformations l Create a camera-centered view l Camera is at origin l Camera is looking along negative z-axis l Camera’s ‘up’ is aligned with y-axis

23 2 Basic Steps l Align the two coordinate frames by rotation

24 2 Basic Steps l Translate to align origins

25 Creating Camera Coordinate Space l Specify a point where the camera is located in world space, the eye point l Specify a point in world space that we wish to become the center of view, the lookat point l Specify a vector in world space that we wish to point up in camera image, the up vector l Intuitive camera movement

26 Constructing Viewing Transformation, V l Create a vector from eye-point to lookat-point l Normalize the vector l Desired rotation matrix should map this vector to [0, 0, -1] T Why?

27 Constructing Viewing Transformation, V l Construct another important vector from the cross product of the lookat-vector and the vup-vector l This vector, when normalized, should align with [1, 0, 0] T Why?

28 Constructing Viewing Transformation, V l One more vector to define… l This vector, when normalized, should align with [0, 1, 0] T l Now let’s composite the results

29 Compositing Vectors to Form V l We know the three world axis vectors (x, y, z) l We know the three camera axis vectors (u, v, n) l Viewing transformation, V, must convert from world to camera coordinate systems

30 Compositing Vectors to Form V l Remember –Each camera axis vector is unit length. –Each camera axis vector is perpendicular to others l Camera matrix is orthogonal and normalized –Orthonormal l Therefore, M -1 = M T

31 Compositing Vectors to Form V l Therefore, rotation component of viewing transformation is just transpose of computed vectors

32 Compositing Vectors to Form V l Translation component too l Multiply it through

33 Final Viewing Transformation, V l To transform vertices, use this matrix: l And you get this:

34 Special Viewing Transformations l Orthographic is one alternative

35 Orthographic Transformation l Simple Orthographic Transformation l Original world units are preserved –Pixel units are preferred

36 Screen-space Transformation l left, right, top, bottom refer to the viewing frustum in modeling coordinates l width and height are in pixel units l This matrix scales and translates to accomplish the transition in units

37 Perspective Projections l First discovered by Donatello, Brunelleschi, and DaVinci during Renaissance l Objects closer to viewer look larger l Parallel lines appear to converge to single point

38 Perspective Projection l In the real world, objects exhibit perspective foreshortening: distant objects appear smaller l The basic situation:

39 Perspective Projection l When we do 3-D graphics, we think of the screen as a 2-D window onto the 3-D world: How tall should this bunny be?

40 Perspective Projection l The geometry of the situation is that of similar triangles. View from above: l What is y’? P (x, y, z) y Z View plane d (0,0,0) y’ = ?

41 Perspective Projection Desired result for a point [x, y, z, 1] T projected onto the view plane: l What could a matrix look like to do this?

42 A Perspective Projection Matrix l Answer:

43 A Perspective Projection Matrix l Example: l Or, in 3-D coordinates:

44 Screen-space Coordinates l Translate model units to pixel units

45 Canonical Perspective View Volume l Perspective view volume is shaped like a truncated pyramid l A canonical perspective view volumes scale a perspective view volume –Base has sides length 2 –Height is 1 –Origin is centered

46 Canonical Space Mapping for Perspective Projection


Download ppt "CS 551 / 645: Introductory Computer Graphics Viewing Transforms."

Similar presentations


Ads by Google