Modeling Transformations - PowerPoint PPT Presentation

1 / 69
About This Presentation
Title:

Modeling Transformations

Description:

Title: 3D Transformations Author: Reaz Last modified by: farhan Created Date: 8/8/2001 7:16:14 PM Document presentation format: On-screen Show Company – PowerPoint PPT presentation

Number of Views:160
Avg rating:3.0/5.0
Slides: 70
Provided by: Reaz3
Category:

less

Transcript and Presenter's Notes

Title: Modeling Transformations


1
Modeling Transformations
  • 2D Transformations
  • 3D Transformations
  • OpenGL Transformation

2
2D-Transformations
  • Basic Transformations
  • Homogeneous coordinate system
  • Composition of transformations

3
Translation 2D
4
Scaling 2D
  • Types of Scaling
  • Differential ( sx ! sy )
  • Uniform ( sx sy )

5
Rotation 2D
6
Rotation 2D
7
Mirror Reflection
8
Shearing Transformation
9
Inverse 2D - Transformations
10
Homogeneous Co-ordinates
  • Translation, scaling and rotation are expressed
    (non-homogeneously) as
  • translation P? P T
  • Scale P? S P
  • Rotate P? R P
  • Composition is difficult to express, since
    translation not expressed as a matrix
    multiplication
  • Homogeneous coordinates allow all three to be
    expressed homogeneously, using multiplication by
    3 3 matrices
  • W is 1 for affine transformations in graphics

11
Homogeneous Co-ordinates
  • P2d is a projection of Ph onto the w 1 plane
  • So an infinite number of points correspond to
    they constitute the whole line (tx, ty, tw)

12
Classification of Transformations
  • Rigid-body Transformation
  • Preserves parallelism of lines
  • Preserves angle and length
  • e.g. any sequence of R(?) and T(dx,dy)
  • Affine Transformation
  • Preserves parallelism of lines
  • Doesnt preserve angle and length
  • e.g. any sequence of R(?), S(sx,sy) and T(dx,dy)

13
Properties of rigid-body transformation
The following Matrix is Orthogonal if the upper
left 2X2 matrix has the following properties
  • A) Each row are unit vector.
  • sqrt(r11 r11 r12 r12) 1
  • B) Each column are unit vector.
  • sqrt(c11 c11 c12 c12) 1
  • 2. A) Rows will be perpendicular to each other
  • (r11 , r12 ) . ( r21 , r22) 0
  • B) Columns will be perpendicular to each other
  • (c11 , c12 ) . (c21 ,c22) 0
  • e.g. Rotation matrix is orthogonal
  • Orthogonal Transformation ? Rigid-Body
    Transformation
  • For any orthogonal matrix B ? B-1 BT

14
Commutativity of Transformation Matrices
  • In general matrix multiplication is not
    commutative
  • For the following special cases commutativity
    holds i.e. M1.M2 M2.M1

M1 M2
Translate Translate
Scale Scale
Rotate Rotate
Uniform Scale Rotate
  • Some non-commutative Compositions
  • Non-uniform scale, Rotate
  • Translate, Scale
  • Rotate, Translate

Original Transitional Final
15
Associativity of Matirx Multiplication
Create new affine transformations by multiplying
sequences of the above basic transformations.
q CBAp q ( (CB) A) p (C (B A))p C (B
(Ap) ) etc. matrix multiplication is
associative.
To transform just a point, better to do q
C(B(Ap))
But to transform many points, best to do
M CBA
then do q Mp for any
point p to be rendered.
For geometric pipeline transformation, define M
and set it up with the model-view matrix and
apply it to any vertex subsequently defined to
its setting.
16
Rotation of ? about P(h,k) R?,P
17
Scaling w.r.t. P(h,k) Ssx,sy,p
T(-h ,-k)
S(sx,sy)
T(h ,k)
18
Reflection about line L, ML
Step 1 Translate (0,b) to origin
Step 2 Rotate -? degrees
Step 3 Mirror reflect about X-axis
Step 4 Rotate ? degrees
Step 5 Translate origin to (0,b)
T(0 ,-b)
ML
R(-?)
T(0 ,b)
M x
R(?)
19
Problems to be solved
  • Schaums outline series
  • Problems
  • 4.1
  • 4.2
  • 4.3, 4.4, 4.5 gt R?,P
  • 4.6, 4.7, 4.8 gt Ssx,sy,,P
  • 4.9, 4.10, 4.11, 4.21 gt ML
  • 4.12 gt Shearing
  • Pg-281(1.24), Pg-320(5.19)
  • gt Circular view-port

20
3D Transformations
  • Basics of 3D geometry
  • Basic 3D Transformations
  • Composite Transformations

21
Orientation
  • Thumb points to ve Z-axis
  • Fingers show ve rotation from X to Y axis

