Presentation is loading. Please wait.

Presentation is loading. Please wait.

Transformations Objectives Understand how transformations work in 2D and 3D Understand the concept of homogenous coordinate system Understand scene graphs.

Similar presentations


Presentation on theme: "Transformations Objectives Understand how transformations work in 2D and 3D Understand the concept of homogenous coordinate system Understand scene graphs."— Presentation transcript:

1

2 Transformations

3 Objectives Understand how transformations work in 2D and 3D Understand the concept of homogenous coordinate system Understand scene graphs and hierarchical composition of transformations Get familiar with transformations in OpenGL and DirectX

4 Transformations Transformations change 2D or 3D points and vectors, or change coordinate systems. An object transformation alters the coordinates of each point on the object according to the same rule, leaving the underlying coordinate system fixed. A coordinate transformation defines a new coordinate system in terms of the old one, then represents all of the object’s points in this new system. Object transformations are easier to understand, so we will do them first.

5 Transformations (2) A (2D or 3D) transformation T( ) alters each point P into a new point Q using a specific formula or algorithm: Q= T(P).

6 Transformations (3) An arbitrary point P in the plane is mapped to Q. Q is the image of P under the mapping T. We transform an object by transforming each of its points, using the same function T() for each point. The image of line L under T, for instance, consists of the images of all the individual points of L.

7 Transformations (4) Most mappings of interest are continuous, so the image of a straight line is still a connected curve of some shape, although it’s not necessarily a straight line. Affine transformations, however, do preserve lines: the image under T of a straight line is also a straight line.

8 Geometric Effects of Affine Transformations Combinations of four elementary transformations: (a) a translation, (b) a scaling, (c) a rotation, and (d) a shear (all shown below).

9 2D Translations P P’

10 2D Scaling from the origin P P’

11 2D Rotation about the origin y x r r P’(x’,y’) P(x,y)  Recall the right-hand rule!

12 2D Rotation about the origin y x r r P’(x’,y’) P(x,y)   y x

13 2D Rotation about the origin. Substituting for r : Given us: After all, these are just High-schools formulas!

14 2D Rotation about the origin. Rewriting in matrix form gives us :

15 Shear: Off Diagonal Elements

16 Example 1 S

17 S

18 T(S)

19 Example 2 S

20 S

21 T(S)

22 Summary Shear in x: Shear in y:

23 Sample Points: unit inverses

24 Geometric View of Shear in x

25 Another Geometric View of Shear in x 24

26 Another Geometric View of Shear in x 25

27 Geometric View of Shear in y

28 Another Geometric View of Shear in y h h 27

29 Another Geometric View of Shear in y 28

30 Transformations Translation. P=T + P Scale P=S  P Rotation P=R  P Shear P=H  P We would like all transformations to be multiplications so we can concatenate them  express points in homogenous coordinates.

31 Homogeneous coordinates Add an extra coordinate, W, to a point. P(x,y,W). Two sets of homogeneous coordinates represent the same point if they are a multiple of each other. (2,5,3) and (4,10,6) represent the same point. At least one component must be non-zero  (0,0,0) is not allowed. If W  0, divide by it to get Cartesian coordinates of point (x/W,y/W,1). If W=0, point is said to be at infinity. P(x,y,0) can be interpreted as the vector v(x, y) Both points and vectors are represented by the same set of underlying objects

32 Homogeneous coordinates If we represent (x,y,W) in 3-space, all triples representing the same point describe a line passing through the origin. If we homogenize the point, we get a point of form (x,y,1) homogenised points form a plane at W=1. P X Y W W=1 plane

33 Translations in homogenised coordinates Transformation matrices for 2D translation are now 3x3.

34 Concatenation We perform 2 translations on the same point:

35 Concatenation. Matrix product is variously referred to as compounding, concatenation, or composition. This single matrix is called the Coordinate Transformation Matrix or CTM.

36 Homogeneous form of scale Recall the (x,y) form of Scale : In homogeneous coordinates :

37 Concatenation of scales.

38 Homogeneous form of rotation

39 Composition of Transformations Suppose we want to rotate around an arbitrary point P Idea: Compose simple transformations 1. Translate P to origin 2. Rotate around origin 3. Translate origin back to P The order is very important!

40 Order!

41 3D Transformations Use homogeneous coordinates, just as in 2D case. Transformations are now 4x4 matrices. We will use a right-handed (world) coordinate system - ( z out of page ). z (out of page) y x Note: Convenient to think of display as Being left-handed !! ( z into the screen )

42 More on Homogeneous Coordinates To: if the object is a vector, add a 0 as the 4 th coordinate; if it is a point, add a 1. From: If the 4 th coordinate is zero, then simply remove it. If it is not, then divide the other coordinate by it and remove it. OpenGL uses 4D homogeneous coordinates for all its vertices. If you send it a 3-tuple in the form (x, y, z), it converts it immediately to (x, y, z, 1). If you send it a 2D point (x, y), it first appends a 0 for the z- component and then a 1, to form (x, y, 0, 1). All computations are done within OpenGL in 4D homogeneous coordinates.

