Presentation is loading. Please wait.

Presentation is loading. Please wait.

Transformation. 3D Transformation oIn the modeling lecture we saw how to define an object in terms of its vertices in object space oWe will now see how.

Similar presentations


Presentation on theme: "Transformation. 3D Transformation oIn the modeling lecture we saw how to define an object in terms of its vertices in object space oWe will now see how."— Presentation transcript:

1 Transformation

2 3D Transformation oIn the modeling lecture we saw how to define an object in terms of its vertices in object space oWe will now see how to use transformations to move objects around, either inside the same space, or from one space to another oIn computer graphics a transformation is represented by a matrix. To transform an object is to multiply the points (represented as vectors) of the object with the matrix oThe points of an object are usually represented using homogeneous coordinates, which means an extra component for the vector

3 3D Transformations 3 commonly used transformations: o Scaling – making objects bigger/smaller o Translating – moving object around o Rotating – rotating objects in space e.g., Scale by 2 e.g., Translate by (1, 1) e.g., Rotate 90°

4 3D Scaling Matrix oBy multiplying a point (x,y,z,1) by a scaling matrix we turn it to (S x x, S y y, S z z,1), all coordinates are scaled oWe use homogeneous coordinates. This allows us to represent all transformations (e.g., scale, rotate, translate) using matrices Scaling coefficients in x, y, z directions

5 Scaling Example oMake the triangle twice as tall but half as wide (0, 1, 0) (-1, -1, 0) (1, -1, 0) (0, 2, 0) (-0.5, -2, 0)(0.5, -2, 0) x y x y

6 3D Translation Matrix oBy multiplying a point (x,y,z,1) by the translation matrix we turn it to (x+T x, y+T y, z+T z, 1): oNote: It will not be possible to use a 3x3 matrix to translate the point, which is why we use a 4x4 homogenous matrix Translation in x, y, z directions

7 Translation Example oMove the triangle back by 5 and right by 3 (0, 1, 0) (-1, -1, 0)(1, -1, 0) (3, 1, -5) (2, -1, -5)(4, -1, -5) x y x y z z

8 Rotation in space

9 3D Rotation About Coordinate Axes oabout X axis oabout Y axis oabout Z axis x y z x y z x y z

10 Not Required oFor simplicity, let theta = q = initial angle, f = angle of rotation ox = r cos q y = r sin q ox' = r cos ( q + f ) = r cos q cos f - r sin q sin f y' = r sin ( q + w ) = r sin q cos f + r cos q sin f ohence: x' = x cos f - y sin f y' = y cos f + x sin f

11 Rotation About Y-Axis oRotate by 45°around y axis (0, 1, 0) (-1, -1, 0) (1, -1, 0) (0, 1, 0) (-0.7, -1, 0.7) (0.7, -1, -0.7) x y x y

12 Composite Transformations oTo transform an object like this: oIt will take several transformations, each represented as a matrix:

13 Composite Transformations o

14 Transformation Implementation in OpenGL oFRONT - Multicolored oBACK - White oTOP - Blue oBOTTOM - Red oRIGHT - Purple oLEFT - Green oglTranslatef(0, 0, -500.0); oglScalef(100, 100, 100); o glRotated(30, 0.0, 0.0, 1.0); o glRotated(30, 0.0, 1.0, 0.0); o glRotated(30, 1.0, 0.0, 0.0);

15

16 Transformation Implementation in OpenGL oSnowman 1 is at the coordinate origin, looking along the z-axis. Now draw Snowman 2, positioned 8 units along the negative x-axis, 6 units along the positive z- axis, half the size of Snowman 1, and looks down the x-axis. o glMatrixMode(GL_MODELVIEW) o glTranslatef(-8.0, 0.0, 6.0); o glRotatef(90.0, 0.0, 1.0, 0.0); o glScalef(0.5, 0.5, 0.5); o drawSnowman(); x y z

17 0 0 0 Transformation Implementation in OpenGL glTranslatef(5.0, 0.0, 5.0); glRotatef(90.0, 0.0, 1.0, 0.0); Or glRotatef(90.0, 0.0, 1.0, 0.0); glTranslatef(5.0, 0.0, 5.0); T * R * point Or R * T * point y x z z y x x z y

18 Next Lab oYou are given a Framework for your work or coursework – a set of ‘library’ functions that do the extra work for you so that you can focus on the graphics techniques oSpecial effort is being made to provide the Framework for both C++ and Java users. oThe Framework includes Object (or DisplayableObject in Java) and Scene classes for your classes to inherit from so that you can call the methods implemented in these classes oIt also includes Camera and Texture classes so that you can view your scene created in different ways, and texture objects to make them look more realistic, and it also includes functions for dealing with keyboard and mouse inputs so that you could manipulate your objects and scene. oThese programs should also work under Mac, simply create a new project, then use add existing items

19 Next Lab oYou are also given examples of object transformations, including the Cube, Triforce, and the Planet programs, e.g., the planets program - in addition to rotational movement, planets also move around, or orbit, other bodies, e.g., the Sun while the Moon orbits around the Earth, slower than either the Earth or Mars. oSo try to get the Framework working oThen try to integrate the examples to your work, e.g., under Windows, put them in the source file directory then use Add Existing Items.


Download ppt "Transformation. 3D Transformation oIn the modeling lecture we saw how to define an object in terms of its vertices in object space oWe will now see how."

Similar presentations


Ads by Google