0% found this document useful (0 votes)
152 views

Composite Transformations: The Heart of Computer Graphics: Lecturer

The document discusses composite transformations in computer graphics. It explains that transformations can be combined by multiplying their matrices, allowing complex transformations to be computed easily. It describes how OpenGL handles composite transformations by applying matrices in reverse order and maintaining transformation stacks. The document also covers calculating inverse transformations and improving efficiency by reducing the number of operations needed when applying transformations.
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
152 views

Composite Transformations: The Heart of Computer Graphics: Lecturer

The document discusses composite transformations in computer graphics. It explains that transformations can be combined by multiplying their matrices, allowing complex transformations to be computed easily. It describes how OpenGL handles composite transformations by applying matrices in reverse order and maintaining transformation stacks. The document also covers calculating inverse transformations and improving efficiency by reducing the number of operations needed when applying transformations.
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 18

Composite transformations: The heart of computer graphics

Lecturer: Dr Dan Cornford


[email protected] http://wiki.aston.ac.uk/DanCornford

CS2150, Computer Graphics, Aston University, Birmingham, UK


http://wiki.aston.ac.uk/C2150

October 12, 2009


Dan Cornford Composite Transformations 1/18

Outline: Composite transformations

Combining transformations. Matrix times a matrix. How to transform things in OpenGL. Efciency. Inverse transformations.

Dan Cornford

Composite Transformations

2/18

Composition of transformations

Big advantage of homogeneous coordinates is that transformations can be very easily combined. All that is required is multiplication of the transformation matrices. This makes otherwise complex transformations very easy to compute.

Dan Cornford

Composite Transformations

3/18

Composition of transformations

For instance if we wanted to rotate an object about some point, p. To simply write down the transformation would be quite a challenge! However, the transformation matrix can be computed by:
1 2 3

translate object by p, rotate object by angle , translate object by p.

Dan Cornford

Composite Transformations

4/18

Matrices multiplication
Given two matrices, A and B if we want to multiply B by A (that is form AB) then if A is (n m), B must be (m p). This produces a result, C = AB, which is (n p), with elements:
m

cij =
k =1

aik bkj

Basically we multiply the rst row of A with the rst column of B and put this in the c1,1 element of C. And so on .... The identity matrix (for multiplication) is denoted I: 1 0 0 I = 0 1 0 . 0 0 1 This means that AI = A = IA.
Dan Cornford Composite Transformations 5/18

Matrices basics

From GameDev.net

Unlike scalar multiplication, AB = BA this means that applying a scaling after a translation will not have the same effect as a translation after a scaling.
Multiplying composite transformation matrices is at the core of all modern graphics libraries.

Dan Cornford

Composite Transformations

6/18

Composition of transformations
Recall our previous example of rotation about a point p, which can be written as:
1 0 px cos sin 0 1 0 px T (p)R()T (p) = 0 1 py sin cos 0 0 1 py 0 0 1 0 0 1 0 0 1 cos sin px (1 cos ) + py sin cos py (1 cos ) px sin . = sin 0 0 1

Note the ordering of the transformation matrices. For those interested, M ATLAB provides an excellent platform for investigating these sort of transformations, since its natural matrix format makes things very easy to code.

Dan Cornford

Composite Transformations

7/18

Transformations and OpenGL

Basic commands are:


glTranslate#(dx, dy, dz) glScale#(sx, sy, sz) glRotate#(angle, x, y, z)

The matrices are applied to the vertices in the opposite order they are specied (pre-multiplied by existing transformation matrix). Can dene our own matrices: glLoadMatrix and glMultMatrix.

Dan Cornford

Composite Transformations

8/18

Transformations and OpenGL stacks

From GameDev.net

There are two important matrices in OpenGL GL PROJECTION and GL MODELVIEW. OpenGL stores these as composite transformation matrices. OpenGL maintains matrix stacks which are used to store the composite transformation matrices (of all transformations so far specied).
Dan Cornford Composite Transformations 9/18

Transformations and OpenGL stacks


Consider the following code fragment:
glLo adIdenti ty (); glRotate (45.0 , 0.0 , 0.0 , 0.0); /* apply tra nsformat ion R */ glTranslate (2.0 , 0.0 , 0.0); /* apply transf ormation T */ glBegin ( GL_POINTS ); glVertex3f ( v ); /* draw transformed vertex v */ glEnd ();

The effect of this is: the GL MODELVIEW matrix successively contains I, I R, and nally I R T ; the transformed vertex is I R T v = (I (R (T v ))); the transformations to vertex v effectively occur in the opposite order to which they were specied.
In reality only a single multiplication of the vertex by the GL MODELVIEW matrix occurs; the R and T matrices are already multiplied into a single composite matrix before being applied to v.
Dan Cornford Composite Transformations 10/18

Transformations and OpenGL stacks

From GameDev.net

We use glPushMatrix() and glPopMatrix() to save and remove the current matrix from its stack. This is normally the GL MODELVIEW matrix. Stacks play a large role in dening scene graphs and animating models.
Dan Cornford Composite Transformations 11/18

Efciency your job

The composition of transformations involving translation, scaling and rotation leads to transformation matrices M of the general form: r1,1 r1,2 tx M = r2,1 r2,2 ty . 0 0 1 How many elementary operations (+, , , /) are required to multiply a vector [x, y , w] by this matrix?

Dan Cornford

Composite Transformations

12/18

Efciency

The composition of transformations involving translation, scaling and rotation leads to transformation matrices M of the general form: r1,1 r1,2 tx M = r2,1 r2,2 ty . 0 0 1 Multiplying a point [x, y , w] by this matrix would take nine multiplies and six adds.

Dan Cornford

Composite Transformations

13/18

Efciency

Using the xed structure in the nal row of the matrix, the actual transformation can be written: x = r1,1 x + r1,2 y + tx , y = r2,2 y + r2,1 x + ty , This takes four multiplies and four adds. Parallel hardware adders and multipliers effectively remove this concern in modern graphics.

Dan Cornford

Composite Transformations

14/18

Inverse transformations

If a general transformation (which may be composite) is given by the 3 3 matrix M, then the inverse transformation, which maps the new image back to the original, untransformed one is given by M 1 . The matrix inverse is dened so that MM 1 = I where I is the 3 3 identity matrix, 1 0 0 I = 0 1 0 . 0 0 1 Inverses only exist for one to one transformations, for many operations they are not dened.

Dan Cornford

Composite Transformations

15/18

Inverse transformations

The translation matrix has inverse: 1 0 tx T 1 = 0 1 ty , 0 0 1 The scaling matrix has inverse: S 1 = 0 0
1 sx

0
1 sy

0 0 . 1

You should be able to work out the inverse of the rotation matrix ...

Dan Cornford

Composite Transformations

16/18

Inverse of composite transformations

For a composite transformation matrix C = AB the inverse is less obvious. We know (AB)1 = B 1 A1 from linear algebra thus: C 1 = B 1 A1 . This is logical the inverse transformations are applied in the opposite order.

Dan Cornford

Composite Transformations

17/18

Summary

Having nished this lecture you should: be able to compute composite transformation matrices; understand the way OpenGL implements transformations; be able to improve the efciency of applying transformations; understand the role and concept of an inverse transformation. If you have trouble with the maths use the extra example sheets (and solutions) on the web site.

Dan Cornford

Composite Transformations

18/18

You might also like