Download Session 18

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Determinant wikipedia , lookup

Mathematics of radio engineering wikipedia , lookup

Matrix calculus wikipedia , lookup

Transcript
Perception, Illusion and VR
HNRS 299, Spring 2008
Lecture 18
Multiple Transformations
1
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:
Rotate
Translate
Now start with the same square. 1st translate to the right, then rotate by 45 deg.
Translate
Rotate
2
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
3

Matrices
OpenGL accomplishes all transformations by way of Matrix
Multiplication.
A matrix is a 2 dimensional set of numbers.
Examples:
1.3 
 
 47 

2.6

1.0 3.5


2.0
2.7


2x2 Matrix
3x1 Matrix

4
Using Matrices to Solve Linear
Equations
Matrices can be used to solve systems of linear equations.
x' 3x  4 y  6z
y' 4 x  7y  13z
z' 2x  5y  10z
can be
written as
x' 3 4 6x
  
 
y'

4
7
13
  
y

z'
 
2 5 10

z 

P'
M
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.
5
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
6
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);
glRotatef(angle, x, y, z);
glScalef(sx, sy, sz);
M=T
M = TR
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.
7