Composing Transformations - PowerPoint PPT Presentation

About This Presentation
Title:

Composing Transformations

Description:

Composing Transformations Composing Transformations the process of applying several transformations in succession to form one overall transformation – PowerPoint PPT presentation

Number of Views:94
Avg rating:3.0/5.0
Slides: 22
Provided by: HanW166
Category:

less

Transcript and Presenter's Notes

Title: Composing Transformations


1
Composing Transformations
  • Composing Transformations the process of
    applying several transformations in succession to
    form one overall transformation
  • If we transform a point P using matrix M1 first,
    and then transform using M2, and then M3, we
    have
  • (M3 x (M2 x (M1 x P ))) M3 x M2 x
    M1 x P

2
Composing Transformation
  • Matrix multiplication is associative
  • M3 x M2 x M1 (M3 x M2) x M1 M3 x (M2 x
    M1)
  • Transformation products may not be commutative
    A x B ! B x A
  • Some cases where A x B B x A
  • A
    B
  • translation
    translation
  • scaling
    scaling
  • rotation
    rotation
  • uniform scaling
    rotation
  • (sx sy)

3
Transformation order matters!
  • Example rotation and translation are not
    commutative

Translate (5,0) and then Rotate 60 degree
OR Rotate 60 degree and then
translate (5,0)??
Rotate and then translate !!
4
How OpenGL does it?
  • OpenGLs transformation functions are meant to be
    used in 3D
  • No problem for 2D though just ignore the z
    dimension
  • Translation
  • glTranslatef(d)(tx, ty, tz) -gt
    glTranslatef(d)(tx,ty,0) for 2D

5
How OpenGL does it?
  • Rotation
  • glRotatef(d)(angle, vx, vy, vz) -gt
    glRotatef(d)(angle, 0,0,1) for 2D

y
(vx, vy, vz) rotation axis
x
You can imagine z is pointing out of the slide
6
OpenGL Transformation Composition
  • A global modeling transformation matrix
  • (GL_MODELVIEW, called it M here)
  • glMatrixMode(GL_MODELVIEW)
  • The user is responsible to reset it if necessary
  • glLoadIdentity()
  • -gt M 1 0 0
  • 0 1 0
  • 0 0 1

7
OpenGL Transformation Composition
  • Matrices for performing user-specified
    transformations are multiplied to the current
    matrix
  • For example,

  • 1 0 1
  • glTranslated(1,1 0) M M x 0 1
    1

  • 0 0 1
  • All the vertices defined within glBegin() /
    glEnd() will first go through the transformation
    (modeling transformation)
  • P M x P

8
Transformation Pipeline
Modeling transformation

9
Something noteworthy
  • Very very noteworthy
  • OpenGL post-multiplies each new transformation
    matrix
  • M M x Mnew
  • Example perform translation, then rotation
  • 0) M Identity
  • 1) translation T(tx,ty,0) -gt M M x
    T(tx,ty,0)
  • 2) rotation R(q) -gt M M x R(q)
  • 3) Now, transform a point P -gt P M x P
  • T(tx, ty, 0) x R(q) x P

10
Example Revisit
  • We want rotation and then translation
  • Generate wrong results if you do

You need to specify the transformation in the
opposite order!!
11
How Strange
  • OpenGL has its reason
  • It wants you to think of transformation in a
    different way
  • Instead of thinking of transforming the object
    in a fixed global coordinate system, you should
    think of transforming an object as moving
    (transforming) its local coordinate system

12
OpenGL Transformation
  • When using OpenGL, we need to think of object
    transformations as moving (transforming) its
    local coordinate frame
  • All the transformations are performed relative to
    the current coordinate frame origin and axes

13
Translate Coordinate Frame
Translate (3,3)?
14
Translate Coordinate Frame (2)
Translate (3,3)?
15
Rotate Coordinate Frame
Rotate 30 degree?
16
Scale Coordinate Frame
Scale (0.5,0.5)?
17
Compose Transformations
Transformations?
  • Answer
  • Translate(7,9)
  • Rotate 45
  • Scale (2,2)

o
45
(7,9)
18
Another example
How do you transform from C1 to C2?
C1
C2
Translate (5,5) and then Rotate (60) OR
Rotate (60) and then Translate (5,5) ???
Answer Translate(5,5) and then
Rotate (60)
19
Another example (contd)
If you Rotate(60) and then Translate(5,5)
C2
C1
5
5
You will be translated (5,5) relative to C2!!
20
Transform Objects
  • What does coordinate frame transformations have
    to do with object transformations?
  • You can view transformations as tying the object
    to a local coordinate frame and moving that
    coordinate frame

21
Put it all together
  • When you use OpenGL
  • Think of transformation as moving coordinate
    frames
  • Call OpenGL transformation functions in that
    order
  • OpenGL will actually perform the transformations
    in the reverse order
  • Everything will be just right!!!
Write a Comment
User Comments (0)
About PowerShow.com