43 Combinations Linear combinations of vectors and points: The difference of 2 points is a vector: the fourth component is 1 – 1 = 0 The sum of a point and a vector is a point: the fourth component is 1 + 0 = 1 The sum of 2 vectors is a vector: 0 + 0 = 0 A vector multiplied by a scalar is still a vector Linear combinations of vectors are vectors

44 Translation in 3D Simple extension to the 3D case: In OpenGL: glMatrixMode(GL_ModelView); glTranslatef(dx, dy, dz); In DirectX: device.Transform.World = Matrix.Translation(dx, dy, dz)

45 Scale in 3D Simple extension to the 3D case: In OpenGL: glMatrixMode(GL_ModelView); glScalef(Sx, Sy, Sz); In DirectX: device.Transform.World = Matrix.Scaling(Sx, Sy, Sz)

46 Rotation in 3D Need to specify which axis the rotation is about. z-axis rotation is the same as the 2D case. In OpenGL: glMatrixMode(GL_ModelView); glRotatef(theta, 0.0f, 0.0f, 1.0f); In DirectX: device.Transform.World = Matrix.RotationZ(theta)

47 Rotation in 3D For rotation about the x and y axes: In OpenGL: glMatrixMode(GL_ModelView); glRotatef(theta, 1.0f, 0.0f, 0.0f); //gRotatef(theta,0.0f,1.0f,0.0f) (about y) In DirectX: device.Transform.World = Matrix.RotationZ(theta); //Matrix.RotationY(theta) (about y)

48 3D Shear in x -direction In OpenGL: glMatrixMode(GL_ModelView); glMultMatrixf(Shx(a)); In DirectX: device.Transform.World = Matrix. Multiply(Matrix.Identity,Shx(a));

49 3D Shear in x -direction

50

51 Transformations of coordinate systems Alternate view: when we apply a transformation, we’re not changing the coordinates of a point within a coordinate system. Instead, we’re changing the coordinate system itself All the transformations are performed relative to the current coordinate frame origin and axes; OpenGL post-multiplies each new transformation matrix

52 Successive Transformations C1 C2 C3 M1 M2 Given P (a3,b3) in C3 What is P’s coordinates in C1? 1)Get P’s coordinates in C2 P_c2 = M2 x P 2)Get P_c2’s coordinates in C1 P_c1 = M1 x P_c2 P_c1 = M1 x M2 x P the answer!! C1 M1 C2 M2 (a3,b3) C3 a3 b3

53 Successive Transformations (2) The sequence translate 1.5 0 0 cube translate 8.5 0 0 cube will draw two cubes with x centres 1.5 and 10.0 respectively. We could create the same image with the sequence save state translate 1.5 0 0 cube restore state save state translate 10.0 0 0 cube restore state Here both cubes have an absolute translation and the order in which the two cubes are drawn does not matter.

54 Hierarchical composition using Push and Pop glPushMatrix(); Save the state. Push a copy of the CTM onto the stack. The CTM itself is unchanged. glPopMatrix () ; Restore the state, as it was at the last Push. Overwrite the CTM with the matrix at the top of the stack. glLoadIdentity (); Overwrite the CTM with the identity matrix.

55 Scene graphs 3D scenes are often stored in a directed acyclic graph (DAG) called a scene graph Open Scene Graph (used in the Cave) Sun’s Java3D™ VRML Common scene graph format: objects (cubes, spheres, cones,...) stored as leaf nodes attributes (color, texture map, etc.), and transformations are also nodes in a scene graph Very helpful in designing complex objects Allows us to know when to push and when to pop Allows to know when to use display lists/index buffers Allows us to animate different parts of a complex object

56 Scene graphs ROBOT upper bodylower body headtrunk arm stanchionbase 2. We transform them 3. To make sub-groups 4. Transform subgroups 5. To get final scene 1. Leaves of tree are standard size object primitives

57 Hierarchical transformation and scene graphs Example: - for o1, CT = m1 - for o2, CT = m2* m3 - for o3, CT = m2* m4* m5 - for a vertex v in o3, position in the world (root) coordinate system is: CT.v = (m2*m4*m5)v m1m2 m3 m4 o1 o2 o3 g1 g2 g: group nodes m: matrices of transform nodes o: object nodes

58 Transformations in OpenGL: Summary Important: OpenGL maintains a number of matrices: ModelView, Projection, and Texture. We switch between them with the glMatrixMode() routine The most recent call to glMatrixMode() selects OpenGL’s current transformation (CT) matrix Transformations are applied by post-multiplying CT by the desired transformation: CT = CT · M

59 Practice session Use glRotate and Matrix.RotationAxis to rotate around any line Use scence graphs and hierarchical composition of transformations to build a nice 3D car and nice 3D airplane


Download ppt "Transformations Objectives Understand how transformations work in 2D and 3D Understand the concept of homogenous coordinate system Understand scene graphs."

Similar presentations


Ads by Google