2-D Transformations Why Do We Need Transformations?: - Glusphere Draws A Sphere of Radius
2-D Transformations Why Do We Need Transformations?: - Glusphere Draws A Sphere of Radius
Transformations are functions applied to points in space Makes modeling more convenient
p ' = f ( p) • for example, often easier to generate models around origin
– gluSphere() draws a sphere of radius r about the origin
• can then move them to final position with transformations
Provide a mechanism for manipulating geometric models
Offset all points by constant amount Scale all points by constant amount
x ' = x + ∆x x ' = sx
y' = y + ∆y y ' = ty
x ' x ∆ x x ' s 0 x
= + y ' = 0 t y
y ' y ∆ y
or or
p' = p + d p ' = Sp
What order of R, S, T
will produce this figure?
(a) TRSv
(b) RSTv
(c) TSRv
(d) RTSv
(c) TSRv (d) RTSv
We developed 2-D transformations Looks pretty much the same as in 2-D Scaling
• just add on the z dimension to everything
r 0 0 0
0 s 0 0
But we’re mainly interested in 3-D graphics S=
0 0 t 0
0 0 0 1
So we’ll extend these tools to 3-D
Translation
1 0 0 ∆ x
0 1 0 ∆ y
T=
0 0 1 ∆z
Unfortunately, rotation is not so simple …
0 0 0 1
Rotation About Coordinate Axes Some Mathematical Definitions
Let’s suppose we have a unit direction vector OpenGL maintains a current transformation matrix M
x • issue commands to post-multiply matrices into M
u = y where x 2 + y 2 + z 2 = 1
• so, commands are listed in reverse order of application
• glLoadIdentity() — set M to identity matrix (M ← I)
z
• glTranslatef(∆x, ∆y, ∆z) — translation (M ← MT)
• glRotatef(θ, x, y, z) — rotate about given axis (M ← MR)
We can derive a rotation by a given angle about this axis • glScalef(r, s, t) — scale by given factors (M ← MS)
This is the approach used by OpenGL — glRotatef(θ, x, y, z) glTranslatef(x, y, z, 0); // (3) move p back
glRotatef(theta, 0, 0, 1); // (2) rotate around z axis
Has many of the same interpolation problems as Euler angles glTranslatef(-x, -y, -z, 0);// (1) move p to origin
DrawSomething();
A Word of Caution on Notation Transformation of Normal Vectors
We’ve consistently written points as column vectors Affine transformations map parallel lines to parallel lines
• virtually everyone does this x ' a b x • but the same does not hold for perpendicular lines
• typically represent matrices in row-major order y ' = c d y
[[a b] [c d]]
Some in graphics have traditionally used row vectors Transform M will not map normal vectors to normal vectors
• convert by transposing everything: a c • first guess would be to map normals as n → Mn
ABv → (ABv)T=vT BT AT [ x ' y '] = [ x y] • after transform, may or may not be perpendicular to surface
b d
• note that order is reversed as well Normal vectors are defined by surface tangent planes
• typically represent matrices in column-major order • so let’s consider how planes are transformed
[[a c] [b d]]
• OpenGL actually does it this way
• but you’ll probably never notice
A plane in 3-D space is described by the homogeneous vector Must in general compute actual local plane
n = (a, b, c , d ) where ax + by + cz + d = 0 is the plane equation n = (a, b, c , d ) where ax + by + cz + d = 0 is the plane equation
• thus any point v on the plane satisfies the equation • however, there are some simpler cases
nT v = 0
Simplified case #1: Affine Transformations
For any 4x4 matrix whose inverse exists, this is equivalent to • map parallel planes to parallel planes
n T M −1Mv = 0 • thus, can pick any value of d — might as well be 0
• thus the transformed point Mv lies on the plane nTM-1 Simplified case #2: Orthogonal (Rigid-Body) Transformations
• it’s plane vector is (nTM-1)T or (M-1)Tn • in this case (e.g., rotation) M −1 = MT
• thus the normal transformation rule becomes n → Mn
This gives us the transformation rule for normal vectors
n → ( M −1 )T n
An Alternative View of Transformations
e1