22
Vectors in 3D
  • Have length and direction
  • V xv , yv , zv
  • Length is given by the Euclidean Norm
  • V ?( xv2 yv2 zv2 )
  • Dot Product
  • V U xv, yv, zvxu, yu, zu
  • xvxu yvyu zvzu
  • V U cos ß
  • Cross Product
  • V ? U
  • yvzu - zv yu , -xvzu zvxu , xvyu yvxu
  • ? V U sin ß
  • V ? U - ( U x V)

23
3D Equation of Curve Line
  • Parametric equations of Curve Line
  • Curve
  • Line

24
3D Equation of Surface Plane
  • Parametric equations of Surface Plane
  • Surface
  • Plane with Normal, N

25
3D Plane
  • Ways of defining a plane
  • 1. 3 points P0, P1, P2 on the plane
  • 2. Plane Normal N P0 on plane
  • 3. Plane Normal N a vector V on the plane
  • Plane Passing through P0, P1, P2

26
Affine Transformation
  • Transformation is a function that takes a point
    (or vector) and maps that point (or vector) into
    another point (or vector).
  • A coordinate transformation of the form
  • x axx x axy y axz z bx ,
  • y ayx x ayy y ayz z by ,
  • z azx x azy y azz z bz ,
  • is called a 3D affine transformation.
  • The 4th row for affine transformation is always
    0 0 0 1.
  • Properties of affine transformation
  • translation, scaling, shearing, rotation (or any
    combination of them) are examples affine
    transformations.
  • Lines and planes are preserved.
  • parallelism of lines and planes are also
    preserved, but not angles and length.

27
Translation 3D
28
Scaling 3D
29
Rotation 3D
  • For 3D-Rotation 2 parameters are needed
  • Angle of rotation
  • Axis of rotation

Rotation about z-axis
30
Rotation about Y-axis X-axis
About y-axis
About x-axis
31
Shear along Z-axis
32
Object Transformation
  • Line Can be transformed by transforming the end
    points
  • Plane(described by 3-points) Can be transformed
    by transforming the 3-points
  • Plane(described by a point and Normal) Point is
    transformed as usual. Special treatment is needed
    for transforming Normal

33
Composite Transformations 3D
  • Some of the composite transformations to be
    studied are
  • AV,N aligning a vector V with a vector N
  • R?,L rotation about an axis L( V, P )
  • Ssx,sy,P scaling w.r.t. point P

34
AV aligning vector V with k
Av
R?,i
35
AV aligning vector V with k
Av
R?,i
R-?,j
36
AV aligning vector V with k
  • AV-1 AVT
  • AV,N AN-1 AV

37
R?,L rotation about an axis L
  • Let the axis L be represented by vector V and
    passing through point P
  1. Translate P to the origin

2. Align V with vector k
3. Rotate ?? about k
4. Reverse step 2
5. Reverse step 1
R?,L
T-P
AV
R?,k
AV-1
T-P-1
38
MN,P Mirror reflection
  • Let the plane be represented by plane normal N
    and a point P in that plane

39
MN,P Mirror reflection
  • Let the plane be represented by plane normal N
    and a point P in that plane
  1. Translate P to the origin

MN,P
T-P
40
MN,P Mirror reflection
  • Let the plane be represented by plane normal N
    and a point P in that plane
  1. Translate P to the origin

N
2. Align N with vector k
P
MN,P
T-P
AN
41
MN,P Mirror reflection
  • Let the plane be represented by plane normal N
    and a point P in that plane
  1. Translate P to the origin

2. Align N with vector k
3. Reflect w.r.t xy-plane
MN,P
T-P
AN
S1,1,-1
42
MN,P Mirror reflection
  • Let the plane be represented by plane normal N
    and a point P in that plane
  1. Translate P to the origin

2. Align N with vector k
3. Reflect w.r.t xy-plane
4. Reverse step 2
MN,P
T-P
AN
S1,1,-1
AN-1
43
MN,P Mirror reflection
  • Let the plane be represented by plane normal N
    and a point P in that plane
  1. Translate P to the origin

2. Align N with vector k
3. Reflect w.r.t xy-plane
4. Reverse step 2
5. Reverse step 1
MN,P
T-P
AN
S1,1,-1
AN-1
T-P-1
44
Further Composition
45
Finding R
46
Finding Rz
R
47
Finding Rx
48
Finding Ry
Rz
Ry
Rx
49
Problems to be solved
  • Schaums outline series
  • Problems
  • 6.1
  • 6.2, 6.5, 6.9, 6.10, 6.11, 6.12 ? Av
  • 6.3, 6.4 ? R?,L
  • 6.6, 6.7, 6.8 ? MN,P

50
Transformations in OpenGL
  • OpenGL transformation commands
  • Transformation Order
  • Hierarchical Modeling

51
Transformations in OpenGL
  • OpenGL uses 3 stacks to maintain transformation
    matrices
  • Model View transformation matrix stack
  • Projection matrix stack
  • Texture matrix stack
  • You can load, push and pop the stack
  • The top most matrix from each stack is applied to
    all graphics primitive until it is changed

