Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Perception, Illusion and VR HNRS 299, Spring 2008 Lecture 18 Multiple Transformations.

Similar presentations


Presentation on theme: "1 Perception, Illusion and VR HNRS 299, Spring 2008 Lecture 18 Multiple Transformations."— Presentation transcript:

1 1 Perception, Illusion and VR HNRS 299, Spring 2008 Lecture 18 Multiple Transformations

2 2 Multiple Transformations We often want to perform multiple transformations on an object. For example, we might want to rotate and then translate it. The order of we perform transformations matters. Example: Start with a square centered on the origin of the XY plane. First rotate by 45 deg, then translate to the right: Now start with the same square. 1st translate to the right, then rotate by 45 deg. Rotate Translate Rotate

3 3 Multiple Transformations in OpenGL In OpenGL, function calls for transformations are given in the reverse order of what you want them to perform. Example: glTranslatef(0, 0, -200); glRotatef(theta, 0, 1, 0); 1st rotate about the Y axis. Then translate along the negative Z axis. How can this be? The compute executes the function calls in the order given. Why is the effect in the reverse? It all has to do with Matrix Multiplication

4 4 Matrices OpenGL accomplishes all transformations by way of Matrix Multiplication. A matrix is a 2 dimensional set of numbers. Examples: 2x2 Matrix 3x1 Matrix

5 5 Using Matrices to Solve Linear Equations Matrices can be used to solve systems of linear equations. can be written as P' To transform a point, we create a transformation matrix, M, and multiply the point P by that matrix: P' = MP Note: The order of multiplication matters. MP is not the same as PM. MP

6 6 Multiple Matrices To translate a point, we use a translation matrix, T: P' = TP To rotate a point, we use a rotation matrix, R: P' = RP To translate and then rotate, we multiply by T and then R: P' = TP P'' = RP' = RTP We can do this transformation all at once by creating a transformation matrix, M = RT P'' = MP

7 7 Transformation in OpenGL creates a Matrix OpenGL creates the matrix, M, by multiplying the current matrix by a transformation matrix with each call to glTranlatef( ), etc. glTranslatef(x, y, z);M = T glRotatef(angle, x, y, z);M = TR glScalef(sx, sy, sz);M = TRS When you define an object vertex with: glVertex3f(x, y, z); OpenGL multiplies the point by M before rendering it. This has the effect of transforming the point in the reverse order of the transformation calls.


Download ppt "1 Perception, Illusion and VR HNRS 299, Spring 2008 Lecture 18 Multiple Transformations."

Similar presentations


Ads by Google