M
N
Graphics Primitives (P)
Output NMP
Projection Matrix Stack
Model-View Matrix Stack
52
General Transformation Commands
  • Specify current matrix (stack)
  • void glMatrixMode(GLenum mode)
  • Mode GL_MODELVIEW, GL_PROJECTION, GL_TEXTURE
  • Initialize current matrix.
  • void glLoadIdentity(void)
  • Sets the current matrix to 4X4 identity matirx
  • void glLoadMatrixfd(cost TYPE M)
  • Sets the current matrix to 4X4 matrix specified
    by M
  • Note current matrix ? Top most matrix of the
    current matrix stack

glLoadIdentity
glLoadMatrix(M)
53
General Transformation Commands
  • Concatenate Current Matrix
  • void glMultMatrix(const TYPE M)
  • Multiplies current matrix C, by M. i.e. C CM
  • Caveat OpenGL matrices are stored in column
    major order.
  • Best use utility function glTranslate, glRotate,
    glScale for common transformation tasks.

54
Transformations and OpenGL
  • Each time an OpenGL transformation M is called
    the current MODELVIEW matrix C is altered

glTranslatef(1.5, 0.0, 0.0) glRotatef(45.0, 0.0,
0.0, 1.0)
Note v is any vertex placed in rendering
pipeline v is the transformed vertex from v.
55
Sample Instance Transformation
  • glMatrixMode(GL_MODELVIEW)
  • glLoadIdentity()
  • glTranslatef(...)
  • glRotatef(...)
  • glScalef(...)
  • gluCylinder(...)

56
Thinking About Transformations
  • There is a World Coordinate System where
  • All objects are defined
  • Transformations are in World Coordinate space

Two Different Views
  • As a Global System
  • Objects moves but coordinates stay the same
  • Think of transformation in reverse order as they
    appear in code
  • As a Local System
  • Objects moves and coordinates move with it
  • Think of transformation in same order as they
    appear in code

57
Order of Transformation TR
glLoadIdentity() glMultiMatrixf(
T) glMultiMatrixf( R) draw_ the_ object( v) v
ITRv
Effect is same, but perception is different
58
Order of Transformation RT
glLoadIdentity() glMultiMatrixf(
R) glMultiMatrixf( T) draw_ the_ object( v) v
ITRv
Effect is same, but perception is different
59
Hierarchical Modeling
  • Many graphical objects are structured
  • Exploit structure for
  • Efficient rendering
  • Concise specification of model parameters
  • Physical realism
  • Often we need several instances of an object
  • Wheels of a car
  • Arms or legs of a figure
  • Chess pieces
  • Encapsulate basic object in a function
  • Object instances are created in standard form
  • Apply transformations to different instances
  • Typical order scaling, rotation, translation

60
OpenGL Hierarchical Model
61
Scene Graph
  • A scene graph is a hierarchical representation of
    a scene
  • We will use trees for representing hierarchical
    objects such that
  • Nodes represent parts of an object
  • Topology is maintained using parent-child
    relationship
  • Edges represent transformations that applies to a
    part and all the subparts connected to that part

Scene
typedef struct treenode GLfloat m16 //
Transformation void (f) ( ) // Draw
function struct treenode sibling struct
treenode child treenode
Sun
Star X
Earth
Venus
Saturn
Moon
Ring
62
Example - Torso
  • Initializing transformation matrix for node
  • treenode torso, head, ...
  • / in init function /
  • glLoadIdentity()
  • glRotatef(...)
  • glGetFloatv(GL_MODELVIEW_MATRIX, torso.m)
  • Initializing pointers
  • torso.f drawTorso
  • torso.sibling NULL
  • torso.child head

63
Generic Traversal
  • To render the hierarchy
  • Traverse the scene graph depth-first
  • Going down an edge
  • push the top matrix onto the stack
  • apply the edge's transformation(s)
  • At each node, render with the top matrix
  • Going up an edge
  • pop the top matrix off the stack

64
Generic Traversal Torso
  • Recursive definition
  • void traverse (treenode root)
  • if (root NULL) return
  • glPushMatrix()
  • glMultMatrixf(root-gtm)
  • root-gtf()
  • if (root-gtchild ! NULL) traverse(root-gtchild)
  • glPopMatrix()
  • if (root-gtsibling ! NULL) traverse(root-gtsibli
    ng)
  • C is really not the right language for this !!

65
Viewing Transformation
66
Viewing Pipeline Revisited
67
Viewing Transformation in OpenGL
  • To setup the modelview matrix, OpenGL provides
    the following function

gluLookAt( eyex, eyey, eyez, centerx, centery,
centerz, upx, upy, upz )
68
Implementation
We want to construct an Orthogonal Frame such
that,
(1) its origin is the point eye
(2) its -z basis vector points towards the point
center
(3) the up vector projects to the up direction
(ve y-axis)
Let C (for camera) denote this frame. Clearly,
69
Thank You
Write a Comment
User Comments (0)
About PowerShow.com